多语言首页与首页引用页

This commit is contained in:
potaser
2026-08-09 06:03:39 +08:00
parent cb122fd088
commit 8f7e992b84
17 changed files with 29290 additions and 382 deletions
@@ -361,6 +361,7 @@ def execute_queued_operation(payload: dict[str, Any]) -> dict[str, Any]:
settings = LightweightApiSettings.from_environment()
action = str(payload["action"])
runtime_env = str(payload.get("runtime_env", "test4py311"))
extension_id = _safe_component(str(payload["extension_id"]), name="extension_id")
token = _safe_component(str(payload["operation_token"]), name="operation_token")
_set_receipt(settings, token, state="running", status="running")
@@ -373,6 +374,7 @@ def execute_queued_operation(payload: dict[str, Any]) -> dict[str, Any]:
raw_code=stage / "raw_code",
raw_data=stage / "raw_test_data",
original_command=str(payload["original_command"]),
runtime_env=runtime_env,
operation_token=token,
)
elif action == "rebuild":
@@ -479,6 +481,7 @@ def create_lightweight_extension_router(
raw_code_files: list[UploadFile] | None = File(None),
raw_data_files: list[UploadFile] | None = File(None),
raw_data_paths: str | None = Form(None),
runtime_env: str = Form("test4py311"),
) -> dict[str, Any]:
temporary_stage: Path | None = None
try:
@@ -555,6 +558,7 @@ def create_lightweight_extension_router(
"action": "upload",
"operation_token": token,
"original_command": normalized_command,
"runtime_env": runtime_env,
}
)
except BaseException as exc:
@@ -109,6 +109,18 @@ class LightweightExtensionService:
def get(self, extension_id: str) -> dict[str, Any]:
return self._read_record(extension_id)
def _make_env(self, runtime_env: str) -> dict[str, str]:
"""Build a process env that activates the selected conda environment."""
conda_prefix = f"/home/xzq/miniconda3/envs/{runtime_env}"
conda_bin = f"{conda_prefix}/bin"
env = dict(self.environment or {})
existing_path = env.get("PATH", os.environ.get("PATH", ""))
env["PATH"] = f"{conda_bin}:{existing_path}" if existing_path else conda_bin
env["CONDA_PREFIX"] = conda_prefix
env["CONDA_DEFAULT_ENV"] = runtime_env
return env
def _deepseek_candidate(self, facts: dict[str, Any], raw_code: Path) -> tuple[dict[str, Any], dict[str, Any]]:
return generate_semantic_candidate(
execution_facts=facts, raw_code=raw_code, environ=self.environment
@@ -324,12 +336,13 @@ class LightweightExtensionService:
build: dict[str, Any] | None = None
failure: tuple[str, BaseException | str] | None = None
try:
runtime_env = str(record.get("runtime_env") or "test4py311")
evidence = run_raw_baseline(
command=record["original_command"],
raw_code=root / "raw_code",
raw_data=root / "raw_test_data",
run_dir=root / "baseline" / run_id,
env=self.environment,
env=self._make_env(runtime_env),
on_process_start=lambda identity: self._mark_process(
extension_id, token=token, phase="baseline", identity=identity
),
@@ -365,6 +378,7 @@ class LightweightExtensionService:
raw_code: Path,
raw_data: Path,
original_command: str,
runtime_env: str = "test4py311",
operation_token: str,
) -> dict[str, Any]:
raw_code, raw_data = Path(raw_code), Path(raw_data)
@@ -394,6 +408,7 @@ class LightweightExtensionService:
"schema_version": "lightweight-extension-service/v1",
"extension_id": extension_id,
"original_command": original_command,
"runtime_env": runtime_env,
"status": "baseline_running",
"operations": {
operation_token: {
@@ -605,9 +620,10 @@ class LightweightExtensionService:
rendered = render_runtime_package(
record["runtime_binding_contract"], root / "raw_code", resolved, run_dir
)
runtime_env = str(record.get("runtime_env") or "test4py311")
result = replay_runtime_binding(
rendered,
env=self.environment,
env=self._make_env(runtime_env),
on_process_start=lambda identity: self._mark_process(
record["extension_id"], token=operation_token, phase=phase, identity=identity
),