// Magpie settings pages cannot fetch (connect-src 'none'). Their Connect or
// Test click navigates to this loopback page, which probes saved options only.
import { randomBytes, timingSafeEqual } from "node:crypto"
import { readIdentities, testConnection, textsFor } from "./probe.mjs"
const DEFAULT_PORT = 3481
const TOKEN_HEADER = "x-aelios-token"
let running
let pluginOptions = {}
let token
function page(lang, auto = false) {
const t = textsFor(lang)
const zh = lang === "zh"
const labels = zh ? { title: "助手匹配列表", name: "助手", models: "主模型匹配规则", empty: "未配置主模型", unavailable: "当前服务未提供匹配列表;请升级 Aelios 后重试。", rules: "自动分配复用 Aelios 的主模型规则,按列表顺序选择首个匹配的助手。支持 *、忽略大小写,同时匹配完整模型名及最后 / 后的名称。插件先按授权匹配列表在本地筛选;未匹配时不发送对话。列表不可用时暂停回忆和记录,并显示 unavailable。", override: "当前设置包含自定义身份或路由;它们优先于自动分配。", auto: "连接成功后显示此密钥可访问的助手。" } : { title: "Assistant mappings", name: "Assistant", models: "Main model patterns", empty: "No main models configured", unavailable: "This service does not provide mappings. Upgrade Aelios and retry.", rules: "Automatic assignment uses Aelios main model rules, choosing the first matching assistant in order. Patterns support *, ignore case, and match the full model name or the name after its last /. The plugin filters locally using the authorized matching list; unmatched turns are not sent. If the list is unavailable, recall and recording pause with status unavailable.", override: "Custom identity or route settings are active and take priority over automatic assignment.", auto: "After connecting, this page lists the assistants available to this key." }
return `