add wasmtime

bundle

mypy fix

mypy

mypy

pyright

pyright

pyright

make

lock file
This commit is contained in:
arcbtc
2026-05-25 14:56:15 +03:00
committed by Vlad Stan
parent 46bf984c05
commit 46a3a24ce4
6 changed files with 146 additions and 33 deletions
+31 -9
View File
@@ -1,6 +1,7 @@
import asyncio
import glob
import importlib
import json
import os
import shutil
import sys
@@ -53,10 +54,6 @@ from lnbits.utils.logger import (
log_server_info,
)
from lnbits.wallets import get_funding_source, set_funding_source
try:
from lnbits.extensions.wasm.wasm_host.extension_host import register_wasm_ext_routes
except Exception: # pragma: no cover - optional parent extension
register_wasm_ext_routes = None
from .commands import migrate_databases
from .core import init_core_routers
@@ -442,12 +439,23 @@ def register_ext_routes(app: FastAPI, ext: Extension) -> None:
ext.extension_type = _load_extension_type(ext.code) or ext.extension_type
if ext.extension_type == "wasm":
settings.activate_extension_paths(ext.code, ext.upgrade_hash, [])
if register_wasm_ext_routes is None:
try:
module = importlib.import_module(
"lnbits.extensions.wasm.wasm_host.extension_host"
)
register_wasm_ext_routes = getattr(module, "register_wasm_ext_routes", None)
except Exception: # pragma: no cover - optional parent extension
logger.error(
"WASM host extension not installed; cannot register wasm extension "
f"{ext.code}."
)
return
if register_wasm_ext_routes is None:
logger.error(
"WASM host extension missing register_wasm_ext_routes; cannot "
f"register wasm extension {ext.code}."
)
return
register_wasm_ext_routes(app, ext)
return
ext_module = importlib.import_module(ext.module_name)
@@ -488,20 +496,34 @@ def _load_extension_type(ext_id: str) -> str | None:
try:
conf_path = base / "config.json"
if conf_path.is_file():
with open(conf_path, "r") as json_file:
with open(conf_path) as json_file:
config_json = json.load(json_file)
ext_type = config_json.get("extension_type")
if ext_type:
return ext_type
except Exception:
except Exception as exc:
logger.debug(
"Failed to read extension config.json for '{}' in '{}': {}",
ext_id,
base,
exc,
)
continue
for base in base_dirs:
try:
wasm_dir = base / "wasm"
if (wasm_dir / "module.wasm").is_file() or (wasm_dir / "module.wat").is_file():
if (wasm_dir / "module.wasm").is_file() or (
wasm_dir / "module.wat"
).is_file():
return "wasm"
except Exception:
except Exception as exc:
logger.debug(
"Failed to probe wasm files for '{}' in '{}': {}",
ext_id,
base,
exc,
)
continue
return None
+4 -2
View File
@@ -57,13 +57,15 @@ def _is_wasm_extension(ext: InstallableExtension) -> bool:
conf_path = Path(base, "config.json")
if not conf_path.is_file():
continue
with open(conf_path, "r") as json_file:
with open(conf_path) as json_file:
config_json = json.load(json_file)
if config_json.get("extension_type") == "wasm":
return True
for base in candidate_dirs:
wasm_dir = Path(base, "wasm")
if (wasm_dir / "module.wasm").is_file() or (wasm_dir / "module.wat").is_file():
if (wasm_dir / "module.wasm").is_file() or (
wasm_dir / "module.wat"
).is_file():
return True
except Exception as exc:
logger.debug(f"Failed to load extension config for '{ext.id}': {exc!s}")
+31 -16
View File
@@ -50,6 +50,19 @@ from lnbits.decorators import (
)
from lnbits.settings import settings
from ..crud import (
create_user_extension,
delete_dbversion,
drop_extension_db,
get_db_version,
get_db_versions,
get_installed_extension,
get_installed_extensions,
get_user_extension,
update_installed_extension,
update_user_extension,
)
def _load_extension_type(ext_id: str) -> str:
base_dirs = [
@@ -65,35 +78,37 @@ def _load_extension_type(ext_id: str) -> str:
conf_path = base / "config.json"
if not conf_path.is_file():
continue
with open(conf_path, "r") as json_file:
with open(conf_path) as json_file:
config_json = json.load(json_file)
ext_type = config_json.get("extension_type")
if ext_type:
return ext_type
except Exception:
except Exception as exc:
logger.debug(
"Failed to read extension config.json for '{}' in '{}': {}",
ext_id,
base,
exc,
)
continue
for base in base_dirs:
try:
wasm_dir = base / "wasm"
if (wasm_dir / "module.wasm").is_file() or (wasm_dir / "module.wat").is_file():
if (wasm_dir / "module.wasm").is_file() or (
wasm_dir / "module.wat"
).is_file():
return "wasm"
except Exception:
except Exception as exc:
logger.debug(
"Failed to probe wasm files for '{}' in '{}': {}",
ext_id,
base,
exc,
)
continue
return "python"
from ..crud import (
create_user_extension,
delete_dbversion,
drop_extension_db,
get_db_version,
get_db_versions,
get_installed_extension,
get_installed_extensions,
get_user_extension,
update_installed_extension,
update_user_extension,
)
extension_router = APIRouter(
tags=["Extension Managment"],
+2 -1
View File
@@ -268,7 +268,8 @@ window.PageExtensions = {
if (!wasmHost || !wasmHost.isInstalled || !wasmHost.isActive) {
Quasar.Notify.create({
type: 'warning',
message: 'Enable the WASM! host extension before using this extension.'
message:
'Enable the WASM! host extension before using this extension.'
})
return
}