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,130 @@
|
|
|
1
|
+
"""Outgoing HTTPS connections that race address families (RFC 8305, "Happy Eyeballs").
|
|
2
|
+
|
|
3
|
+
urllib connects through socket.create_connection, which tries one address at
|
|
4
|
+
a time and gives each the whole request timeout. On a network where IPv6
|
|
5
|
+
connects sometimes stall, every stalled connect costs the full timeout before
|
|
6
|
+
IPv4 is tried. Here the next address starts after a short delay, or as soon
|
|
7
|
+
as an attempt fails, and the first connection to succeed wins.
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import errno
|
|
12
|
+
import http.client
|
|
13
|
+
import os
|
|
14
|
+
import selectors
|
|
15
|
+
import socket
|
|
16
|
+
import time
|
|
17
|
+
import urllib.request
|
|
18
|
+
|
|
19
|
+
# How long an attempt runs alone before the next address joins the race.
|
|
20
|
+
ATTEMPT_DELAY = 0.25
|
|
21
|
+
|
|
22
|
+
_IN_PROGRESS = {errno.EINPROGRESS, errno.EWOULDBLOCK, errno.EALREADY, 10035} # 10035: WSAEWOULDBLOCK
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _interleave(infos):
|
|
26
|
+
"""Alternate address families, starting with the resolver's first choice."""
|
|
27
|
+
if not infos:
|
|
28
|
+
return []
|
|
29
|
+
first = infos[0][0]
|
|
30
|
+
preferred = [info for info in infos if info[0] == first]
|
|
31
|
+
others = [info for info in infos if info[0] != first]
|
|
32
|
+
ordered = []
|
|
33
|
+
while preferred or others:
|
|
34
|
+
if preferred:
|
|
35
|
+
ordered.append(preferred.pop(0))
|
|
36
|
+
if others:
|
|
37
|
+
ordered.append(others.pop(0))
|
|
38
|
+
return ordered
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def racing_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, source_address=None, *,
|
|
42
|
+
resolve=socket.getaddrinfo, delay=None):
|
|
43
|
+
"""A connected socket like socket.create_connection, racing the resolved addresses."""
|
|
44
|
+
host, port = address[:2]
|
|
45
|
+
delay = ATTEMPT_DELAY if delay is None else delay
|
|
46
|
+
limited = timeout is not None and timeout is not socket._GLOBAL_DEFAULT_TIMEOUT
|
|
47
|
+
deadline = time.monotonic() + timeout if limited else None
|
|
48
|
+
queue = _interleave(resolve(host, port, 0, socket.SOCK_STREAM))
|
|
49
|
+
if not queue:
|
|
50
|
+
raise OSError('getaddrinfo returned an empty list')
|
|
51
|
+
selector = selectors.DefaultSelector()
|
|
52
|
+
pending = set()
|
|
53
|
+
error = None
|
|
54
|
+
winner = None
|
|
55
|
+
next_start = time.monotonic()
|
|
56
|
+
try:
|
|
57
|
+
while winner is None and (queue or pending):
|
|
58
|
+
now = time.monotonic()
|
|
59
|
+
if deadline is not None and now >= deadline:
|
|
60
|
+
break
|
|
61
|
+
if queue and (not pending or now >= next_start):
|
|
62
|
+
family, kind, proto, _, sockaddr = queue.pop(0)
|
|
63
|
+
try:
|
|
64
|
+
sock = socket.socket(family, kind, proto)
|
|
65
|
+
except OSError as failure:
|
|
66
|
+
error = failure
|
|
67
|
+
continue
|
|
68
|
+
try:
|
|
69
|
+
sock.setblocking(False)
|
|
70
|
+
if source_address:
|
|
71
|
+
sock.bind(source_address)
|
|
72
|
+
code = sock.connect_ex(sockaddr)
|
|
73
|
+
except OSError as failure:
|
|
74
|
+
sock.close()
|
|
75
|
+
error = failure
|
|
76
|
+
continue
|
|
77
|
+
if code == 0:
|
|
78
|
+
winner = sock
|
|
79
|
+
break
|
|
80
|
+
if code not in _IN_PROGRESS:
|
|
81
|
+
sock.close()
|
|
82
|
+
error = OSError(code, os.strerror(code))
|
|
83
|
+
continue
|
|
84
|
+
selector.register(sock, selectors.EVENT_WRITE)
|
|
85
|
+
pending.add(sock)
|
|
86
|
+
next_start = now + delay
|
|
87
|
+
continue
|
|
88
|
+
limits = []
|
|
89
|
+
if queue:
|
|
90
|
+
limits.append(next_start - now)
|
|
91
|
+
if deadline is not None:
|
|
92
|
+
limits.append(deadline - now)
|
|
93
|
+
for key, _ in selector.select(max(0, min(limits)) if limits else None):
|
|
94
|
+
sock = key.fileobj
|
|
95
|
+
selector.unregister(sock)
|
|
96
|
+
pending.discard(sock)
|
|
97
|
+
code = sock.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
|
|
98
|
+
if code == 0 and winner is None:
|
|
99
|
+
winner = sock
|
|
100
|
+
continue
|
|
101
|
+
sock.close()
|
|
102
|
+
if code:
|
|
103
|
+
error = OSError(code, os.strerror(code))
|
|
104
|
+
# A failed attempt hands its turn to the next address at once.
|
|
105
|
+
next_start = time.monotonic()
|
|
106
|
+
finally:
|
|
107
|
+
for sock in pending:
|
|
108
|
+
if sock is not winner:
|
|
109
|
+
sock.close()
|
|
110
|
+
selector.close()
|
|
111
|
+
if winner is None:
|
|
112
|
+
if deadline is not None and time.monotonic() >= deadline:
|
|
113
|
+
raise TimeoutError('timed out')
|
|
114
|
+
raise error or OSError('connect failed')
|
|
115
|
+
# Like socket.create_connection: the given timeout, else the global default.
|
|
116
|
+
winner.settimeout(timeout if timeout is not socket._GLOBAL_DEFAULT_TIMEOUT else socket.getdefaulttimeout())
|
|
117
|
+
return winner
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
class _RacingHTTPSConnection(http.client.HTTPSConnection):
|
|
121
|
+
def __init__(self, *args, **kwargs):
|
|
122
|
+
super().__init__(*args, **kwargs)
|
|
123
|
+
self._create_connection = racing_connection
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
class RacingHTTPSHandler(urllib.request.HTTPSHandler):
|
|
127
|
+
"""Replaces urllib's HTTPS handler; everything but the connect is unchanged."""
|
|
128
|
+
|
|
129
|
+
def do_open(self, http_class, req, **kwargs):
|
|
130
|
+
return super().do_open(_RacingHTTPSConnection, req, **kwargs)
|