witbitz-code 1.15.6__tar.gz → 1.15.8__tar.gz
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.
- {witbitz_code-1.15.6/src/witbitz_code.egg-info → witbitz_code-1.15.8}/PKG-INFO +1 -1
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/pyproject.toml +2 -2
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/__init__.py +1 -1
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/app.py +5 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/cli.py +24 -2
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/codekeys.py +10 -6
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/confidential.py +150 -2
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/connector.py +1 -1
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/device.py +4 -2
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/models.py +10 -2
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/pairings.py +23 -4
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/seccheck.py +7 -3
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/ui.py +19 -1
- witbitz_code-1.15.8/src/witbitz_code/venice.py +204 -0
- witbitz_code-1.15.8/src/witbitz_code/venice_models.json +147 -0
- witbitz_code-1.15.8/src/witbitz_code/winrun.py +34 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/wslstart.py +3 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8/src/witbitz_code.egg-info}/PKG-INFO +1 -1
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code.egg-info/SOURCES.txt +5 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_codekeys.py +1 -1
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_pair_flows.py +17 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_ui.py +57 -0
- witbitz_code-1.15.8/tests/test_venice.py +155 -0
- witbitz_code-1.15.8/tests/test_winrun.py +44 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/LICENSE +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/README.md +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/setup.cfg +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/__main__.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/_js.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/account.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/asks.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/attachments.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/auto.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/auto_runner.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/browse.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/browsetree.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/codetools.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/compress.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/computers.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/confidential_models.json +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/devicelink.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/dirs.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/files.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/folders.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/gateway.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/icons/witbitz-code-wsl.ico +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/icons/witbitz-code.ico +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/images.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/keys.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/link.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/mkdir.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/net.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/offered_models.json +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/opencode_plugins/notes-init.md +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/opencode_plugins/witbitz-browse-cdp.mjs +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/opencode_plugins/witbitz-browse-local.mjs +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/opencode_plugins/witbitz-browse-publisher.mjs +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/opencode_plugins/witbitz-browse-tree.mjs +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/opencode_plugins/witbitz-browser.js +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/opencode_plugins/witbitz-media-server.mjs +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/opencode_plugins/witbitz-notes.js +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/opencode_plugins/witbitz-progress.js +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/outputs.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/pair.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/payers.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/plugins.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/policy.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/ports.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/qr.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/receipt.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/relay.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/remind.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/seen.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/selfupdate.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/tinfoil_read.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/tools_catalog.json +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/tools_probe.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/toolsetup.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/ui_static/app.css +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/ui_static/app.js +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/ui_static/index.html +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/uitools.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/uninstall.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/winagent.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/winbg.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/winconsole.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code/wizard.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code.egg-info/dependency_links.txt +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code.egg-info/entry_points.txt +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code.egg-info/requires.txt +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/src/witbitz_code.egg-info/top_level.txt +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_asks.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_attachments.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_auto.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_browse.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_browsetree.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_cli.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_codetools.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_confidential.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_connector_e2e.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_device.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_devicelink.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_dirs.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_files.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_files_and_compress.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_folders.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_images.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_outputs.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_plugins.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_policy.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_ports.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_ports_win.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_registry.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_relay_codec.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_remind.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_seccheck.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_selfupdate.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_setup.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_tools_probe.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_toolsetup.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_ui_page.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_uitools.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_uninstall.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_winagent.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_winbg.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_winconsole.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_windows_files.py +0 -0
- {witbitz_code-1.15.6 → witbitz_code-1.15.8}/tests/test_wslstart.py +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "witbitz-code"
|
|
7
|
-
version = "1.15.
|
|
7
|
+
version = "1.15.8"
|
|
8
8
|
description = "Reach OpenCode on this computer from the Witbitz Spaces Code section, through an end-to-end sealed relay."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -45,7 +45,7 @@ where = ["src"]
|
|
|
45
45
|
|
|
46
46
|
# Our OpenCode plugins, installed by `serve` (plugins.py) — copies of tools/opencode-plugins, kept current by embed.mjs
|
|
47
47
|
[tool.setuptools.package-data]
|
|
48
|
-
witbitz_code = ["opencode_plugins/*", "confidential_models.json", "offered_models.json", "tools_catalog.json", "ui_static/*", "icons/*"]
|
|
48
|
+
witbitz_code = ["opencode_plugins/*", "confidential_models.json", "offered_models.json", "tools_catalog.json", "venice_models.json", "ui_static/*", "icons/*"]
|
|
49
49
|
|
|
50
50
|
[tool.pytest.ini_options]
|
|
51
51
|
testpaths = ["tests"]
|
|
@@ -64,6 +64,11 @@ def ports() -> range:
|
|
|
64
64
|
return range(base_port(), base_port() + PORTS_PER_APP)
|
|
65
65
|
|
|
66
66
|
|
|
67
|
+
def origin_of(which: str) -> str:
|
|
68
|
+
"""An app's origin, by name (REGULAR / VAULTED)."""
|
|
69
|
+
return _APPS[which]["origin"]
|
|
70
|
+
|
|
71
|
+
|
|
67
72
|
def origin() -> str:
|
|
68
73
|
"""The app's origin for an account call with no pairing to name it."""
|
|
69
74
|
return _APPS[name()]["origin"]
|
|
@@ -27,6 +27,7 @@ from . import __version__, app
|
|
|
27
27
|
from . import pair as pair_cmd
|
|
28
28
|
from . import pairings as pp
|
|
29
29
|
from . import browse as browse_mod, codekeys, codetools, confidential, keys, models, plugins, policy, ports, toolsetup, uninstall as uninstall_mod, winagent, winbg, winconsole, wizard, wslstart
|
|
30
|
+
from . import venice as vn # the zero-retention models (docs/code-venice-fallback.md)
|
|
30
31
|
from ._js import to_number, truthy
|
|
31
32
|
from .connector import pairings_for_port, start_connector
|
|
32
33
|
from .payers import SessionPayers
|
|
@@ -44,6 +45,8 @@ HELP = f"""witbitz-code {__version__} — reach OpenCode on this computer from t
|
|
|
44
45
|
serve [--port <n>] [--no-opencode] [--no-browser] [--private-browser]
|
|
45
46
|
start OpenCode on 127.0.0.1 with your account's keys, and the connector
|
|
46
47
|
status list this computer's pairings and their coding keys
|
|
48
|
+
image-reader [<model>|off] who reads pictures for a text-only model that is NOT confidential: a zero-retention
|
|
49
|
+
model (Venice) — not confidential. Off by default. With no argument: what is set.
|
|
47
50
|
rotate [--account <email>] replace the pairing secret(s) without a scan, then restart serve
|
|
48
51
|
unpair [--account <email>] remove this computer from an account
|
|
49
52
|
uninstall [--yes] [--remove-keys] [--remove-notes] [--remove-sessions] [--remove-opencode]
|
|
@@ -54,6 +57,10 @@ Model calls go from this computer straight to TrustedRouter and Tinfoil, each bi
|
|
|
54
57
|
"""
|
|
55
58
|
|
|
56
59
|
|
|
60
|
+
def _image_reader_path() -> str:
|
|
61
|
+
return str(codekeys.keys_path().parent / "image-reader.json")
|
|
62
|
+
|
|
63
|
+
|
|
57
64
|
def _err(msg: str) -> None:
|
|
58
65
|
print(msg, file=sys.stderr, flush=True)
|
|
59
66
|
|
|
@@ -255,14 +262,14 @@ async def serve(args: list[str], *, stop: Any = None, live_out: dict | None = No
|
|
|
255
262
|
try:
|
|
256
263
|
proxy = await confidential.start_confidential_proxy(port=pport, log=_err, on_progress=lambda ev: live["connector"] and live["connector"].progress(ev),
|
|
257
264
|
credential_for=credential_for, offered=lambda m: m in offered,
|
|
258
|
-
on_key_refused=key_refused)
|
|
265
|
+
on_key_refused=key_refused, image_reader=vn.reader_setting(_image_reader_path()))
|
|
259
266
|
except OSError as e:
|
|
260
267
|
held = "; ".join(f"{(o.get('cmd') or 'a program')[:70]} (process {o['pid']})" for o in ports.port_owners(pport))
|
|
261
268
|
_err(f"witbitz-code: could not start the model proxy on 127.0.0.1:{pport} ({e})"
|
|
262
269
|
+ (f" — held by {held}: an earlier witbitz-code still running? witbitz-code setup offers to stop it" if held
|
|
263
270
|
else " — free that port and run serve again"))
|
|
264
271
|
return 1
|
|
265
|
-
route = {**models.proxy_config(proxy.port), **models.default_model_config()}
|
|
272
|
+
route = {**models.proxy_config(proxy.port, image_reader=vn.reader_setting(_image_reader_path())()), **models.default_model_config()}
|
|
266
273
|
if await is_listening(port) and "--no-opencode" not in args:
|
|
267
274
|
_err(f"witbitz-code: OpenCode is already running on 127.0.0.1:{port}, started some other way — it cannot use your account's keys.")
|
|
268
275
|
_err(" Close it, then run witbitz-code serve again (it starts OpenCode itself).")
|
|
@@ -491,6 +498,21 @@ async def _main(argv: list[str]) -> int:
|
|
|
491
498
|
return await ui_command(rest)
|
|
492
499
|
if cmd == "status":
|
|
493
500
|
return await pair_cmd.main(["--status"])
|
|
501
|
+
if cmd == "image-reader":
|
|
502
|
+
want = rest[0] if rest else ""
|
|
503
|
+
if not want:
|
|
504
|
+
m = vn.reader_setting(_image_reader_path())()
|
|
505
|
+
print(f"{vn.entry(m)['label']} ({m}) reads images for text-only models that are not confidential — not confidentially" if m
|
|
506
|
+
else f"off — text-only models get no images. To set one: witbitz-code image-reader <model>, one of {', '.join(vn.VENICE_READERS)}")
|
|
507
|
+
return 0
|
|
508
|
+
try:
|
|
509
|
+
m = vn.set_reader(_image_reader_path(), want)
|
|
510
|
+
except ValueError as e:
|
|
511
|
+
_err(f"witbitz-code: {e}")
|
|
512
|
+
return 2
|
|
513
|
+
print((f"set: {vn.entry(m)['label']} reads images for text-only models that are not confidential. A confidential model's images are still read only inside Tinfoil's enclave." if m
|
|
514
|
+
else "off: text-only models get no images") + "\nRestart serve for OpenCode to take it.")
|
|
515
|
+
return 0
|
|
494
516
|
if cmd == "rotate":
|
|
495
517
|
return await pair_cmd.main(["--rotate", *rest])
|
|
496
518
|
if cmd == "unpair":
|
|
@@ -30,7 +30,7 @@ from . import app as app_mod
|
|
|
30
30
|
from . import pairings as pp
|
|
31
31
|
|
|
32
32
|
API = "https://api.witbitz.chat/v1/spaces/code-keys"
|
|
33
|
-
PROVIDERS = ("trustedrouter", "tinfoil")
|
|
33
|
+
PROVIDERS = ("trustedrouter", "tinfoil", "venice") # venice: the zero-retention models (docs/code-venice-fallback.md)
|
|
34
34
|
STATUS_EVERY_S = 6 * 3600
|
|
35
35
|
SIGNIN_MIN_LEFT_S = 86_400 # = codeKeys.mjs SIGNIN_MIN_LEFT_SEC
|
|
36
36
|
|
|
@@ -221,6 +221,7 @@ def _take(entry: dict, d: dict) -> dict:
|
|
|
221
221
|
computer's own identity. Raises CodeKeyRefusal when they cannot be opened."""
|
|
222
222
|
entry.update({"keyId": d.get("keyId"), "tenantId": d.get("tenantId"), "userId": d.get("userId"), "kid": d.get("kid"), "caps": d.get("caps") or {}})
|
|
223
223
|
entry.pop("tinfoil", None)
|
|
224
|
+
entry.pop("venice", None)
|
|
224
225
|
sealed = d.get("sealed") or {}
|
|
225
226
|
for provider in PROVIDERS:
|
|
226
227
|
if sealed.get(provider):
|
|
@@ -313,11 +314,14 @@ async def status(client: httpx.AsyncClient, entry: dict) -> dict:
|
|
|
313
314
|
except CodeKeyRefusal as e:
|
|
314
315
|
return {"live": None, "why": str(e)}
|
|
315
316
|
return d
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
317
|
+
# a key minted or renewed server-side after the pairing (Tinfoil's, Venice's) arrives sealed in a status answer
|
|
318
|
+
for p in ("tinfoil", "venice"):
|
|
319
|
+
blob = (d.get("sealed") or {}).get(p)
|
|
320
|
+
if not blob:
|
|
321
|
+
continue
|
|
322
|
+
secret = open_sealed(blob, entry, aad(entry["tenantId"], entry["userId"], entry["kid"], p))
|
|
319
323
|
if secret:
|
|
320
|
-
entry[
|
|
324
|
+
entry[p] = secret
|
|
321
325
|
d["changed"] = True
|
|
322
326
|
return d
|
|
323
327
|
|
|
@@ -378,7 +382,7 @@ class LiveKeys:
|
|
|
378
382
|
e = self.entries.get(computer_id)
|
|
379
383
|
if not e:
|
|
380
384
|
return {"refuse": REVOKED_TEXT}
|
|
381
|
-
return {"trustedrouter": e.get("trustedrouter", ""), "tinfoil": e.get("tinfoil", "")}
|
|
385
|
+
return {"trustedrouter": e.get("trustedrouter", ""), "tinfoil": e.get("tinfoil", ""), "venice": e.get("venice", "")}
|
|
382
386
|
|
|
383
387
|
async def check(self, client: httpx.AsyncClient, say: Any = lambda _m: None) -> None:
|
|
384
388
|
self._fresh()
|
|
@@ -20,6 +20,7 @@ from __future__ import annotations
|
|
|
20
20
|
|
|
21
21
|
import asyncio
|
|
22
22
|
import json
|
|
23
|
+
import os
|
|
23
24
|
import re
|
|
24
25
|
import time
|
|
25
26
|
from typing import Any, Callable
|
|
@@ -30,6 +31,7 @@ from . import images, keys, models as mdl, receipt as rcp, tinfoil_read
|
|
|
30
31
|
from .gateway import verify_gateway_attestation
|
|
31
32
|
|
|
32
33
|
TR_UPSTREAM = "https://api.trustedrouter.com"
|
|
34
|
+
from . import venice as vn # the zero-retention models the person may pick (docs/code-venice-fallback.md)
|
|
33
35
|
GATE_TTL_MS = 600_000
|
|
34
36
|
MAX_BODY = 40 * 1024 * 1024
|
|
35
37
|
HOLD_BEFORE_LAPSE_SEC = 90
|
|
@@ -138,6 +140,30 @@ async def convert_unreadable(body: dict, label: str, to_text: Callable | None) -
|
|
|
138
140
|
CONFIDENTIAL_PROVIDERS = ("tinfoil",)
|
|
139
141
|
|
|
140
142
|
|
|
143
|
+
async def describe_images(body: dict, label: str, to_text: Callable) -> dict:
|
|
144
|
+
"""Replace every IMAGE part with the selected reader's description (= describeImages) — not confidentially, and said so."""
|
|
145
|
+
parts = [p for p in unreadable_parts(body) if p["kind"] == "image"]
|
|
146
|
+
if not parts:
|
|
147
|
+
return body
|
|
148
|
+
messages = [({**m, "content": list(m["content"])} if isinstance(m.get("content"), list) else m) for m in body["messages"]]
|
|
149
|
+
who = getattr(to_text, "label", "another model")
|
|
150
|
+
for p in parts:
|
|
151
|
+
mi, pi = p["at"]
|
|
152
|
+
if p.get("remote") or not p.get("b64"):
|
|
153
|
+
raise Refusal(400, f"{label} cannot read an image that is not attached inline.")
|
|
154
|
+
question = ("Describe this image for a coding assistant that cannot see it: its layout and every visible piece of text, code, numbers and UI "
|
|
155
|
+
f"elements, quoted verbatim. The person's message with it: \"{_text_of(body['messages'][mi])[:600]}\"")
|
|
156
|
+
try:
|
|
157
|
+
text = await to_text(p, question)
|
|
158
|
+
except Exception as e: # noqa: BLE001
|
|
159
|
+
said = getattr(e, "said", None)
|
|
160
|
+
if said:
|
|
161
|
+
raise Refusal(said[0], said[1], said[2]) from None
|
|
162
|
+
raise Refusal(502, f"{label}: {who} could not read an image ({str(e)[:140]}).", "image_reader_failed") from None
|
|
163
|
+
messages[mi]["content"][pi] = {"type": "text", "text": f"[An image was attached. This model cannot see images, so {who} read it — not confidentially; this is what it shows:]\n{text}"}
|
|
164
|
+
return {**body, "messages": messages}
|
|
165
|
+
|
|
166
|
+
|
|
141
167
|
def stamp_floor(req: dict) -> dict:
|
|
142
168
|
"""The confidential floor, as a confidential room stamps it. Key ORDER matters — the receipt signs these exact bytes."""
|
|
143
169
|
return {**req, "stream": True, "stream_options": {"include_usage": True}, "provider": {**(req.get("provider") or {}), "min_privacy": "confidential", "only": list(CONFIDENTIAL_PROVIDERS)}}
|
|
@@ -500,7 +526,9 @@ class ConfidentialProxy:
|
|
|
500
526
|
reader: Any = "default", log: Callable[[str], Any] = print, policies: set | None = None,
|
|
501
527
|
verify: Callable | None = None, sleep: Callable = asyncio.sleep, on_progress: Callable[[dict], Any] = lambda ev: None,
|
|
502
528
|
cache_marks: bool = True, credential_for: Callable[["_Request"], dict | None] | None = None,
|
|
503
|
-
offered: Callable[[str], bool] | None = None, on_key_refused: Callable[[], Any] = lambda: None
|
|
529
|
+
offered: Callable[[str], bool] | None = None, on_key_refused: Callable[[], Any] = lambda: None,
|
|
530
|
+
venice_key: Callable[[], str] = lambda: os.environ.get("VENICE_API_KEY", ""), image_reader: Callable[[], str] = lambda: "",
|
|
531
|
+
venice_client: Any = None, on_call: Callable[[dict], Any] = lambda c: None) -> None:
|
|
504
532
|
self.port, self.host, self.upstream = port, host, upstream
|
|
505
533
|
self.client = client or httpx.AsyncClient(trust_env=False, timeout=httpx.Timeout(None, connect=15.0))
|
|
506
534
|
self.models = models if models is not None else mdl.confidential_models()
|
|
@@ -519,6 +547,11 @@ class ConfidentialProxy:
|
|
|
519
547
|
# TrustedRouter refused an account's key (401): it was taken back — a removal in the app, a re-pair. serve asks the
|
|
520
548
|
# account at once instead of at its next check, hours later (the owner, 2026-10-08: "Invalid API key").
|
|
521
549
|
self._on_key_refused = on_key_refused
|
|
550
|
+
# VENICE (venice.py): the key when there is no credential_for (else the credential's `venice`); the selected image reader
|
|
551
|
+
# for text-only models that are NOT confidential ('' = off); each Venice call's record (its stated price).
|
|
552
|
+
self._venice_key, self._image_reader, self._on_call = venice_key, image_reader, on_call
|
|
553
|
+
self._venice_client = venice_client
|
|
554
|
+
self._readers: dict = {}
|
|
522
555
|
|
|
523
556
|
def _key_refused(self, status: int) -> None:
|
|
524
557
|
if status == 401 and self._credential_for is not None:
|
|
@@ -609,11 +642,21 @@ class ConfidentialProxy:
|
|
|
609
642
|
except ValueError:
|
|
610
643
|
body = None
|
|
611
644
|
tinfoil = None
|
|
645
|
+
vkey = self._venice_key() if self._credential_for is None else ""
|
|
612
646
|
if self._credential_for is not None:
|
|
613
647
|
cred = self._credential_for(req)
|
|
614
648
|
if not cred or not cred.get("trustedrouter"):
|
|
615
649
|
await self._fail(res, Refusal(403, (cred or {}).get("refuse") or OUTSIDE_APP, "outside_app"), False)
|
|
616
650
|
return
|
|
651
|
+
vkey = cred.get("venice") or ""
|
|
652
|
+
# ── a zero-retention model (Venice): its own upstream, its own key; never the confidential path ──
|
|
653
|
+
if req.target.startswith(vn.VENICE_PREFIX + "/"):
|
|
654
|
+
await self._venice(req, res, vkey)
|
|
655
|
+
return
|
|
656
|
+
# TrustedRouter not answering: the turn fails and names the way out — the person picks ("I mean the user selects the model")
|
|
657
|
+
self._way_out = f" You can switch to a {vn.ZDR} model (Venice) in the model menu." if vkey else ""
|
|
658
|
+
self._vkey = vkey
|
|
659
|
+
if self._credential_for is not None:
|
|
617
660
|
model = body.get("model") if isinstance(body, dict) else None
|
|
618
661
|
if isinstance(model, str) and model not in self.models and self._offered and not self._offered(model):
|
|
619
662
|
await self._fail(res, Refusal(403, f"{model} is not offered on Witbitz — pick one of the models in the Code section", "model_not_offered"), False)
|
|
@@ -628,6 +671,10 @@ class ConfidentialProxy:
|
|
|
628
671
|
self.log(f"code-confidential: the request was {rep['before'] // 1024} KB; {rep['dropped']} older screenshot(s) left out to send it")
|
|
629
672
|
conf = self.models.get(body.get("model")) if isinstance(body, dict) and isinstance(body.get("model"), str) else None
|
|
630
673
|
if not conf:
|
|
674
|
+
if isinstance(body, dict) and self._vkey:
|
|
675
|
+
body = await self._read_images_for_blind(req, res, body)
|
|
676
|
+
if body is None:
|
|
677
|
+
return
|
|
631
678
|
await self._pass_through(req, res, body, target)
|
|
632
679
|
return
|
|
633
680
|
await self._confidential(req, res, body, conf, target, tinfoil)
|
|
@@ -635,10 +682,19 @@ class ConfidentialProxy:
|
|
|
635
682
|
async def _pass_through(self, req: _Request, res: _Response, body: Any, target: str) -> None:
|
|
636
683
|
marked = with_cache_marks(body) if self.cache_marks else None
|
|
637
684
|
out = dumps(marked).encode() if marked else req.body
|
|
685
|
+
way_out = getattr(self, "_way_out", "")
|
|
638
686
|
try:
|
|
639
687
|
async with self.client.stream(req.method, target, headers=_forward_headers(req.headers), content=None if req.method in ("GET", "HEAD") else out) as up:
|
|
640
688
|
headers = {k: v for k, v in up.headers.items() if k.lower() not in ("content-encoding", "content-length", "transfer-encoding", "connection")}
|
|
641
689
|
self._key_refused(up.status_code)
|
|
690
|
+
if up.status_code >= 500 and way_out and isinstance(body, dict): # an outage, said with the way out — the person picks
|
|
691
|
+
text = (await up.aread()).decode("utf-8", "replace")
|
|
692
|
+
try:
|
|
693
|
+
why = str(json.loads(text)["error"]["message"])[:120]
|
|
694
|
+
except (ValueError, KeyError, TypeError):
|
|
695
|
+
why = ""
|
|
696
|
+
await self._fail(res, Refusal(up.status_code, f"TrustedRouter isn't answering right now ({up.status_code}{': ' + why if why else ''}).{way_out}", "upstream_unavailable"), False)
|
|
697
|
+
return
|
|
642
698
|
if up.status_code == 429: # the month's allowance, said plainly — never a "rate limit" OpenCode would retry
|
|
643
699
|
text = (await up.aread()).decode("utf-8", "replace")
|
|
644
700
|
used = allowance_used(up.status_code, text)
|
|
@@ -654,10 +710,102 @@ class ConfidentialProxy:
|
|
|
654
710
|
except ConnectionError:
|
|
655
711
|
return # OpenCode went away; the upstream call is dropped with the context
|
|
656
712
|
except httpx.HTTPError as e:
|
|
657
|
-
await self._fail(res, Refusal(502, f"could not reach TrustedRouter ({str(e)[:120]})"), False)
|
|
713
|
+
await self._fail(res, Refusal(502, f"could not reach TrustedRouter ({str(e)[:120]}).{way_out}", "upstream_unavailable"), False)
|
|
658
714
|
return
|
|
659
715
|
await res.end()
|
|
660
716
|
|
|
717
|
+
async def _read_images_for_blind(self, req: _Request, res: _Response, body: dict) -> dict | None:
|
|
718
|
+
"""A text-only model that is NOT confidential, and a Venice reader selected: each image becomes the reader's words. Decided by
|
|
719
|
+
the model's tier — a confidential model never comes here, so no picture of a confidential turn reaches Venice."""
|
|
720
|
+
rm = str(self._image_reader() or "")
|
|
721
|
+
blind = next((m for m in vn._DATA.get("blindRegular", []) if m["model"] == body.get("model")), None)
|
|
722
|
+
if not rm or not blind or not any(p["kind"] == "image" for p in unreadable_parts(body)):
|
|
723
|
+
return body
|
|
724
|
+
key = (self._vkey, rm)
|
|
725
|
+
if key not in self._readers:
|
|
726
|
+
self._readers[key] = vn.make_reader(self._venice_client or self.client, self._vkey, rm, on_cost=lambda usd: self._called({"model": "venice/" + rm, "venice": True, "reader": True, "confidential": False, "status": 200, "costUsd": usd}))
|
|
727
|
+
to_text = self._readers[key]
|
|
728
|
+
try:
|
|
729
|
+
out = await describe_images(body, blind["label"], to_text)
|
|
730
|
+
except Refusal as e:
|
|
731
|
+
await self._fail(res, e, False)
|
|
732
|
+
return None
|
|
733
|
+
req.body = dumps(out).encode("utf-8")
|
|
734
|
+
return out
|
|
735
|
+
|
|
736
|
+
def _called(self, fields: dict) -> None:
|
|
737
|
+
try:
|
|
738
|
+
self._on_call(fields)
|
|
739
|
+
except Exception: # noqa: BLE001 — the record must never fail a call
|
|
740
|
+
pass
|
|
741
|
+
|
|
742
|
+
async def _venice(self, req: _Request, res: _Response, key: str) -> None:
|
|
743
|
+
"""ONE call to Venice (= handleVenice)."""
|
|
744
|
+
path = req.target[len(vn.VENICE_PREFIX):]
|
|
745
|
+
if req.method == "GET" and re.match(r"^/v1/models(\?|$)", path):
|
|
746
|
+
await res.head(200, {"content-type": "application/json"})
|
|
747
|
+
await res.end(dumps({"object": "list", "data": [{"id": m["id"], "object": "model", "owned_by": "venice.ai"} for m in vn.VENICE_MODELS]}))
|
|
748
|
+
return
|
|
749
|
+
if req.method != "POST" or not re.match(r"^/v1/chat/completions(\?|$)", path):
|
|
750
|
+
await self._fail(res, Refusal(404, "only chat completions are offered on the Venice route", "not_offered"), False)
|
|
751
|
+
return
|
|
752
|
+
try:
|
|
753
|
+
body = json.loads(req.body.decode("utf-8"))
|
|
754
|
+
except ValueError:
|
|
755
|
+
await self._fail(res, Refusal(400, "the request is not JSON", "bad_request"), False)
|
|
756
|
+
return
|
|
757
|
+
m = vn.entry(body.get("model") if isinstance(body, dict) else None)
|
|
758
|
+
if not m:
|
|
759
|
+
await self._fail(res, Refusal(403, f"{str((body or {}).get('model'))[:80]} is not offered on Witbitz — pick one of the {vn.ZDR} models in the Code section", "model_not_offered"), False)
|
|
760
|
+
return
|
|
761
|
+
if not key:
|
|
762
|
+
await self._fail(res, Refusal(403, f"This computer has no key for the {vn.ZDR} models (Venice) yet. It gets one from your Spaces account at its next check — try again in a minute, or pair again: witbitz-code pair.", "no_credential"), False)
|
|
763
|
+
return
|
|
764
|
+
lbl = vn.label(m)
|
|
765
|
+
rec = {"model": "venice/" + m["id"], "venice": True, "confidential": False}
|
|
766
|
+
stream = body.get("stream") is True
|
|
767
|
+
client = self._venice_client or self.client
|
|
768
|
+
try:
|
|
769
|
+
async with client.stream("POST", vn.VENICE_BASE + "/chat/completions", headers={"authorization": "Bearer " + key, "content-type": "application/json", "accept": "text/event-stream" if stream else "application/json"}, content=dumps(vn.request(body, m)).encode("utf-8")) as up:
|
|
770
|
+
if up.status_code != 200:
|
|
771
|
+
text = (await up.aread()).decode("utf-8", "replace")
|
|
772
|
+
if up.status_code == 401:
|
|
773
|
+
self._key_refused(401)
|
|
774
|
+
said = vn.refusal_of(up.status_code, text, lbl)
|
|
775
|
+
self._called({**rec, "status": said[0] if said else up.status_code, **({"refused": said[2]} if said else {})})
|
|
776
|
+
if said:
|
|
777
|
+
await self._fail(res, Refusal(said[0], said[1], said[2]), False)
|
|
778
|
+
return
|
|
779
|
+
await res.head(up.status_code, {"content-type": up.headers.get("content-type", "application/json")})
|
|
780
|
+
await res.end(text)
|
|
781
|
+
return
|
|
782
|
+
if stream:
|
|
783
|
+
await res.head(200, {"content-type": "text/event-stream", "cache-control": "no-cache"})
|
|
784
|
+
clean = vn.SseCleaner()
|
|
785
|
+
async for c in up.aiter_bytes():
|
|
786
|
+
out = clean.feed(c)
|
|
787
|
+
if out:
|
|
788
|
+
await res.write(out)
|
|
789
|
+
rest = clean.done()
|
|
790
|
+
await res.end(rest)
|
|
791
|
+
self._called({**rec, "status": 200, "tokens": vn.usage_tokens(clean.usage), "costUsd": clean.cost_usd})
|
|
792
|
+
return
|
|
793
|
+
text = (await up.aread()).decode("utf-8", "replace")
|
|
794
|
+
except ConnectionError:
|
|
795
|
+
return
|
|
796
|
+
except httpx.HTTPError as e:
|
|
797
|
+
self._called({**rec, "status": 502})
|
|
798
|
+
await self._fail(res, Refusal(502, f"could not reach Venice ({str(e)[:120]})"), False)
|
|
799
|
+
return
|
|
800
|
+
try:
|
|
801
|
+
j = json.loads(text)
|
|
802
|
+
except ValueError:
|
|
803
|
+
await self._fail(res, Refusal(502, "Venice answered something that is not JSON"), False)
|
|
804
|
+
return
|
|
805
|
+
await res.head(200, {"content-type": "application/json"})
|
|
806
|
+
await res.end(dumps(vn.clean_event(j)))
|
|
807
|
+
self._called({**rec, "status": 200, "tokens": vn.usage_tokens(j.get("usage")), "costUsd": vn.cost_of(j)})
|
|
808
|
+
|
|
661
809
|
async def _confidential(self, req: _Request, res: _Response, body: dict, conf: dict, target: str, tinfoil: str | None = None) -> None:
|
|
662
810
|
label = f"{conf['label']} (confidential)"
|
|
663
811
|
wants_stream = body.get("stream") is True
|
|
@@ -1120,7 +1120,7 @@ class _DefaultDevices:
|
|
|
1120
1120
|
|
|
1121
1121
|
def _watch_devices(c: Connector, devices: Any, log: Callable[[str], Any], on_all_signed_out: Callable[[], Any] | None) -> None:
|
|
1122
1122
|
"""SIGNED OUT OF THE ACCOUNT (account recovery v2, § 8.5; device.py): a pairing whose computer the account's service
|
|
1123
|
-
registered is asked about now,
|
|
1123
|
+
registered is asked about now, every 5 minutes, and when a page connects. Signed out → that pairing stops and the account's keys
|
|
1124
1124
|
here are wiped; nothing else changes on any other answer (offline, an error, a key the service does not know)."""
|
|
1125
1125
|
dev = _DefaultDevices if devices is _DEFAULT_DEVICES else devices
|
|
1126
1126
|
if dev is None:
|
|
@@ -31,8 +31,10 @@ from . import pairings as pp
|
|
|
31
31
|
from ._js import b64u, unb64u_loose
|
|
32
32
|
|
|
33
33
|
SIGNED_OUT_TEXT = "This computer was signed out of your account. Pair it again from the app."
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
# every 5 minutes while serving (each check is signed: it says the computer is in use) — the owner, 2026-11-17: a computer
|
|
35
|
+
# signed out from Your devices kept running "Online" until its next hourly check ("do the Faster check on the computer")
|
|
36
|
+
CHECK_EVERY_S = 300
|
|
37
|
+
CHECK_FLOOR_S = 60 # a page connecting — Code in Spaces, or this computer's own page (ui.py) — asks again, at most this often
|
|
36
38
|
_LABEL_MAX = 64
|
|
37
39
|
# The account service a computer may ask: one of the two the apps use (spaces/public/acctV2Switch.js) — never an address a
|
|
38
40
|
# link names.
|
|
@@ -78,7 +78,7 @@ def default_model_config() -> dict:
|
|
|
78
78
|
return {"model": f"trustedrouter/{DEFAULT_MODEL}"}
|
|
79
79
|
|
|
80
80
|
|
|
81
|
-
def proxy_config(proxy_port: int, cat: list[dict] | None = None) -> dict:
|
|
81
|
+
def proxy_config(proxy_port: int, cat: list[dict] | None = None, image_reader: str = "") -> dict:
|
|
82
82
|
"""OpenCode config that sends TrustedRouter through the proxy and declares the confidential models — a text-only one
|
|
83
83
|
still receives images (the proxy reads them through Tinfoil). Merged by OpenCode over the user's own config."""
|
|
84
84
|
models = {}
|
|
@@ -88,4 +88,12 @@ def proxy_config(proxy_port: int, cat: list[dict] | None = None) -> dict:
|
|
|
88
88
|
"modalities": {"input": ["text", "image"], "output": ["text"]},
|
|
89
89
|
"limit": {"context": 200_000, "output": m.get("maxTokens") or 16_000},
|
|
90
90
|
**({"reasoning": True, "variants": v} if v else {})}
|
|
91
|
-
|
|
91
|
+
# A selected image reader (venice.py): the text-only models that are NOT confidential take images — the proxy has it describe them
|
|
92
|
+
if image_reader:
|
|
93
|
+
from . import venice as vn
|
|
94
|
+
for m in vn._DATA.get("blindRegular", []):
|
|
95
|
+
v = variants_for(m)
|
|
96
|
+
models.setdefault(m["model"], {"name": m["label"], "attachment": True, "tool_call": True, "modalities": {"input": ["text", "image"], "output": ["text"]},
|
|
97
|
+
"limit": {"context": 200_000, "output": m.get("maxTokens") or 16_000}, **({"reasoning": True, "variants": v} if v else {})})
|
|
98
|
+
from . import venice as vn # + the zero-retention models (Venice), through the same proxy
|
|
99
|
+
return {"provider": {"trustedrouter": {"options": {"baseURL": f"http://127.0.0.1:{proxy_port}/v1"}, "models": models}, **vn.provider_config(proxy_port)}}
|
|
@@ -237,12 +237,31 @@ def default_store_owner(pairings: list[dict]) -> str:
|
|
|
237
237
|
return key
|
|
238
238
|
|
|
239
239
|
|
|
240
|
+
def store_keys(p: Any) -> list[str]:
|
|
241
|
+
"""This account's store keys, its own first. A REGULAR-app account is the same account whether its pairing names the app's
|
|
242
|
+
origin or not: pairings before 2026-10-22 name none (= the regular app, app.of_origin), and a pairing since names
|
|
243
|
+
https://witbitz-spaces.pages.dev — so the owner's computer, paired again on 2026-11-16, opened a NEW empty store and its 27
|
|
244
|
+
sessions seemed gone ("what happened to the old sessions?"). Both spellings find the same store."""
|
|
245
|
+
p = p if isinstance(p, dict) else {}
|
|
246
|
+
keys = [store_key(p)]
|
|
247
|
+
if app_mod.of_origin(p.get("origin")) == app_mod.REGULAR:
|
|
248
|
+
for o in ("", app_mod.origin_of(app_mod.REGULAR)):
|
|
249
|
+
k = store_key({**p, "origin": o})
|
|
250
|
+
if k not in keys:
|
|
251
|
+
keys.append(k)
|
|
252
|
+
return keys
|
|
253
|
+
|
|
254
|
+
|
|
240
255
|
def store_dir(p: Any, pairings: list[dict]) -> Path | None:
|
|
241
|
-
"""None = OpenCode's default store (the first account's); else this account's own folder
|
|
242
|
-
|
|
256
|
+
"""None = OpenCode's default store (the first account's); else this account's own folder — one it already has under any of
|
|
257
|
+
its keys (store_keys), else a new one under its own."""
|
|
258
|
+
keys = store_keys(p)
|
|
259
|
+
base = pairings_path().parent / "accounts"
|
|
243
260
|
if app_mod.is_vaulted(): # OpenCode's default store is the regular install's: every vaulted account has its own
|
|
244
|
-
return
|
|
245
|
-
|
|
261
|
+
return base / keys[0]
|
|
262
|
+
if default_store_owner(pairings) in keys:
|
|
263
|
+
return None
|
|
264
|
+
return next((base / k for k in keys if (base / k).is_dir()), base / keys[0])
|
|
246
265
|
|
|
247
266
|
|
|
248
267
|
# ── files ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
@@ -12,6 +12,7 @@ Windows only for now (also from WSL, where it reads the Windows that hosts it).
|
|
|
12
12
|
|
|
13
13
|
from __future__ import annotations
|
|
14
14
|
|
|
15
|
+
from . import winrun # a Windows program from WSL, tried again when WSL's link times out
|
|
15
16
|
import asyncio
|
|
16
17
|
import json
|
|
17
18
|
import os
|
|
@@ -144,9 +145,10 @@ def powershell() -> str | None:
|
|
|
144
145
|
|
|
145
146
|
def _run_ps(ps: str, script: str, timeout: int = 60) -> subprocess.CompletedProcess:
|
|
146
147
|
flags = getattr(subprocess, "CREATE_NO_WINDOW", 0)
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
# tried again when WSL's link to Windows timed out (winrun.py) — the check runs in the background, so the wait costs the page nothing
|
|
149
|
+
return winrun.run_retrying(subprocess.run, [ps, "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", script], # noqa: S603
|
|
150
|
+
check=False, stdin=subprocess.DEVNULL, capture_output=True, text=True, errors="replace",
|
|
151
|
+
timeout=timeout, creationflags=flags, cwd="/mnt/c" if _in_wsl() and os.path.isdir("/mnt/c") else None)
|
|
150
152
|
|
|
151
153
|
|
|
152
154
|
def read_status(run: Callable[[str, str], subprocess.CompletedProcess] = _run_ps, ps: str | None = None) -> dict:
|
|
@@ -158,6 +160,8 @@ def read_status(run: Callable[[str, str], subprocess.CompletedProcess] = _run_ps
|
|
|
158
160
|
try:
|
|
159
161
|
return {"supported": True, **json.loads(out[-1] if out else "")}
|
|
160
162
|
except (ValueError, IndexError):
|
|
163
|
+
if winrun.link_failed(r.stderr): # WSL's link to Windows, not the check: said in words, and the next minute's check tries again
|
|
164
|
+
return {"supported": True, "error": winrun.LINK_WORDS}
|
|
161
165
|
return {"supported": True, "error": "Windows did not answer the check" + (f" ({(r.stderr or '').strip()[:120]})" if r.stderr else "")}
|
|
162
166
|
|
|
163
167
|
|
|
@@ -219,11 +219,29 @@ class Manager:
|
|
|
219
219
|
out = {"available": False, "why": "not on this kind of computer yet — Windows and WSL only"}
|
|
220
220
|
else:
|
|
221
221
|
st = self._login_state(spec)
|
|
222
|
-
out = {"available": st in ("on", "off"), "on": st == "on", **({} if st in ("on", "off") else {"why": "Windows did not answer"})}
|
|
222
|
+
out = {"available": st in ("on", "off"), "on": st == "on", **({} if st in ("on", "off") else {"why": "Windows did not answer just now — it asks again in a moment"})}
|
|
223
223
|
self._login_cache = (time.monotonic(), out)
|
|
224
224
|
return out
|
|
225
225
|
|
|
226
|
+
def poke_device_checks(self) -> int:
|
|
227
|
+
"""This page is open (its status poll): ask the account's service whether each served pairing is still signed in —
|
|
228
|
+
each watch asks at most once a minute (device.CHECK_FLOOR_S). A computer signed out from Your devices then stops
|
|
229
|
+
while someone is looking at it, not at the next timed check (the owner, 2026-11-17). → how many checks started."""
|
|
230
|
+
n = 0
|
|
231
|
+
for r in self.runs.values():
|
|
232
|
+
if r["task"].done():
|
|
233
|
+
continue
|
|
234
|
+
conn = r["live"].get("connector")
|
|
235
|
+
for w in list(getattr(conn, "watchers", None) or []):
|
|
236
|
+
try:
|
|
237
|
+
if w.poke() is not None:
|
|
238
|
+
n += 1
|
|
239
|
+
except Exception: # noqa: BLE001 — a check that cannot start now is asked at its next time
|
|
240
|
+
pass
|
|
241
|
+
return n
|
|
242
|
+
|
|
226
243
|
async def status(self, fresh: bool = False) -> dict:
|
|
244
|
+
self.poke_device_checks()
|
|
227
245
|
ps = self.pairings()
|
|
228
246
|
paired = []
|
|
229
247
|
for p in ps:
|