llmworld-agentmail 0.1.0__py3-none-any.whl
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.
- llmworld_agentmail/__init__.py +3 -0
- llmworld_agentmail/__main__.py +3 -0
- llmworld_agentmail/cli.py +283 -0
- llmworld_agentmail/client.py +171 -0
- llmworld_agentmail/config.py +75 -0
- llmworld_agentmail-0.1.0.dist-info/METADATA +60 -0
- llmworld_agentmail-0.1.0.dist-info/RECORD +10 -0
- llmworld_agentmail-0.1.0.dist-info/WHEEL +5 -0
- llmworld_agentmail-0.1.0.dist-info/entry_points.txt +2 -0
- llmworld_agentmail-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
"""argparse CLI for llmworld-agentmail."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import sys
|
|
8
|
+
import uuid
|
|
9
|
+
from typing import Any, Callable
|
|
10
|
+
|
|
11
|
+
from . import __version__
|
|
12
|
+
from .client import ApiError, Client
|
|
13
|
+
from .config import (
|
|
14
|
+
CREDENTIALS_PATH,
|
|
15
|
+
load_credentials,
|
|
16
|
+
resolve_api_key,
|
|
17
|
+
resolve_base,
|
|
18
|
+
set_api_key,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _emit(data: Any, *, pretty: bool) -> None:
|
|
23
|
+
if pretty:
|
|
24
|
+
print(json.dumps(data, indent=2, ensure_ascii=False))
|
|
25
|
+
else:
|
|
26
|
+
print(json.dumps(data, ensure_ascii=False, separators=(",", ":")))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _fail(err: ApiError, *, pretty: bool) -> int:
|
|
30
|
+
payload = err.body if err.body is not None else {"message": err.message}
|
|
31
|
+
if not isinstance(payload, (dict, list)):
|
|
32
|
+
payload = {"message": str(payload), "status": err.status}
|
|
33
|
+
elif isinstance(payload, dict) and "status" not in payload:
|
|
34
|
+
payload = {**payload, "status": err.status}
|
|
35
|
+
text = (
|
|
36
|
+
json.dumps(payload, indent=2, ensure_ascii=False)
|
|
37
|
+
if pretty
|
|
38
|
+
else json.dumps(payload, ensure_ascii=False, separators=(",", ":"))
|
|
39
|
+
)
|
|
40
|
+
print(text, file=sys.stderr)
|
|
41
|
+
return 1 if err.status != 0 else 2
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _client_from_args(args: argparse.Namespace, *, need_auth: bool) -> Client:
|
|
45
|
+
base = resolve_base(getattr(args, "base", None))
|
|
46
|
+
key = resolve_api_key(getattr(args, "api_key", None))
|
|
47
|
+
if need_auth and not key:
|
|
48
|
+
raise ApiError(
|
|
49
|
+
401,
|
|
50
|
+
{
|
|
51
|
+
"code": "missing_api_key",
|
|
52
|
+
"message": (
|
|
53
|
+
"No API key. Run: llmworld-agentmail config set-key <key> "
|
|
54
|
+
"or set AGENTMAIL_API_KEY"
|
|
55
|
+
),
|
|
56
|
+
"fix": "After the owner claims the key from email, save it with config set-key.",
|
|
57
|
+
},
|
|
58
|
+
)
|
|
59
|
+
return Client(base, key)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def cmd_provision(args: argparse.Namespace) -> int:
|
|
63
|
+
client = _client_from_args(args, need_auth=False)
|
|
64
|
+
try:
|
|
65
|
+
data = client.provision(
|
|
66
|
+
human_email=args.email,
|
|
67
|
+
username=args.username,
|
|
68
|
+
display_name=args.display_name,
|
|
69
|
+
)
|
|
70
|
+
except ApiError as e:
|
|
71
|
+
return _fail(e, pretty=args.pretty)
|
|
72
|
+
_emit(data, pretty=args.pretty)
|
|
73
|
+
if args.pretty:
|
|
74
|
+
print(
|
|
75
|
+
"\nStop here: check the owner inbox for the claim email, "
|
|
76
|
+
"open the link, then run: llmworld-agentmail config set-key <api_key>",
|
|
77
|
+
file=sys.stderr,
|
|
78
|
+
)
|
|
79
|
+
return 0
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def cmd_config_set_key(args: argparse.Namespace) -> int:
|
|
83
|
+
path = set_api_key(args.api_key_value, base=resolve_base(args.base))
|
|
84
|
+
_emit({"ok": True, "path": str(path)}, pretty=args.pretty)
|
|
85
|
+
return 0
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def cmd_config_show(args: argparse.Namespace) -> int:
|
|
89
|
+
data = load_credentials()
|
|
90
|
+
key = data.get("api_key")
|
|
91
|
+
masked = None
|
|
92
|
+
if isinstance(key, str) and key:
|
|
93
|
+
masked = key[:8] + "…" if len(key) > 8 else "***"
|
|
94
|
+
_emit(
|
|
95
|
+
{
|
|
96
|
+
"path": str(CREDENTIALS_PATH),
|
|
97
|
+
"base": resolve_base(args.base),
|
|
98
|
+
"api_key_set": bool(masked),
|
|
99
|
+
"api_key_prefix": masked,
|
|
100
|
+
},
|
|
101
|
+
pretty=args.pretty,
|
|
102
|
+
)
|
|
103
|
+
return 0
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def cmd_whoami(args: argparse.Namespace) -> int:
|
|
107
|
+
try:
|
|
108
|
+
client = _client_from_args(args, need_auth=True)
|
|
109
|
+
data = client.whoami()
|
|
110
|
+
except ApiError as e:
|
|
111
|
+
return _fail(e, pretty=args.pretty)
|
|
112
|
+
_emit(data, pretty=args.pretty)
|
|
113
|
+
return 0
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def cmd_inboxes(args: argparse.Namespace) -> int:
|
|
117
|
+
try:
|
|
118
|
+
client = _client_from_args(args, need_auth=True)
|
|
119
|
+
data = client.list_inboxes()
|
|
120
|
+
except ApiError as e:
|
|
121
|
+
return _fail(e, pretty=args.pretty)
|
|
122
|
+
_emit(data, pretty=args.pretty)
|
|
123
|
+
return 0
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def cmd_send(args: argparse.Namespace) -> int:
|
|
127
|
+
to_list = [a.strip() for a in args.to if a.strip()]
|
|
128
|
+
if not to_list:
|
|
129
|
+
print(
|
|
130
|
+
json.dumps({"code": "validation_error", "message": "--to is required"}),
|
|
131
|
+
file=sys.stderr,
|
|
132
|
+
)
|
|
133
|
+
return 2
|
|
134
|
+
idem = args.idempotency_key or str(uuid.uuid4())
|
|
135
|
+
try:
|
|
136
|
+
client = _client_from_args(args, need_auth=True)
|
|
137
|
+
data = client.send_message(
|
|
138
|
+
args.inbox,
|
|
139
|
+
to=to_list,
|
|
140
|
+
subject=args.subject,
|
|
141
|
+
text=args.text,
|
|
142
|
+
html=args.html,
|
|
143
|
+
idempotency_key=idem,
|
|
144
|
+
)
|
|
145
|
+
except ApiError as e:
|
|
146
|
+
return _fail(e, pretty=args.pretty)
|
|
147
|
+
_emit(data, pretty=args.pretty)
|
|
148
|
+
return 0
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def cmd_list(args: argparse.Namespace) -> int:
|
|
152
|
+
try:
|
|
153
|
+
client = _client_from_args(args, need_auth=True)
|
|
154
|
+
data = client.list_messages(
|
|
155
|
+
args.inbox,
|
|
156
|
+
limit=args.limit,
|
|
157
|
+
unread=args.unread,
|
|
158
|
+
)
|
|
159
|
+
except ApiError as e:
|
|
160
|
+
return _fail(e, pretty=args.pretty)
|
|
161
|
+
_emit(data, pretty=args.pretty)
|
|
162
|
+
return 0
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def cmd_get(args: argparse.Namespace) -> int:
|
|
166
|
+
try:
|
|
167
|
+
client = _client_from_args(args, need_auth=True)
|
|
168
|
+
data = client.get_message(args.inbox, args.message)
|
|
169
|
+
except ApiError as e:
|
|
170
|
+
return _fail(e, pretty=args.pretty)
|
|
171
|
+
_emit(data, pretty=args.pretty)
|
|
172
|
+
return 0
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def cmd_quota(args: argparse.Namespace) -> int:
|
|
176
|
+
try:
|
|
177
|
+
client = _client_from_args(args, need_auth=True)
|
|
178
|
+
data = client.send_quota(args.inbox)
|
|
179
|
+
except ApiError as e:
|
|
180
|
+
return _fail(e, pretty=args.pretty)
|
|
181
|
+
_emit(data, pretty=args.pretty)
|
|
182
|
+
return 0
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def _add_global(parser: argparse.ArgumentParser) -> None:
|
|
186
|
+
parser.add_argument(
|
|
187
|
+
"--base",
|
|
188
|
+
default=None,
|
|
189
|
+
help="API base URL (default: MAIL_API_BASE or https://mail.llmworld.net)",
|
|
190
|
+
)
|
|
191
|
+
parser.add_argument(
|
|
192
|
+
"--api-key",
|
|
193
|
+
default=None,
|
|
194
|
+
dest="api_key",
|
|
195
|
+
help="Bearer API key (overrides env / credentials file)",
|
|
196
|
+
)
|
|
197
|
+
parser.add_argument(
|
|
198
|
+
"--pretty",
|
|
199
|
+
action="store_true",
|
|
200
|
+
help="Pretty-print JSON",
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
205
|
+
parser = argparse.ArgumentParser(
|
|
206
|
+
prog="llmworld-agentmail",
|
|
207
|
+
description="CLI for llmworld Mail (https://mail.llmworld.net /v0)",
|
|
208
|
+
)
|
|
209
|
+
parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
|
210
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
211
|
+
|
|
212
|
+
p_prov = sub.add_parser("provision", help="Create inbox; claim email goes to owner")
|
|
213
|
+
_add_global(p_prov)
|
|
214
|
+
p_prov.add_argument("--email", required=True, help="Owner human_email (not @llmworld.net)")
|
|
215
|
+
p_prov.add_argument("--username", required=True, help="Local-part → {username}@llmworld.net")
|
|
216
|
+
p_prov.add_argument("--display-name", default=None, dest="display_name")
|
|
217
|
+
p_prov.set_defaults(func=cmd_provision)
|
|
218
|
+
|
|
219
|
+
p_cfg = sub.add_parser("config", help="Manage local credentials")
|
|
220
|
+
cfg_sub = p_cfg.add_subparsers(dest="config_cmd", required=True)
|
|
221
|
+
|
|
222
|
+
p_set = cfg_sub.add_parser("set-key", help="Save API key to ~/.llmworld/credentials.json")
|
|
223
|
+
_add_global(p_set)
|
|
224
|
+
p_set.add_argument("api_key_value", metavar="API_KEY")
|
|
225
|
+
p_set.set_defaults(func=cmd_config_set_key)
|
|
226
|
+
|
|
227
|
+
p_show = cfg_sub.add_parser("show", help="Show masked credential status")
|
|
228
|
+
_add_global(p_show)
|
|
229
|
+
p_show.set_defaults(func=cmd_config_show)
|
|
230
|
+
|
|
231
|
+
p_me = sub.add_parser("whoami", help="GET /v0/auth/me")
|
|
232
|
+
_add_global(p_me)
|
|
233
|
+
p_me.set_defaults(func=cmd_whoami)
|
|
234
|
+
|
|
235
|
+
p_inboxes = sub.add_parser("inboxes", help="GET /v0/inboxes")
|
|
236
|
+
_add_global(p_inboxes)
|
|
237
|
+
p_inboxes.set_defaults(func=cmd_inboxes)
|
|
238
|
+
|
|
239
|
+
p_send = sub.add_parser("send", help="Send a message")
|
|
240
|
+
_add_global(p_send)
|
|
241
|
+
p_send.add_argument("--inbox", required=True, help="inbox_id or email")
|
|
242
|
+
p_send.add_argument(
|
|
243
|
+
"--to",
|
|
244
|
+
action="append",
|
|
245
|
+
default=[],
|
|
246
|
+
help="Recipient (repeatable)",
|
|
247
|
+
)
|
|
248
|
+
p_send.add_argument("--subject", required=True)
|
|
249
|
+
p_send.add_argument("--text", default=None)
|
|
250
|
+
p_send.add_argument("--html", default=None)
|
|
251
|
+
p_send.add_argument("--idempotency-key", default=None, dest="idempotency_key")
|
|
252
|
+
p_send.set_defaults(func=cmd_send)
|
|
253
|
+
|
|
254
|
+
p_list = sub.add_parser("list", help="List messages")
|
|
255
|
+
_add_global(p_list)
|
|
256
|
+
p_list.add_argument("--inbox", required=True)
|
|
257
|
+
p_list.add_argument("--limit", type=int, default=None)
|
|
258
|
+
p_list.add_argument("--unread", action="store_true")
|
|
259
|
+
p_list.set_defaults(func=cmd_list)
|
|
260
|
+
|
|
261
|
+
p_get = sub.add_parser("get", help="Get one message")
|
|
262
|
+
_add_global(p_get)
|
|
263
|
+
p_get.add_argument("--inbox", required=True)
|
|
264
|
+
p_get.add_argument("--message", required=True, help="message_id")
|
|
265
|
+
p_get.set_defaults(func=cmd_get)
|
|
266
|
+
|
|
267
|
+
p_quota = sub.add_parser("quota", help="Send quota for an inbox")
|
|
268
|
+
_add_global(p_quota)
|
|
269
|
+
p_quota.add_argument("--inbox", required=True)
|
|
270
|
+
p_quota.set_defaults(func=cmd_quota)
|
|
271
|
+
|
|
272
|
+
return parser
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def main(argv: list[str] | None = None) -> int:
|
|
276
|
+
parser = build_parser()
|
|
277
|
+
args = parser.parse_args(argv)
|
|
278
|
+
func: Callable[[argparse.Namespace], int] = args.func
|
|
279
|
+
return func(args)
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
if __name__ == "__main__":
|
|
283
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"""Minimal HTTP client for llmworld mail-api /v0."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import urllib.error
|
|
7
|
+
import urllib.parse
|
|
8
|
+
import urllib.request
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ApiError(Exception):
|
|
13
|
+
def __init__(self, status: int, body: Any, message: str | None = None):
|
|
14
|
+
self.status = status
|
|
15
|
+
self.body = body
|
|
16
|
+
self.message = message or _summarize(status, body)
|
|
17
|
+
super().__init__(self.message)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _summarize(status: int, body: Any) -> str:
|
|
21
|
+
if isinstance(body, dict):
|
|
22
|
+
parts = [
|
|
23
|
+
str(body.get(k))
|
|
24
|
+
for k in ("code", "name", "message", "fix")
|
|
25
|
+
if body.get(k)
|
|
26
|
+
]
|
|
27
|
+
if parts:
|
|
28
|
+
return f"HTTP {status}: " + " | ".join(parts)
|
|
29
|
+
if isinstance(body, str) and body.strip():
|
|
30
|
+
return f"HTTP {status}: {body.strip()[:400]}"
|
|
31
|
+
return f"HTTP {status}"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class Client:
|
|
35
|
+
def __init__(self, base: str, api_key: str | None = None, timeout: float = 30.0):
|
|
36
|
+
self.base = base.rstrip("/")
|
|
37
|
+
self.api_key = api_key
|
|
38
|
+
self.timeout = timeout
|
|
39
|
+
|
|
40
|
+
def request(
|
|
41
|
+
self,
|
|
42
|
+
method: str,
|
|
43
|
+
path: str,
|
|
44
|
+
*,
|
|
45
|
+
body: dict[str, Any] | None = None,
|
|
46
|
+
query: dict[str, Any] | None = None,
|
|
47
|
+
headers: dict[str, str] | None = None,
|
|
48
|
+
auth: bool = True,
|
|
49
|
+
) -> Any:
|
|
50
|
+
url = self.base + path
|
|
51
|
+
if query:
|
|
52
|
+
qs = urllib.parse.urlencode(
|
|
53
|
+
{k: v for k, v in query.items() if v is not None}
|
|
54
|
+
)
|
|
55
|
+
if qs:
|
|
56
|
+
url = f"{url}?{qs}"
|
|
57
|
+
|
|
58
|
+
req_headers: dict[str, str] = {"Accept": "application/json"}
|
|
59
|
+
data: bytes | None = None
|
|
60
|
+
if body is not None:
|
|
61
|
+
data = json.dumps(body).encode("utf-8")
|
|
62
|
+
req_headers["Content-Type"] = "application/json"
|
|
63
|
+
if headers:
|
|
64
|
+
req_headers.update(headers)
|
|
65
|
+
if auth:
|
|
66
|
+
if not self.api_key:
|
|
67
|
+
raise ApiError(
|
|
68
|
+
401,
|
|
69
|
+
{"code": "missing_api_key", "message": "No API key configured"},
|
|
70
|
+
)
|
|
71
|
+
req_headers["Authorization"] = f"Bearer {self.api_key}"
|
|
72
|
+
|
|
73
|
+
req = urllib.request.Request(url, data=data, headers=req_headers, method=method)
|
|
74
|
+
try:
|
|
75
|
+
with urllib.request.urlopen(req, timeout=self.timeout) as resp:
|
|
76
|
+
raw = resp.read().decode("utf-8") or ""
|
|
77
|
+
if not raw:
|
|
78
|
+
return {}
|
|
79
|
+
try:
|
|
80
|
+
return json.loads(raw)
|
|
81
|
+
except json.JSONDecodeError:
|
|
82
|
+
return raw
|
|
83
|
+
except urllib.error.HTTPError as e:
|
|
84
|
+
raw = e.read().decode("utf-8", errors="replace") or ""
|
|
85
|
+
try:
|
|
86
|
+
parsed: Any = json.loads(raw) if raw else {}
|
|
87
|
+
except json.JSONDecodeError:
|
|
88
|
+
parsed = raw
|
|
89
|
+
raise ApiError(e.code, parsed) from None
|
|
90
|
+
except urllib.error.URLError as e:
|
|
91
|
+
raise ApiError(0, {"code": "network_error", "message": str(e.reason)}) from None
|
|
92
|
+
|
|
93
|
+
def provision(
|
|
94
|
+
self,
|
|
95
|
+
*,
|
|
96
|
+
human_email: str,
|
|
97
|
+
username: str,
|
|
98
|
+
display_name: str | None = None,
|
|
99
|
+
) -> Any:
|
|
100
|
+
payload: dict[str, Any] = {
|
|
101
|
+
"human_email": human_email,
|
|
102
|
+
"username": username,
|
|
103
|
+
}
|
|
104
|
+
if display_name:
|
|
105
|
+
payload["display_name"] = display_name
|
|
106
|
+
return self.request(
|
|
107
|
+
"POST",
|
|
108
|
+
"/v0/agent/provision",
|
|
109
|
+
body=payload,
|
|
110
|
+
auth=False,
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
def whoami(self) -> Any:
|
|
114
|
+
return self.request("GET", "/v0/auth/me")
|
|
115
|
+
|
|
116
|
+
def list_inboxes(self) -> Any:
|
|
117
|
+
return self.request("GET", "/v0/inboxes")
|
|
118
|
+
|
|
119
|
+
def send_message(
|
|
120
|
+
self,
|
|
121
|
+
inbox_id: str,
|
|
122
|
+
*,
|
|
123
|
+
to: list[str],
|
|
124
|
+
subject: str,
|
|
125
|
+
text: str | None = None,
|
|
126
|
+
html: str | None = None,
|
|
127
|
+
idempotency_key: str,
|
|
128
|
+
) -> Any:
|
|
129
|
+
body: dict[str, Any] = {"to": to, "subject": subject}
|
|
130
|
+
if text is not None:
|
|
131
|
+
body["text"] = text
|
|
132
|
+
if html is not None:
|
|
133
|
+
body["html"] = html
|
|
134
|
+
return self.request(
|
|
135
|
+
"POST",
|
|
136
|
+
f"/v0/inboxes/{urllib.parse.quote(inbox_id, safe='@.')}/messages/send",
|
|
137
|
+
body=body,
|
|
138
|
+
headers={"Idempotency-Key": idempotency_key},
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
def list_messages(
|
|
142
|
+
self,
|
|
143
|
+
inbox_id: str,
|
|
144
|
+
*,
|
|
145
|
+
limit: int | None = None,
|
|
146
|
+
unread: bool = False,
|
|
147
|
+
) -> Any:
|
|
148
|
+
query: dict[str, Any] = {}
|
|
149
|
+
if limit is not None:
|
|
150
|
+
query["limit"] = limit
|
|
151
|
+
if unread:
|
|
152
|
+
query["labels"] = "unread"
|
|
153
|
+
return self.request(
|
|
154
|
+
"GET",
|
|
155
|
+
f"/v0/inboxes/{urllib.parse.quote(inbox_id, safe='@.')}/messages",
|
|
156
|
+
query=query or None,
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
def get_message(self, inbox_id: str, message_id: str) -> Any:
|
|
160
|
+
return self.request(
|
|
161
|
+
"GET",
|
|
162
|
+
f"/v0/inboxes/{urllib.parse.quote(inbox_id, safe='@.')}/messages/"
|
|
163
|
+
f"{urllib.parse.quote(message_id, safe='')}",
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
def send_quota(self, inbox_id: str) -> Any:
|
|
167
|
+
return self.request(
|
|
168
|
+
"GET",
|
|
169
|
+
"/v0/extensions/llmworld/send-quota",
|
|
170
|
+
query={"inbox_id": inbox_id},
|
|
171
|
+
)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""Local credentials and base URL resolution."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
DEFAULT_BASE = "https://mail.llmworld.net"
|
|
11
|
+
CONFIG_DIR = Path.home() / ".llmworld"
|
|
12
|
+
CREDENTIALS_PATH = CONFIG_DIR / "credentials.json"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def ensure_config_dir() -> Path:
|
|
16
|
+
CONFIG_DIR.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
17
|
+
return CONFIG_DIR
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def load_credentials() -> dict[str, Any]:
|
|
21
|
+
if not CREDENTIALS_PATH.is_file():
|
|
22
|
+
return {}
|
|
23
|
+
try:
|
|
24
|
+
data = json.loads(CREDENTIALS_PATH.read_text(encoding="utf-8"))
|
|
25
|
+
except (OSError, json.JSONDecodeError):
|
|
26
|
+
return {}
|
|
27
|
+
return data if isinstance(data, dict) else {}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def save_credentials(data: dict[str, Any]) -> Path:
|
|
31
|
+
ensure_config_dir()
|
|
32
|
+
CREDENTIALS_PATH.write_text(
|
|
33
|
+
json.dumps(data, indent=2, ensure_ascii=False) + "\n",
|
|
34
|
+
encoding="utf-8",
|
|
35
|
+
)
|
|
36
|
+
try:
|
|
37
|
+
CREDENTIALS_PATH.chmod(0o600)
|
|
38
|
+
except OSError:
|
|
39
|
+
pass
|
|
40
|
+
return CREDENTIALS_PATH
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def set_api_key(api_key: str, *, base: str | None = None) -> Path:
|
|
44
|
+
data = load_credentials()
|
|
45
|
+
data["api_key"] = api_key.strip()
|
|
46
|
+
if base:
|
|
47
|
+
data["base"] = base.rstrip("/")
|
|
48
|
+
elif "base" not in data:
|
|
49
|
+
data["base"] = DEFAULT_BASE
|
|
50
|
+
return save_credentials(data)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def resolve_base(cli_base: str | None = None) -> str:
|
|
54
|
+
if cli_base:
|
|
55
|
+
return cli_base.rstrip("/")
|
|
56
|
+
env = os.environ.get("MAIL_API_BASE", "").strip()
|
|
57
|
+
if env:
|
|
58
|
+
return env.rstrip("/")
|
|
59
|
+
stored = load_credentials().get("base")
|
|
60
|
+
if isinstance(stored, str) and stored.strip():
|
|
61
|
+
return stored.strip().rstrip("/")
|
|
62
|
+
return DEFAULT_BASE
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def resolve_api_key(cli_key: str | None = None) -> str | None:
|
|
66
|
+
if cli_key and cli_key.strip():
|
|
67
|
+
return cli_key.strip()
|
|
68
|
+
for env_name in ("AGENTMAIL_API_KEY", "MAIL_API_KEY"):
|
|
69
|
+
val = os.environ.get(env_name, "").strip()
|
|
70
|
+
if val:
|
|
71
|
+
return val
|
|
72
|
+
stored = load_credentials().get("api_key")
|
|
73
|
+
if isinstance(stored, str) and stored.strip():
|
|
74
|
+
return stored.strip()
|
|
75
|
+
return None
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: llmworld-agentmail
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: CLI for llmworld Mail (mail.llmworld.net /v0)
|
|
5
|
+
Author: llmworld
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://mail.llmworld.net
|
|
8
|
+
Project-URL: Documentation, https://mail.llmworld.net/llms.txt
|
|
9
|
+
Project-URL: MCP, https://mail.llmworld.net/mcp
|
|
10
|
+
Project-URL: Skill, https://mail.llmworld.net/skills/llmworld-mail/SKILL.md
|
|
11
|
+
Keywords: llmworld,agentmail,email,agent,cli
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Topic :: Communications :: Email
|
|
15
|
+
Requires-Python: >=3.9
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# llmworld-agentmail(CLI + Skill)
|
|
19
|
+
|
|
20
|
+
客户 Agent 对接 [mail.llmworld.net](https://mail.llmworld.net) 的工具包。
|
|
21
|
+
|
|
22
|
+
## 推荐:托管 MCP(零本机 MCP 安装)
|
|
23
|
+
|
|
24
|
+
- URL:https://mail.llmworld.net/mcp
|
|
25
|
+
- 说明:https://mail.llmworld.net/zh/mcp.md
|
|
26
|
+
|
|
27
|
+
## 安装 CLI
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install llmworld-agentmail
|
|
31
|
+
llmworld-agentmail --help
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
备用(本域 wheel,发 PyPI 前/镜像):
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install https://mail.llmworld.net/skills/llmworld-mail/llmworld_agentmail-0.1.0-py3-none-any.whl
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
本地开发:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
cd AgentMail/agent-pack/llmworld-mail
|
|
44
|
+
python3 -m venv .venv && .venv/bin/pip install -e .
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 最小闭环
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
llmworld-agentmail provision --email owner@example.com --username my-agent --pretty
|
|
51
|
+
# STOP — 主人 claim 后:
|
|
52
|
+
llmworld-agentmail config set-key 'am_...'
|
|
53
|
+
llmworld-agentmail whoami --pretty
|
|
54
|
+
llmworld-agentmail send --inbox my-agent@llmworld.net --to alice@example.com --subject Hi --text hello --pretty
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Skill
|
|
58
|
+
|
|
59
|
+
- 公网:https://mail.llmworld.net/skills/llmworld-mail/SKILL.md
|
|
60
|
+
- 索引:https://mail.llmworld.net/llms.txt
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
llmworld_agentmail/__init__.py,sha256=Pwu_u2xAckym6HLgDxzocYygceIP5Hf8NfMIDUGZv6c,98
|
|
2
|
+
llmworld_agentmail/__main__.py,sha256=k1ocEWawweo1qCJWNFAAvyxz3tcY13dzvCenHszij30,48
|
|
3
|
+
llmworld_agentmail/cli.py,sha256=MlVWF6Qq7MxrUZRRb3G8R9ThLbVkfF0uMpN0MI7woJw,8939
|
|
4
|
+
llmworld_agentmail/client.py,sha256=sM_GqbNqGYSuTZ3NopF_0fI0nTCUtJMfc-7v7DQKU9M,5248
|
|
5
|
+
llmworld_agentmail/config.py,sha256=19wmcIKnwjcW9x__UmEX6Nphxpr6X_T5rUac1eQUPNs,2098
|
|
6
|
+
llmworld_agentmail-0.1.0.dist-info/METADATA,sha256=qn_jEyRuR5EHhHAMjOHMSOFBwVX_PperEJXPqeQAbDc,1726
|
|
7
|
+
llmworld_agentmail-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
8
|
+
llmworld_agentmail-0.1.0.dist-info/entry_points.txt,sha256=FgqPX03rL8_2i-Lsu0HsS-s59TqmZhv4kYPbZ5zdG_I,67
|
|
9
|
+
llmworld_agentmail-0.1.0.dist-info/top_level.txt,sha256=v-ujASTNZ290qtDVyPsgfaXCdN9H9MlsDRGyhSdqD8E,19
|
|
10
|
+
llmworld_agentmail-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
llmworld_agentmail
|