Add Playerbot Characters model setup

This commit is contained in:
Nightwalker743 committed 2026-11-20 16:14:27 -06:00
1 parent 10cfdcf5a2
commit 206d4844c9
16 files changed
+564 -4

No files matched your search

+12
View File
@@ -845,6 +845,18 @@ const de: Partial<Record<keyof typeof en, string>> = {
"mod.switch": "{name} ein- oder ausschalten",
"mod.notHere": "Nicht Teil dieses Servers",
"mod.github": "GitHub",
"mod.pbc.connection": "Modellverbindung",
"mod.pbc.provider": "Modellanbieter",
"mod.pbc.compatible": "OpenAI-kompatibler Endpunkt",
"mod.pbc.model": "Modellname",
"mod.pbc.endpoint": "API-Basis-URL",
"mod.pbc.key": "API-Schlüssel",
"mod.pbc.savedKey": "Schlüssel gespeichert",
"mod.pbc.removeKey": "Gespeicherten Schlüssel löschen",
"mod.pbc.keyHint": "Lass das Feld leer, um den Schlüssel für denselben Endpunkt zu behalten. Lokales Ollama braucht meist keinen Schlüssel.",
"mod.pbc.save": "Modellverbindung speichern",
"mod.pbc.saved": "Modellverbindung gespeichert.",
"mod.pbc.useConnection": "Beim Speichern wird diese Verbindung als Standard für mod-pbc auf dem Server festgelegt.",
"mod.settings": "Einstellungen",
"mod.default": "Zurück zum Standard ({v})",
"mod.saved": "Gespeichert ({n} geändert).",
+12
View File
@@ -891,6 +891,18 @@ const en = {
"mod.switch": "Turn {name} on or off",
"mod.notHere": "Not part of this server",
"mod.github": "GitHub",
"mod.pbc.connection": "Model connection",
"mod.pbc.provider": "Model provider",
"mod.pbc.compatible": "OpenAI-compatible endpoint",
"mod.pbc.model": "Model name",
"mod.pbc.endpoint": "API base URL",
"mod.pbc.key": "API key",
"mod.pbc.savedKey": "Saved key",
"mod.pbc.removeKey": "Remove saved key",
"mod.pbc.keyHint": "Leave the key blank to keep it for the same endpoint. Local Ollama usually needs no key.",
"mod.pbc.save": "Save model connection",
"mod.pbc.saved": "Model connection saved.",
"mod.pbc.useConnection": "Saving makes this the server’s default mod-pbc connection.",
"mod.settings": "Settings",
"mod.default": "Back to the default ({v})",
"mod.saved": "Saved ({n} changed).",
+12
View File
@@ -845,6 +845,18 @@ const es: Partial<Record<keyof typeof en, string>> = {
"mod.switch": "Activar o desactivar {name}",
"mod.notHere": "No forma parte de este servidor",
"mod.github": "GitHub",
"mod.pbc.connection": "Conexión con el modelo",
"mod.pbc.provider": "Proveedor del modelo",
"mod.pbc.compatible": "Endpoint compatible con OpenAI",
"mod.pbc.model": "Nombre del modelo",
"mod.pbc.endpoint": "URL base de la API",
"mod.pbc.key": "Clave de API",
"mod.pbc.savedKey": "Clave guardada",
"mod.pbc.removeKey": "Eliminar la clave guardada",
"mod.pbc.keyHint": "Deja el campo vacío para conservar la clave del mismo endpoint. Ollama en local normalmente no necesita clave.",
"mod.pbc.save": "Guardar la conexión",
"mod.pbc.saved": "Conexión con el modelo guardada.",
"mod.pbc.useConnection": "Al guardar, esta será la conexión predeterminada de mod-pbc en el servidor.",
"mod.settings": "Ajustes",
"mod.default": "Volver al valor por defecto ({v})",
"mod.saved": "Guardado ({n} cambiado(s)).",
+12
View File
@@ -845,6 +845,18 @@ const fr: Partial<Record<keyof typeof en, string>> = {
"mod.switch": "Activer ou désactiver {name}",
"mod.notHere": "Ne fait pas partie de ce serveur",
"mod.github": "GitHub",
"mod.pbc.connection": "Connexion au modèle",
"mod.pbc.provider": "Fournisseur du modèle",
"mod.pbc.compatible": "Point d’accès compatible OpenAI",
"mod.pbc.model": "Nom du modèle",
"mod.pbc.endpoint": "URL de base de l’API",
"mod.pbc.key": "Clé API",
"mod.pbc.savedKey": "Clé enregistrée",
"mod.pbc.removeKey": "Supprimer la clé enregistrée",
"mod.pbc.keyHint": "Laissez le champ vide pour conserver la clé du même point d’accès. Ollama en local ne demande généralement pas de clé.",
"mod.pbc.save": "Enregistrer la connexion",
"mod.pbc.saved": "Connexion au modèle enregistrée.",
"mod.pbc.useConnection": "Cette connexion deviendra la connexion par défaut de mod-pbc sur le serveur.",
"mod.settings": "Réglages",
"mod.default": "Revenir à la valeur par défaut ({v})",
"mod.saved": "Enregistré ({n} modifié(s)).",
+12
View File
@@ -874,6 +874,18 @@ const ru: Partial<Record<keyof typeof en, string>> = {
"mod.switch": "Включить или выключить {name}",
"mod.notHere": "Нет в этом сервере",
"mod.github": "GitHub",
"mod.pbc.connection": "Подключение к модели",
"mod.pbc.provider": "Провайдер модели",
"mod.pbc.compatible": "Эндпоинт, совместимый с OpenAI",
"mod.pbc.model": "Имя модели",
"mod.pbc.endpoint": "Базовый URL API",
"mod.pbc.key": "Ключ API",
"mod.pbc.savedKey": "Ключ сохранён",
"mod.pbc.removeKey": "Удалить сохранённый ключ",
"mod.pbc.keyHint": "Оставьте поле пустым, чтобы сохранить ключ для того же адреса. Локальной Ollama обычно ключ не нужен.",
"mod.pbc.save": "Сохранить подключение",
"mod.pbc.saved": "Подключение к модели сохранено.",
"mod.pbc.useConnection": "После сохранения это подключение станет основным для mod-pbc на сервере.",
"mod.settings": "Настройки",
"mod.default": "Вернуть по умолчанию ({v})",
"mod.saved": "Сохранено (изменено: {n}).",
+12
View File
@@ -845,6 +845,18 @@ const zh = {
"mod.switch": "开启或关闭 {name}",
"mod.notHere": "未包含在当前服务器中",
"mod.github": "GitHub 页面",
"mod.pbc.connection": "模型连接",
"mod.pbc.provider": "模型服务商",
"mod.pbc.compatible": "兼容 OpenAI 的端点",
"mod.pbc.model": "模型名称",
"mod.pbc.endpoint": "API 基础网址",
"mod.pbc.key": "API 密钥",
"mod.pbc.savedKey": "已保存密钥",
"mod.pbc.removeKey": "删除已保存的密钥",
"mod.pbc.keyHint": "留空会保留同一端点的密钥。本地 Ollama 通常不需要密钥。",
"mod.pbc.save": "保存模型连接",
"mod.pbc.saved": "模型连接已保存。",
"mod.pbc.useConnection": "保存后,此连接将成为该服务器上 mod-pbc 的默认连接。",
"mod.settings": "模块设置",
"mod.default": "恢复为默认值 ({v})",
"mod.saved": "已保存(修改了 {n} 项)。",
+17
View File
@@ -229,6 +229,21 @@ export interface RealmProfile {
data: string;
}
export type PbcApiType = "openai" | "ollama" | "anthropic";
export interface PbcConnection {
apiType: PbcApiType;
baseUrl: string;
model: string;
}
export interface PbcConnectionSetup {
active: boolean;
connection: (PbcConnection & { hasKey: boolean }) | null;
}
export interface PbcConnectionUpdate extends PbcConnection {
apiKey?: string;
removeKey: boolean;
}
export interface ModuleView {
id: string;
name: string;
@@ -545,6 +560,8 @@ export const api = {
realmlistDelete: (id: string, profileId: string) => invoke<void>("realmlist_delete", { id, profileId }),
realmlistActivate: (id: string, profileId: string) => invoke<string[]>("realmlist_activate", { id, profileId }),
modulesList: (id: string) => invoke<ModuleView[]>("modules_list", { id }),
pbcConnection: (id: string) => invoke<PbcConnectionSetup>("pbc_connection", { id }),
pbcSaveConnection: (id: string, update: PbcConnectionUpdate) => invoke<PbcConnectionSetup>("pbc_save_connection", { id, update }),
moduleSetEnabled: (id: string, module: string, enabled: boolean) => invoke<void>("module_set_enabled", { id, module, enabled }),
moduleSettings: (id: string, module: string) => invoke<ModuleSetting[]>("module_settings", { id, module }),
moduleSaveSettings: (id: string, module: string, changes: Record<string, string>) => invoke<string[]>("module_save_settings", { id, module, changes }),
+7 -3
View File
@@ -9,6 +9,7 @@ import { useHuman, useI18n, useSchemaText, type Key } from "@/i18n";
import { auctionWeightKey, canonicalModuleValue, moduleEnableKey, moduleField, retiredModuleKeys } from "@/lib/moduleSettings";
import { AuctionTypes } from "@/screens/AuctionTypes";
import { RaceAvailabilitySettings } from "@/screens/RaceAvailabilitySettings";
import { PbcConnectionSettings } from "@/screens/PbcConnectionSettings";
import type { UnsavedChangesGuard } from "@/lib/unsavedGuard";
/** The GitHub mark (lucide dropped its brand icons). */
@@ -111,16 +112,18 @@ export function ModulesPage({ serverId, onChanged, onRegisterGuard }: { serverId
}, [serverId]);
const [guard, setGuard] = useState<UnsavedChangesGuard | null>(null);
const [racesGuard, setRacesGuard] = useState<UnsavedChangesGuard | null>(null);
const [pbcGuard, setPbcGuard] = useState<UnsavedChangesGuard | null>(null);
const markChanged = useCallback(() => setChanged(true), []);
useEffect(() => {
const guards = [guard, racesGuard].filter((item): item is UnsavedChangesGuard => item !== null);
const guards = [guard, racesGuard, pbcGuard].filter((item): item is UnsavedChangesGuard => item !== null);
onRegisterGuard?.(guards.length ? {
isDirty: () => guards.some(item => item.isDirty()),
save: async () => { for (const item of guards) if (item.isDirty() && !await item.save()) return false; return true; },
discard: () => guards.forEach(item => item.discard()),
} : null);
return () => onRegisterGuard?.(null);
}, [guard, racesGuard, onRegisterGuard]);
}, [guard, racesGuard, pbcGuard, onRegisterGuard]);
const load = useCallback(async () => {
try {
@@ -343,6 +346,7 @@ export function ModulesPage({ serverId, onChanged, onRegisterGuard }: { serverId
{selected?.has_settings && !selected.page && selectedAt >= 0 && Math.floor(selectedAt / 2) === Math.floor(i / 2) && (i % 2 === 1 || i === modules.length - 1) && (
<SettingsPanel key={selected.id} className="sm:col-span-2">
<h2 className="font-semibold">{t("mod.settingsOf", { name: selected.name })}</h2>
{selected.id === "mod-pbc" && <PbcConnectionSettings serverId={serverId} onSaved={markChanged} onRegisterGuard={setPbcGuard} />}
<ModuleSettings serverId={serverId} module={selected} onSaved={() => setChanged(true)} onRegisterGuard={setGuard} />
{selected.id === "custom-races" && <RaceAvailabilitySettings serverId={serverId}
blocked={racesInstalling || toggling !== null} onSaved={() => setChanged(true)}
@@ -461,7 +465,7 @@ function ModuleSettings({ serverId, module, onSaved, onRegisterGuard }: { server
else next[key] = value;
return next;
});
const available = items?.filter(s => s.key !== moduleEnableKey(module.id) && !["CoACustomRaces.DisabledRaceIds", "CoACustomRaces.DisabledRaceCatalogSha256"].includes(s.key) && !retiredModuleKeys.has(s.key)) ?? [];
const available = items?.filter(s => s.key !== moduleEnableKey(module.id) && !["CoACustomRaces.DisabledRaceIds", "CoACustomRaces.DisabledRaceCatalogSha256", "PBC.DefaultConnection"].includes(s.key) && !retiredModuleKeys.has(s.key)) ?? [];
const advancedCount = available.filter(s => !auctionWeightKey(s.key) && (!moduleField(s.key, locale, s.field) || moduleField(s.key, locale, s.field)?.advanced)).length;
const visible = available.filter(s => {
if (module.id === "ah-bot" && auctionWeightKey(s.key)) return false;
+141
View File
@@ -0,0 +1,141 @@
import { useCallback, useEffect, useState } from "react";
import { Button } from "@/components/ui/button";
import { useHuman, useI18n } from "@/i18n";
import { api, asUiError, type PbcConnection, type PbcConnectionSetup, type UiError } from "@/lib/api";
import type { UnsavedChangesGuard } from "@/lib/unsavedGuard";
type Provider = "openai" | "ollama" | "anthropic" | "compatible";
const presets: Record<Provider, PbcConnection> = {
openai: { apiType: "openai", baseUrl: "https://api.openai.com/v1", model: "gpt-5.4-mini" },
ollama: { apiType: "ollama", baseUrl: "http://127.0.0.1:11434", model: "" },
anthropic: { apiType: "anthropic", baseUrl: "https://api.anthropic.com/v1", model: "" },
compatible: { apiType: "openai", baseUrl: "", model: "" },
};
const providerOf = (connection: PbcConnection): Provider => connection.apiType !== "openai" ? connection.apiType
: connection.baseUrl === presets.openai.baseUrl ? "openai" : "compatible";
const inputClass = "selectable w-full rounded-md border border-line bg-bg px-3 py-2 text-sm outline-none focus:border-gold";
export function PbcConnectionSettings({ serverId, onSaved, onRegisterGuard }: {
serverId: string;
onSaved: () => void;
onRegisterGuard: (guard: UnsavedChangesGuard | null) => void;
}) {
const { t } = useI18n();
const human = useHuman();
const [setup, setSetup] = useState<PbcConnectionSetup | null>(null);
const [connection, setConnection] = useState<PbcConnection>(presets.openai);
const [provider, setProvider] = useState<Provider>("openai");
const [apiKey, setApiKey] = useState("");
const [removeKey, setRemoveKey] = useState(false);
const [busy, setBusy] = useState(false);
const [error, setError] = useState<UiError | null>(null);
const [saved, setSaved] = useState(false);
const reset = useCallback((value: PbcConnectionSetup) => {
const current = value.connection ?? presets.openai;
setConnection(current);
setProvider(providerOf(current));
setApiKey("");
setRemoveKey(false);
}, []);
useEffect(() => {
let cancelled = false;
setSetup(null);
setSaved(false);
setError(null);
void api.pbcConnection(serverId).then(value => {
if (cancelled) return;
setSetup(value);
reset(value);
}).catch(e => { if (!cancelled) setError(asUiError(e)); });
return () => { cancelled = true; };
}, [serverId, reset]);
const previous = setup?.connection ?? presets.openai;
const dirty = !!setup && (connection.apiType !== previous.apiType || connection.baseUrl !== previous.baseUrl
|| connection.model !== previous.model || !!apiKey || removeKey);
const sameEndpoint = connection.apiType === previous.apiType
&& connection.baseUrl.trim().replace(/\/+$/, "") === previous.baseUrl;
const hasKey = !!setup?.connection?.hasKey && sameEndpoint;
const valid = !!connection.baseUrl.trim() && !!connection.model.trim();
const save = useCallback(async () => {
if (!setup || !valid || busy) return false;
setBusy(true);
setSaved(false);
setError(null);
try {
const next = await api.pbcSaveConnection(serverId, { ...connection, apiKey: apiKey || undefined, removeKey });
setSetup(next);
reset(next);
setSaved(true);
onSaved();
return true;
} catch (e) {
setError(asUiError(e));
return false;
} finally {
setBusy(false);
}
}, [setup, valid, busy, serverId, connection, apiKey, removeKey, reset, onSaved]);
useEffect(() => {
if (!setup || !dirty) return;
onRegisterGuard({ isDirty: () => true, save, discard: () => reset(setup) });
return () => onRegisterGuard(null);
}, [setup, dirty, save, reset, onRegisterGuard]);
function changeProvider(value: Provider) {
setProvider(value);
setConnection(presets[value]);
setApiKey("");
setRemoveKey(false);
setSaved(false);
}
return (
<section className="mt-4 space-y-3 border-t border-line pt-4" aria-labelledby="pbc-connection-heading">
<h3 id="pbc-connection-heading" className="font-semibold">{t("mod.pbc.connection")}</h3>
{error && <p className="text-sm text-warn" role="alert">{error.human.code === "unknown" ? error.technical : human(error.human).message}</p>}
{setup && (
<form className="space-y-3" onSubmit={event => { event.preventDefault(); void save(); }}>
{!setup.active && <p className="text-sm text-muted">{t("mod.pbc.useConnection")}</p>}
<fieldset disabled={busy} className="grid gap-3 sm:grid-cols-2">
<label className="space-y-1 text-sm">
<span>{t("mod.pbc.provider")}</span>
<select className={inputClass} value={provider} onChange={event => changeProvider(event.target.value as Provider)}>
<option value="openai">OpenAI</option>
<option value="ollama">Ollama</option>
<option value="anthropic">Anthropic</option>
<option value="compatible">{t("mod.pbc.compatible")}</option>
</select>
</label>
<label className="space-y-1 text-sm">
<span>{t("mod.pbc.model")}</span>
<input className={inputClass} value={connection.model} required onChange={event => { setConnection({ ...connection, model: event.target.value }); setSaved(false); }} />
</label>
<label className="space-y-1 text-sm sm:col-span-2">
<span>{t("mod.pbc.endpoint")}</span>
<input className={inputClass} value={connection.baseUrl} type="url" required readOnly={provider === "openai"}
onChange={event => { setConnection({ ...connection, baseUrl: event.target.value }); setApiKey(""); setRemoveKey(false); setSaved(false); }} />
</label>
<label className="space-y-1 text-sm sm:col-span-2">
<span>{t("mod.pbc.key")}</span>
<input className={inputClass} value={apiKey} type="password" autoComplete="off" disabled={removeKey}
placeholder={hasKey ? t("mod.pbc.savedKey") : undefined}
onChange={event => { setApiKey(event.target.value); setSaved(false); }} />
</label>
{hasKey && <label className="flex items-center gap-2 text-sm sm:col-span-2">
<input type="checkbox" checked={removeKey} onChange={event => { setRemoveKey(event.target.checked); setApiKey(""); setSaved(false); }} />
{t("mod.pbc.removeKey")}
</label>}
</fieldset>
<p className="text-sm text-muted">{t("mod.pbc.keyHint")}</p>
<Button size="sm" type="submit" disabled={busy || !valid || (setup.active && !dirty)}>{t("mod.pbc.save")}</Button>
{saved && <p className="text-sm text-ok" role="status">{t("mod.pbc.saved")}</p>}
</form>
)}
</section>
);
}