Pause browser local AI behind disabled feature flag
Build and publish frontend / publish (push) Failing after 2s
Build and publish frontend / publish (push) Failing after 2s
This commit is contained in:
+30
-8
@@ -116,8 +116,25 @@
|
||||
<footer id="version-footer">Frontend <span id="frontend-version">__FRONTEND_VERSION__</span> · Statik <span id="static-version">hämtar version…</span> · API <span id="api-version">hämtar version…</span></footer>
|
||||
<script src="/piper-runtime.js?v=__FRONTEND_VERSION__"></script>
|
||||
<script src="/voice.js?v=__FRONTEND_VERSION__"></script>
|
||||
<script src="/static/wllama-gemma3-v2/local-ai.js"></script>
|
||||
<script>
|
||||
// Local Gemma/Wllama assistance is paused until explicitly re-enabled here.
|
||||
// Keep the adapter unloaded when false so it cannot download or initialize.
|
||||
const FEATURE_FLAGS = Object.freeze({localAI: false});
|
||||
let localAiAdapterPromise = null;
|
||||
function loadLocalAiAdapter() {
|
||||
if (!FEATURE_FLAGS.localAI) return Promise.resolve(null);
|
||||
if (window.localGameAI) return Promise.resolve(window.localGameAI);
|
||||
if (!localAiAdapterPromise) {
|
||||
localAiAdapterPromise = new Promise((resolve) => {
|
||||
const script = document.createElement('script');
|
||||
script.src = '/static/' + 'wllama-gemma3-v2/local-ai.js';
|
||||
script.onload = () => resolve(window.localGameAI || null);
|
||||
script.onerror = () => resolve(null);
|
||||
document.head.append(script);
|
||||
});
|
||||
}
|
||||
return localAiAdapterPromise;
|
||||
}
|
||||
const auth = document.querySelector('#auth');
|
||||
const play = document.querySelector('#play');
|
||||
const playLayout = document.querySelector('#play-layout');
|
||||
@@ -163,7 +180,7 @@
|
||||
line.dataset.role = role;
|
||||
line.textContent = `${options.speaker || (role === 'user' ? 'Du' : 'Berättelsen')}: ${content}`;
|
||||
transcript.append(line);
|
||||
if (role === 'user' || role === 'assistant') window.localGameAI?.record({type: 'dialogue', role, content});
|
||||
if (FEATURE_FLAGS.localAI && (role === 'user' || role === 'assistant')) window.localGameAI?.record({type: 'dialogue', role, content});
|
||||
line.scrollIntoView({block: 'end'});
|
||||
if (role === 'assistant') {
|
||||
latestAssistantText = content;
|
||||
@@ -227,7 +244,7 @@
|
||||
if (authVoiceStatus && !auth.hidden && message) authVoiceStatus.textContent = message;
|
||||
}
|
||||
window.addEventListener('local-ai-status', event => {
|
||||
if (!currentAccount || currentAccount.is_admin || play.hidden) return;
|
||||
if (!FEATURE_FLAGS.localAI || !currentAccount || currentAccount.is_admin || play.hidden) return;
|
||||
const detail = typeof event.detail === 'string' ? {text: event.detail} : event.detail;
|
||||
const statusAttribute = detail.type === 'activity' ? 'data-local-ai-activity' : 'data-local-ai-status';
|
||||
let statusLine = transcript.querySelector(`li[${statusAttribute}]`);
|
||||
@@ -751,7 +768,10 @@
|
||||
currentAccount = await request('/api/me');
|
||||
gameState = await request('/api/world');
|
||||
showPlay();
|
||||
if (!currentAccount.is_admin) window.localGameAI?.start(currentAccount.id);
|
||||
if (!currentAccount.is_admin && FEATURE_FLAGS.localAI) {
|
||||
const localAI = await loadLocalAiAdapter();
|
||||
localAI?.start(currentAccount.id);
|
||||
}
|
||||
if (!gameState.character) {
|
||||
transcript.replaceChildren();
|
||||
appendInitialPrompt();
|
||||
@@ -918,7 +938,7 @@
|
||||
presenceTimer = null;
|
||||
playerMessagesPrimed = false;
|
||||
seenPlayerMessageIds.clear();
|
||||
window.localGameAI?.stop();
|
||||
if (FEATURE_FLAGS.localAI) window.localGameAI?.stop();
|
||||
await request('/api/logout', {method: 'POST'});
|
||||
if (location.pathname !== '/admin') appendLine('assistant', 'Du har loggat ut. Logga in igen för att fortsätta spela.');
|
||||
characterDraft = null;
|
||||
@@ -974,7 +994,7 @@
|
||||
document.querySelector('#dry-run-action').disabled = !enabled;
|
||||
}
|
||||
async function handleGameMessage(message, actionMode = 'normal') {
|
||||
if (actionMode === 'normal' && /^lokal ai(?:\s|$)/i.test(message.trim())) {
|
||||
if (FEATURE_FLAGS.localAI && actionMode === 'normal' && /^lokal ai(?:\s|$)/i.test(message.trim())) {
|
||||
const response = await window.localGameAI?.settings(message);
|
||||
appendLine('user', message);
|
||||
appendLine('assistant', response || 'Kommandon: “lokal ai villkor”, “lokal ai godkänn villkor”, “lokal ai avvisa villkor”, “lokal ai på/av”, “lokal ai loggar på/av”, “lokal ai exportera loggar” och “lokal ai radera loggar”.');
|
||||
@@ -1014,7 +1034,7 @@
|
||||
: 'Berättaren arbetar med din avsikt. Den avgör om en plats, scen eller person behöver etableras och fortsätter sedan berättelsen.');
|
||||
try {
|
||||
let clientAssistance = null;
|
||||
if (actionMode === 'normal' && currentAccount && !currentAccount.is_admin && window.localGameAI) {
|
||||
if (FEATURE_FLAGS.localAI && actionMode === 'normal' && currentAccount && !currentAccount.is_admin && window.localGameAI) {
|
||||
try {
|
||||
const history = [...transcript.querySelectorAll('li')].map(line => line.textContent).filter(Boolean);
|
||||
const assisted = await window.localGameAI.assist(message, history, gameState?.world || {});
|
||||
@@ -1074,7 +1094,9 @@
|
||||
messageField.value = message;
|
||||
try {
|
||||
const history = [...transcript.querySelectorAll('li')].map(line => line.textContent).filter(Boolean);
|
||||
const localReply = await window.localGameAI?.offline(message, history, gameState?.world || {});
|
||||
const localReply = FEATURE_FLAGS.localAI
|
||||
? await window.localGameAI?.offline(message, history, gameState?.world || {})
|
||||
: null;
|
||||
if (localReply) appendLine('assistant', `Lokalt, osparat förslag: ${localReply}`, {speaker: 'Lokal hjälp'});
|
||||
else appendLine('assistant', `${explainDialogueError(error)} Ditt meddelande ligger kvar i inmatningen.`);
|
||||
} catch (_) { appendLine('assistant', `${explainDialogueError(error)} Ditt meddelande ligger kvar i inmatningen.`); }
|
||||
|
||||
Reference in New Issue
Block a user