synth-code 0.0.1__py3-none-macosx_15_0_arm64.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.
- synth_code/__init__.py +0 -0
- synth_code/account.py +551 -0
- synth_code/account_http.py +86 -0
- synth_code/account_refusal.py +80 -0
- synth_code/accounting.py +148 -0
- synth_code/activity_grouping.py +149 -0
- synth_code/agent_panels.py +127 -0
- synth_code/approvals.py +397 -0
- synth_code/blobs.py +31 -0
- synth_code/cli.py +734 -0
- synth_code/client.py +413 -0
- synth_code/composer_delivery.py +139 -0
- synth_code/conversation.py +949 -0
- synth_code/daemon.py +34 -0
- synth_code/edition.py +306 -0
- synth_code/enrollment.py +304 -0
- synth_code/file_edit_facts.py +10 -0
- synth_code/freeze.py +234 -0
- synth_code/grant.py +59 -0
- synth_code/history.py +140 -0
- synth_code/history_generated.py +219 -0
- synth_code/history_wire.py +166 -0
- synth_code/image_input.py +109 -0
- synth_code/image_preview.py +105 -0
- synth_code/legacy_history.py +161 -0
- synth_code/live_turns.py +171 -0
- synth_code/model_picker.py +311 -0
- synth_code/native/manifest.json +1 -0
- synth_code/native/synth-code-runtime +0 -0
- synth_code/native.py +95 -0
- synth_code/oauth.py +284 -0
- synth_code/operator.py +116 -0
- synth_code/pack_source.py +65 -0
- synth_code/panel_request.py +291 -0
- synth_code/panels.py +40 -0
- synth_code/plugin_host.py +459 -0
- synth_code/protocol.py +35 -0
- synth_code/provider.py +313 -0
- synth_code/provider_fault.py +173 -0
- synth_code/provider_frames.py +571 -0
- synth_code/recommendation.py +324 -0
- synth_code/report.py +72 -0
- synth_code/research_events.py +44 -0
- synth_code/research_trace.py +449 -0
- synth_code/rex_view.py +58 -0
- synth_code/runtime_refusal.py +108 -0
- synth_code/schema/budgets.json +17 -0
- synth_code/schema/history-v2.json +1002 -0
- synth_code/session.py +291 -0
- synth_code/shoal.py +564 -0
- synth_code/side_panel.py +309 -0
- synth_code/skills.py +269 -0
- synth_code/slash.py +425 -0
- synth_code/source_view.py +135 -0
- synth_code/starter.json +13 -0
- synth_code/stdio.py +75 -0
- synth_code/stream.py +142 -0
- synth_code/subscriptions.py +267 -0
- synth_code/synth_authority.py +362 -0
- synth_code/synth_extra.py +32 -0
- synth_code/terminal.py +817 -0
- synth_code/terminal_journal.py +284 -0
- synth_code/terminal_layout.py +643 -0
- synth_code/terminal_surfaces.py +470 -0
- synth_code/terminal_viewport.py +125 -0
- synth_code/tool_render.py +86 -0
- synth_code/transcript_frames.py +212 -0
- synth_code/transcript_placement.py +63 -0
- synth_code/transcript_rows.py +456 -0
- synth_code/transport.py +243 -0
- synth_code/v001_history.py +468 -0
- synth_code/view.py +854 -0
- synth_code/views/__init__.py +93 -0
- synth_code/views/charts.py +196 -0
- synth_code/views/curses_adapter.py +116 -0
- synth_code/views/engine.py +170 -0
- synth_code/views/model.py +226 -0
- synth_code/views/primitives.py +270 -0
- synth_code/views/tiling.py +124 -0
- synth_code-0.0.1.dist-info/METADATA +50 -0
- synth_code-0.0.1.dist-info/RECORD +110 -0
- synth_code-0.0.1.dist-info/WHEEL +5 -0
- synth_code-0.0.1.dist-info/entry_points.txt +6 -0
- synth_code-0.0.1.dist-info/licenses/temper/LICENSE-APACHE +190 -0
- synth_code-0.0.1.dist-info/licenses/temper/LICENSE-MIT +21 -0
- synth_code-0.0.1.dist-info/licenses/temper/SOURCE.json +433 -0
- synth_code-0.0.1.dist-info/top_level.txt +2 -0
- synth_code_plugins/_sdk/__init__.py +19 -0
- synth_code_plugins/_sdk/callback_wire.py +240 -0
- synth_code_plugins/_sdk/callbacks.py +317 -0
- synth_code_plugins/_sdk/compliance.py +51 -0
- synth_code_plugins/_sdk/contracts.py +236 -0
- synth_code_plugins/_sdk/discovery.py +75 -0
- synth_code_plugins/_sdk/job_binding.py +71 -0
- synth_code_plugins/_sdk/lifecycle.py +50 -0
- synth_code_plugins/_sdk/lifecycle_generated.py +15 -0
- synth_code_plugins/_sdk/manifest.py +269 -0
- synth_code_plugins/_sdk/pack.py +332 -0
- synth_code_plugins/_sdk/push.py +98 -0
- synth_code_plugins/_sdk/records.py +26 -0
- synth_code_plugins/_sdk/registry.py +491 -0
- synth_code_plugins/_sdk/schemas.py +210 -0
- synth_code_plugins/_sdk/sources.py +230 -0
- synth_code_plugins/_sdk/surfaces.py +54 -0
- synth_code_plugins/_sdk/tools.py +172 -0
- synth_code_plugins/_sdk/worker_memory.py +49 -0
- synth_code_plugins/core/SKILL.md +6 -0
- synth_code_plugins/core/__init__.py +21 -0
- synth_code_plugins/core/plugin.toml +44 -0
- synth_code_plugins/core/source.py +18 -0
synth_code/stream.py
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"""Cursor transport, observer grants, and bounded diagnostic export."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import secrets
|
|
9
|
+
import time
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def follow(client, after=0, until=None):
|
|
14
|
+
if after < 0 or until is not None and until < after:
|
|
15
|
+
raise ValueError("Invalid cursor range")
|
|
16
|
+
if after == until:
|
|
17
|
+
return
|
|
18
|
+
with client.subscribe(after) as subscription:
|
|
19
|
+
for frame in subscription:
|
|
20
|
+
kind = frame["type"]
|
|
21
|
+
if kind == "refused":
|
|
22
|
+
raise frame["error"]
|
|
23
|
+
if kind == "caught_up" and frame.get("terminal"):
|
|
24
|
+
return
|
|
25
|
+
if kind != "event":
|
|
26
|
+
continue
|
|
27
|
+
row = frame["event"]
|
|
28
|
+
if row.get("event_id") != f"{client.run}/{row['seq']}":
|
|
29
|
+
raise ValueError("Discontinuous event stream")
|
|
30
|
+
after = row["seq"]
|
|
31
|
+
yield row
|
|
32
|
+
if after == until:
|
|
33
|
+
return
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def viewer(client, identity, path, revoke=False):
|
|
37
|
+
# Retain the secret before the grant RPC so retries use the same operation.
|
|
38
|
+
path = Path(path)
|
|
39
|
+
if not path.exists() and not revoke:
|
|
40
|
+
key = secrets.token_hex(32)
|
|
41
|
+
fd = os.open(path, os.O_WRONLY | os.O_EXCL | os.O_CREAT | os.O_NOFOLLOW, 0o600)
|
|
42
|
+
with os.fdopen(fd, "w") as out:
|
|
43
|
+
out.write(key + "\n")
|
|
44
|
+
out.flush()
|
|
45
|
+
os.fsync(out.fileno())
|
|
46
|
+
if path.is_symlink() or path.stat().st_mode & 0o077:
|
|
47
|
+
raise ValueError("A private viewer credential file is required")
|
|
48
|
+
secret = path.read_text().strip()
|
|
49
|
+
if len(secret) != 64 or not all(c in "0123456789abcdef" for c in secret):
|
|
50
|
+
raise ValueError("Invalid viewer credential")
|
|
51
|
+
return client.send(
|
|
52
|
+
"viewer",
|
|
53
|
+
id=identity,
|
|
54
|
+
digest=hashlib.sha256(secret.encode()).hexdigest(),
|
|
55
|
+
revoke=revoke,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _usage_counters(usage) -> dict[str, int]:
|
|
60
|
+
if not isinstance(usage, dict):
|
|
61
|
+
return {}
|
|
62
|
+
counters: dict[str, int] = {}
|
|
63
|
+
for src, dst in (
|
|
64
|
+
("inputTokens", "inputTokens"),
|
|
65
|
+
("input_tokens", "inputTokens"),
|
|
66
|
+
("outputTokens", "outputTokens"),
|
|
67
|
+
("output_tokens", "outputTokens"),
|
|
68
|
+
("cachedInputTokens", "cachedInputTokens"),
|
|
69
|
+
("cached_input_tokens", "cachedInputTokens"),
|
|
70
|
+
("totalTokens", "totalTokens"),
|
|
71
|
+
("total_tokens", "totalTokens"),
|
|
72
|
+
):
|
|
73
|
+
val = usage.get(src)
|
|
74
|
+
if type(val) is int and dst not in counters:
|
|
75
|
+
counters[dst] = val
|
|
76
|
+
details = usage.get("input_tokens_details")
|
|
77
|
+
if isinstance(details, dict) and "cachedInputTokens" not in counters:
|
|
78
|
+
cached = details.get("cached_tokens")
|
|
79
|
+
if type(cached) is int:
|
|
80
|
+
counters["cachedInputTokens"] = cached
|
|
81
|
+
return counters
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def diagnostic(client, destination, after, ttl):
|
|
85
|
+
if not 1 <= ttl <= 86400 or after < 0:
|
|
86
|
+
raise ValueError("Invalid diagnostic bounds")
|
|
87
|
+
folder = Path(destination)
|
|
88
|
+
folder.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
89
|
+
if folder.is_symlink() or folder.stat().st_mode & 0o077:
|
|
90
|
+
raise ValueError("Private diagnostic directory required")
|
|
91
|
+
now = int(time.time())
|
|
92
|
+
purge(folder, now)
|
|
93
|
+
head = client.send("snapshot")["cursor"]
|
|
94
|
+
rows = []
|
|
95
|
+
while after < head and len(rows) < 512:
|
|
96
|
+
batch = client.send("events", after=after, limit=min(32, 512 - len(rows)))
|
|
97
|
+
for event in batch["events"]:
|
|
98
|
+
if event["seq"] > head:
|
|
99
|
+
break
|
|
100
|
+
data = event["payload"]
|
|
101
|
+
result = data.get("result")
|
|
102
|
+
# Use a fixed field allowlist. Operator text and raw adapter errors are excluded.
|
|
103
|
+
raw_usage = data.get("usage")
|
|
104
|
+
usage = (
|
|
105
|
+
raw_usage
|
|
106
|
+
if isinstance(raw_usage, dict)
|
|
107
|
+
else (result.get("usage") if isinstance(result, dict) else None)
|
|
108
|
+
)
|
|
109
|
+
counters = _usage_counters(usage)
|
|
110
|
+
rows.append(
|
|
111
|
+
{k: event[k] for k in ("seq", "cause", "kind", "at")}
|
|
112
|
+
| {"usage": counters}
|
|
113
|
+
)
|
|
114
|
+
after = event["seq"]
|
|
115
|
+
if not batch["events"]:
|
|
116
|
+
break
|
|
117
|
+
name = f"synth-diag-{now + ttl}-{secrets.token_hex(8)}.json"
|
|
118
|
+
with (folder / name).open("x") as out:
|
|
119
|
+
json.dump(
|
|
120
|
+
{
|
|
121
|
+
"version": 1,
|
|
122
|
+
"expires": now + ttl,
|
|
123
|
+
"through": after,
|
|
124
|
+
"head": head,
|
|
125
|
+
"events": rows,
|
|
126
|
+
},
|
|
127
|
+
out,
|
|
128
|
+
)
|
|
129
|
+
return {"path": str(folder / name), "through": after, "expires": now + ttl}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def purge(directory, now=None):
|
|
133
|
+
import re
|
|
134
|
+
|
|
135
|
+
now = int(time.time()) if now is None else now
|
|
136
|
+
removed = 0
|
|
137
|
+
for p in Path(directory).glob("synth-diag-*.json"):
|
|
138
|
+
m = re.fullmatch(r"synth-diag-(\d+)-[0-9a-f]{16}\.json", p.name)
|
|
139
|
+
if m and int(m[1]) <= now and p.is_file() and not p.is_symlink():
|
|
140
|
+
p.unlink()
|
|
141
|
+
removed += 1
|
|
142
|
+
return removed
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"""Read displayable subscription facts on demand, without starting model turns."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from decimal import Decimal
|
|
5
|
+
from enum import StrEnum
|
|
6
|
+
|
|
7
|
+
from . import account
|
|
8
|
+
from .account_http import SERVICE_HTTP, AdapterCode, AdapterError, api
|
|
9
|
+
from .edition import beta_env
|
|
10
|
+
|
|
11
|
+
SERVICE_TIERS = ("standard", "fast", "ultrafast")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def service_tiers(model):
|
|
15
|
+
advertised = {
|
|
16
|
+
tier["name"].lower(): tier["id"] for tier in model.get("serviceTiers", [])
|
|
17
|
+
}
|
|
18
|
+
# App-server supports explicit default speed even when the catalog only lists upgrades.
|
|
19
|
+
advertised.setdefault("standard", "default")
|
|
20
|
+
return {name: advertised[name] for name in SERVICE_TIERS if name in advertised}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def tier_label(tier, details):
|
|
24
|
+
if tier is None:
|
|
25
|
+
return details.get("tier")
|
|
26
|
+
return next(
|
|
27
|
+
(
|
|
28
|
+
name
|
|
29
|
+
for name, identity in details.get("service_tiers", {}).items()
|
|
30
|
+
if identity == tier
|
|
31
|
+
),
|
|
32
|
+
{"default": "standard", "priority": "fast"}.get(tier, tier),
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def preview_tier(tier, details):
|
|
37
|
+
label = tier_label(tier, details)
|
|
38
|
+
return None if label in ("standard", "default", "auto") else label
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def available_models(provider, workspace=None):
|
|
42
|
+
if provider == "inkling-2-mini":
|
|
43
|
+
return {provider: {"tier": "standard", "service_tiers": {"standard": "default"}}}
|
|
44
|
+
raise ValueError("This provider does not expose selectable models")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@dataclass(frozen=True, slots=True)
|
|
48
|
+
class AccountStatus:
|
|
49
|
+
state: str
|
|
50
|
+
details: tuple[tuple[str, str], ...]
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def synth():
|
|
54
|
+
try:
|
|
55
|
+
if (
|
|
56
|
+
not beta_env("SYNTH_CODE_CUSTOMER_KEY")
|
|
57
|
+
and not account.authority().status().authenticated
|
|
58
|
+
):
|
|
59
|
+
return ("Signed out", "", "")
|
|
60
|
+
base, token = account.customer()
|
|
61
|
+
receipt = account.account_receipt(base, token)
|
|
62
|
+
except ImportError:
|
|
63
|
+
return ("Synth SDK unavailable", "", "")
|
|
64
|
+
except AdapterError as exc:
|
|
65
|
+
return (
|
|
66
|
+
"Sign-in expired"
|
|
67
|
+
if exc.kind == AdapterCode(SERVICE_HTTP, status=401)
|
|
68
|
+
else "Account unavailable",
|
|
69
|
+
"",
|
|
70
|
+
"",
|
|
71
|
+
)
|
|
72
|
+
principal = receipt["principal"]
|
|
73
|
+
details = (
|
|
74
|
+
("Email", principal.get("email")),
|
|
75
|
+
("User", principal.get("user_id")),
|
|
76
|
+
("Organization", receipt.get("organization")),
|
|
77
|
+
("Plan", receipt["plan"]),
|
|
78
|
+
("Allowance", allowance(base, token, receipt.get("org_id")).render()),
|
|
79
|
+
)
|
|
80
|
+
return AccountStatus(
|
|
81
|
+
"Connected", tuple((label, value) for label, value in details if value)
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class AllowanceRefusal(StrEnum):
|
|
86
|
+
FETCH_FAILED = "allowance_fetch_failed"
|
|
87
|
+
ORG_MISMATCH = "allowance_org_mismatch"
|
|
88
|
+
MALFORMED = "allowance_malformed"
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@dataclass(frozen=True, slots=True)
|
|
92
|
+
class Allowance:
|
|
93
|
+
remaining: Decimal
|
|
94
|
+
limit: Decimal
|
|
95
|
+
reset_at: str
|
|
96
|
+
|
|
97
|
+
def render(self) -> str:
|
|
98
|
+
return f"${self.remaining:.2f} / ${self.limit:.2f} left · resets {self.reset_at}"
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@dataclass(frozen=True, slots=True)
|
|
102
|
+
class NoIncludedAllowance:
|
|
103
|
+
def render(self) -> str:
|
|
104
|
+
return "None"
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@dataclass(frozen=True, slots=True)
|
|
108
|
+
class AllowanceUnavailable:
|
|
109
|
+
code: AllowanceRefusal
|
|
110
|
+
stage: str
|
|
111
|
+
cause: str
|
|
112
|
+
|
|
113
|
+
def render(self) -> str:
|
|
114
|
+
return f"Unavailable ({self.code}: {self.cause})"
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def allowance(base, token, organization) -> Allowance | NoIncludedAllowance | AllowanceUnavailable:
|
|
118
|
+
"""Included allowance from the billing balance, verified against the signed-in org."""
|
|
119
|
+
from .enrollment import money, seconds
|
|
120
|
+
|
|
121
|
+
try:
|
|
122
|
+
funding, _ = api(base + "/v1/billing/balance", token)
|
|
123
|
+
except AdapterError as exc:
|
|
124
|
+
return AllowanceUnavailable(AllowanceRefusal.FETCH_FAILED, "billing.balance", exc.code)
|
|
125
|
+
try:
|
|
126
|
+
if funding["org_id"] != organization:
|
|
127
|
+
return AllowanceUnavailable(
|
|
128
|
+
AllowanceRefusal.ORG_MISMATCH, "billing.balance.org_id", "balance belongs to another organization"
|
|
129
|
+
)
|
|
130
|
+
included = funding["included_allowance"]
|
|
131
|
+
if included is None:
|
|
132
|
+
return NoIncludedAllowance()
|
|
133
|
+
remaining = money(included["remaining"]) / 1000000
|
|
134
|
+
limit = money(included["limit"]) / 1000000
|
|
135
|
+
reset = included["reset_at"]
|
|
136
|
+
seconds(reset)
|
|
137
|
+
except AdapterError as exc:
|
|
138
|
+
return AllowanceUnavailable(AllowanceRefusal.MALFORMED, "billing.balance.included_allowance", exc.code)
|
|
139
|
+
except (KeyError, TypeError, ValueError) as exc:
|
|
140
|
+
return AllowanceUnavailable(
|
|
141
|
+
AllowanceRefusal.MALFORMED, "billing.balance.included_allowance", f"{type(exc).__name__}: {exc}"
|
|
142
|
+
)
|
|
143
|
+
return Allowance(remaining, limit, reset)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
@dataclass(frozen=True)
|
|
147
|
+
class SlotStatus:
|
|
148
|
+
state: str
|
|
149
|
+
principal: str | None
|
|
150
|
+
model: str | None
|
|
151
|
+
reason: str | None = None
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def synth_login(action="synth"):
|
|
155
|
+
"""Run Synth account sign-in; the only sign-in synth-code offers."""
|
|
156
|
+
if action not in ("", "status", "synth", "synth device"):
|
|
157
|
+
raise ValueError("Usage: /login [synth|synth device]")
|
|
158
|
+
if action in ("", "status"):
|
|
159
|
+
return synth().state
|
|
160
|
+
import curses
|
|
161
|
+
|
|
162
|
+
from .account import reauthenticate
|
|
163
|
+
|
|
164
|
+
curses.def_prog_mode()
|
|
165
|
+
curses.endwin()
|
|
166
|
+
try:
|
|
167
|
+
return reauthenticate(True if action == "synth device" else None)
|
|
168
|
+
except ImportError:
|
|
169
|
+
return "Install synth-code[synth] to sign in"
|
|
170
|
+
except RuntimeError as error:
|
|
171
|
+
# account.reauthenticate carries the refusal code: "Synth account sign-in failed: <code>".
|
|
172
|
+
return str(error)
|
|
173
|
+
except KeyboardInterrupt:
|
|
174
|
+
return "Synth sign-in canceled"
|
|
175
|
+
finally:
|
|
176
|
+
curses.reset_prog_mode()
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
OPTIONS = (("Synth", "synth", synth),)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
BINDINGS = {"synth": "inkling-2-mini"}
|
|
183
|
+
ROLE_FIELDS = {"core": ("core",), "side": ("side",), "both": ("core", "side")}
|
|
184
|
+
ROLE_LABELS = {"core": "Core + subagents", "side": "Side agents", "both": "Both"}
|
|
185
|
+
ACTIONS = ("login", *ROLE_FIELDS)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def assigned_roles(profile, provider):
|
|
189
|
+
core = profile.get("core") == provider
|
|
190
|
+
side = profile.get("side") == provider
|
|
191
|
+
if core and side:
|
|
192
|
+
return "Core + subagents and side agents"
|
|
193
|
+
if core:
|
|
194
|
+
return ROLE_LABELS["core"]
|
|
195
|
+
if side:
|
|
196
|
+
return ROLE_LABELS["side"]
|
|
197
|
+
return "Unassigned"
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def assign(client, arguments, profile, revision):
|
|
201
|
+
parts = arguments.split()
|
|
202
|
+
if (
|
|
203
|
+
len(parts) != 3
|
|
204
|
+
or parts[0] != "set"
|
|
205
|
+
or parts[1] not in BINDINGS
|
|
206
|
+
or parts[2] not in ROLE_FIELDS
|
|
207
|
+
):
|
|
208
|
+
raise ValueError("Usage: /providers set synth core|side|both")
|
|
209
|
+
if not revision:
|
|
210
|
+
raise ValueError("No active profile")
|
|
211
|
+
_, provider, scope = parts
|
|
212
|
+
changes = dict.fromkeys(ROLE_FIELDS[scope], BINDINGS[provider])
|
|
213
|
+
result = client.send(
|
|
214
|
+
"configure", profile=profile | changes, expected_revision=revision
|
|
215
|
+
)
|
|
216
|
+
if not result["active"]:
|
|
217
|
+
raise ValueError("Provider profile was not activated")
|
|
218
|
+
return f"{ROLE_LABELS[scope]} · {BINDINGS[provider]}"
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def picker_lines(futures, selected, profile=None, action="login"):
|
|
222
|
+
lines = []
|
|
223
|
+
for index, ((label, _, _), future) in enumerate(zip(OPTIONS, futures, strict=True)):
|
|
224
|
+
facts = ("Checking…", "", "")
|
|
225
|
+
if future.done():
|
|
226
|
+
facts = (
|
|
227
|
+
("Account unavailable", "", "")
|
|
228
|
+
if future.exception()
|
|
229
|
+
else future.result()
|
|
230
|
+
)
|
|
231
|
+
if isinstance(facts, AccountStatus):
|
|
232
|
+
state, details = facts.state, facts.details
|
|
233
|
+
elif isinstance(facts, SlotStatus):
|
|
234
|
+
state = facts.state
|
|
235
|
+
details = (
|
|
236
|
+
(("Status", facts.reason),)
|
|
237
|
+
if facts.reason
|
|
238
|
+
else (("Principal", facts.principal), ("Model", facts.model))
|
|
239
|
+
)
|
|
240
|
+
else:
|
|
241
|
+
state, email, plan = facts
|
|
242
|
+
details = tuple(
|
|
243
|
+
(name, value) for name, value in (("Email", email), ("Plan", plan)) if value
|
|
244
|
+
)
|
|
245
|
+
lines.append(f"{'›' if index == selected else ' '} {label} · {state}")
|
|
246
|
+
if index == selected:
|
|
247
|
+
label_width = max((len(name) for name, _ in details), default=0)
|
|
248
|
+
for name, value in details:
|
|
249
|
+
lines.append(f" {name:<{label_width}} {value or 'Unavailable'}")
|
|
250
|
+
if profile is not None:
|
|
251
|
+
lines.append(
|
|
252
|
+
f" Roles {assigned_roles(profile, BINDINGS[OPTIONS[index][1]])}"
|
|
253
|
+
)
|
|
254
|
+
if profile is not None:
|
|
255
|
+
labels = {"login": "Sign in", **ROLE_LABELS}
|
|
256
|
+
lines.append(
|
|
257
|
+
" ".join(
|
|
258
|
+
f"[{title}]" if name == action else title
|
|
259
|
+
for name, title in labels.items()
|
|
260
|
+
)
|
|
261
|
+
)
|
|
262
|
+
if action == "login":
|
|
263
|
+
choice = f"/login {OPTIONS[selected][1]}"
|
|
264
|
+
else:
|
|
265
|
+
choice = f"Assign to {ROLE_LABELS[action]}"
|
|
266
|
+
lines.append(f"↑↓ provider · ←→ action · Enter {choice} · Esc close")
|
|
267
|
+
return lines
|