fix: use SDK.fetchJSON for auth, Optional[str] for Python 3.9 compat

This commit is contained in:
OpenCode Agent 2026-08-17 22:03:34 +00:00
parent 7435a418c8
commit 7a6871e1e9
2 changed files with 7 additions and 29 deletions

View File

@ -6,34 +6,11 @@
const { useState, useEffect, useCallback } = SDK.hooks;
const { Card, CardHeader, CardTitle, CardContent, Button } = SDK.components;
// Use native fetch with session token header for remote dashboard
function getSessionToken() {
return window.__HERMES_SESSION_TOKEN__ || "";
}
async function apiFetch(path) {
const res = await fetch(path, {
credentials: "include",
headers: { "x-hermes-session-token": getSessionToken() }
});
if (!res.ok) {
const text = await res.text();
throw new Error("API error " + res.status + ": " + text.slice(0, 100));
}
return res.json();
}
const fetchJSON = SDK.fetchJSON;
async function apiPost(path) {
const res = await fetch(path, {
method: "POST",
credentials: "include",
headers: { "x-hermes-session-token": getSessionToken() }
});
if (!res.ok) {
const text = await res.text();
throw new Error("API error " + res.status + ": " + text.slice(0, 100));
}
return res.json();
const res = await fetchJSON(path, { method: "POST" });
return res;
}
function SSHXPage() {
@ -45,7 +22,7 @@
setStatus("loading");
setError(null);
try {
const res = await apiFetch("/api/plugins/sshx-link/start");
const res = await fetchJSON("/api/plugins/sshx-link/start");
if (res.link) {
setLink(res.link);
setStatus("running");
@ -71,7 +48,7 @@
const checkStatus = useCallback(async function () {
try {
const res = await apiFetch("/api/plugins/sshx-link/status");
const res = await fetchJSON("/api/plugins/sshx-link/status");
if (res.status === "running" && res.link) {
setLink(res.link);
setStatus("running");

View File

@ -9,6 +9,7 @@ import subprocess
import re
import shutil
import logging
from typing import Optional
from fastapi import APIRouter
from fastapi.responses import JSONResponse
@ -20,7 +21,7 @@ _sshx_process = None
_sshx_link = None
def _find_link(text: str) -> str | None:
def _find_link(text: str) -> Optional[str]:
"""Extract sshx link from output."""
match = re.search(r"https://sshx\.io/s/[A-Za-z0-9_-]+", text)
return match.group(0) if match else None