Show player-facing processing feedback
Build and publish frontend / publish (push) Successful in 47s
Build and publish frontend / publish (push) Successful in 47s
This commit is contained in:
@@ -10,5 +10,5 @@
|
|||||||
- Helm charts are published to `harbor.k3s.k0.nu/ai-spel`; Argo CD uses the existing `ai-spel` project and namespace.
|
- Helm charts are published to `harbor.k3s.k0.nu/ai-spel`; Argo CD uses the existing `ai-spel` project and namespace.
|
||||||
- Player-facing speech uses the local Piper WebAssembly adapter when the player has activated audio. The separate `ai-spel-static` Nginx service serves pinned Swedish Piper models and ONNX/Piper runtime files from same-origin `/static/piper-wasm-v1/` URLs with immutable caching. Game text is synthesized on-device and must never be sent to a TTS provider.
|
- Player-facing speech uses the local Piper WebAssembly adapter when the player has activated audio. The separate `ai-spel-static` Nginx service serves pinned Swedish Piper models and ONNX/Piper runtime files from same-origin `/static/piper-wasm-v1/` URLs with immutable caching. Game text is synthesized on-device and must never be sent to a TTS provider.
|
||||||
- This pipeline bundles only the Piper worker/client glue. Model/runtime downloads, image builds, and deployment belong to `ai-spel/ai-spel-static` and the existing `large` runner. Never build or run these assets locally.
|
- This pipeline bundles only the Piper worker/client glue. Model/runtime downloads, image builds, and deployment belong to `ai-spel/ai-spel-static` and the existing `large` runner. Never build or run these assets locally.
|
||||||
- Browser local AI loads its client adapter, Wllama runtime, WebAssembly, Gemma model, manifest, YAML prompt, and license resources only from the same-origin `/static/wllama-gemma3-v1/` path owned by `ai-spel/ai-spel-static`. Do not add browser CDN, npm, or model-hub fallbacks. The player must be shown and accept applicable model terms before the model downloads or runs. Acceptance, model failure, or local-AI opt-out must never block play. Incompatible asset changes require a new immutable static path and a coordinated frontend release.
|
- Browser local AI loads its client adapter, Wllama runtime, WebAssembly, Gemma model, manifest, YAML prompt, and license resources only from the same-origin `/static/wllama-gemma3-v2/` path owned by `ai-spel/ai-spel-static`. Do not add browser CDN, npm, or model-hub fallbacks. The player must be shown and accept applicable model terms before the model downloads or runs. Acceptance, model failure, or local-AI opt-out must never block play. Incompatible asset changes require a new immutable static path and a coordinated frontend release.
|
||||||
- Local model output is advisory only. Preserve the original player input, send local hints only as untrusted context to Rust, and label offline replies as unsaved. Local diagnostic logging is opt-in, browser-local, exportable/deletable, and expires after 30 days.
|
- Local model output is advisory only. Preserve the original player input, send local hints only as untrusted context to Rust, and label offline replies as unsaved. Local diagnostic logging is opt-in, browser-local, exportable/deletable, and expires after 30 days.
|
||||||
|
|||||||
+48
-8
@@ -116,7 +116,7 @@
|
|||||||
<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>
|
<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="/piper-runtime.js?v=__FRONTEND_VERSION__"></script>
|
||||||
<script src="/voice.js?v=__FRONTEND_VERSION__"></script>
|
<script src="/voice.js?v=__FRONTEND_VERSION__"></script>
|
||||||
<script src="/static/wllama-gemma3-v1/local-ai.js"></script>
|
<script src="/static/wllama-gemma3-v2/local-ai.js"></script>
|
||||||
<script>
|
<script>
|
||||||
const auth = document.querySelector('#auth');
|
const auth = document.querySelector('#auth');
|
||||||
const play = document.querySelector('#play');
|
const play = document.querySelector('#play');
|
||||||
@@ -174,6 +174,24 @@
|
|||||||
}
|
}
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
let activityStatusLine = null;
|
||||||
|
function setActivityStatus(message) {
|
||||||
|
if (!message) return;
|
||||||
|
if (!activityStatusLine?.isConnected) {
|
||||||
|
activityStatusLine = document.createElement('li');
|
||||||
|
activityStatusLine.dataset.role = 'system';
|
||||||
|
activityStatusLine.dataset.activityStatus = 'true';
|
||||||
|
activityStatusLine.setAttribute('role', 'status');
|
||||||
|
activityStatusLine.setAttribute('aria-live', 'polite');
|
||||||
|
transcript.append(activityStatusLine);
|
||||||
|
}
|
||||||
|
activityStatusLine.textContent = `Berättelsen: ${message}`;
|
||||||
|
activityStatusLine.scrollIntoView({block: 'end'});
|
||||||
|
}
|
||||||
|
function clearActivityStatus() {
|
||||||
|
activityStatusLine?.remove();
|
||||||
|
activityStatusLine = null;
|
||||||
|
}
|
||||||
function biographyContextText(context) {
|
function biographyContextText(context) {
|
||||||
if (!context || typeof context !== 'object') return '';
|
if (!context || typeof context !== 'object') return '';
|
||||||
const details = [];
|
const details = [];
|
||||||
@@ -210,13 +228,17 @@
|
|||||||
}
|
}
|
||||||
window.addEventListener('local-ai-status', event => {
|
window.addEventListener('local-ai-status', event => {
|
||||||
if (!currentAccount || currentAccount.is_admin || play.hidden) return;
|
if (!currentAccount || currentAccount.is_admin || play.hidden) return;
|
||||||
let statusLine = transcript.querySelector('li[data-local-ai-status]');
|
|
||||||
if (!statusLine) {
|
|
||||||
const detail = typeof event.detail === 'string' ? {text: event.detail} : event.detail;
|
|
||||||
statusLine = appendLine(detail.type === 'terms-required' ? 'assistant' : 'system', detail.text || '', {speaker: 'Lokal AI', speak: detail.type === 'terms-required'});
|
|
||||||
statusLine.dataset.localAiStatus = 'true';
|
|
||||||
}
|
|
||||||
const detail = typeof event.detail === 'string' ? {text: event.detail} : event.detail;
|
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}]`);
|
||||||
|
if (!statusLine) {
|
||||||
|
statusLine = appendLine(detail.type === 'terms-required' ? 'assistant' : 'system', detail.text || '', {
|
||||||
|
speaker: 'Lokal AI', speak: detail.type === 'terms-required',
|
||||||
|
});
|
||||||
|
statusLine.setAttribute(statusAttribute, 'true');
|
||||||
|
statusLine.setAttribute('role', 'status');
|
||||||
|
statusLine.setAttribute('aria-live', 'polite');
|
||||||
|
}
|
||||||
statusLine.replaceChildren(document.createTextNode(`Lokal AI: ${detail.text || ''}`));
|
statusLine.replaceChildren(document.createTextNode(`Lokal AI: ${detail.text || ''}`));
|
||||||
if (detail.type === 'terms-required') {
|
if (detail.type === 'terms-required') {
|
||||||
statusLine.append(document.createTextNode(' Läs dokumenten: '));
|
statusLine.append(document.createTextNode(' Läs dokumenten: '));
|
||||||
@@ -670,15 +692,17 @@
|
|||||||
stage = 'world-start';
|
stage = 'world-start';
|
||||||
messageField.disabled = true;
|
messageField.disabled = true;
|
||||||
appendLine('user', message);
|
appendLine('user', message);
|
||||||
appendLine('assistant', 'Jag tar fram ett förslag på startplats och startläge…');
|
setActivityStatus('Berättaren ber AI ta fram ett förslag på startvärld och en plats som passar din biografi.');
|
||||||
try {
|
try {
|
||||||
const proposal = await request('/api/world/draft', {
|
const proposal = await request('/api/world/draft', {
|
||||||
method: 'POST', headers: {'content-type': 'application/json'},
|
method: 'POST', headers: {'content-type': 'application/json'},
|
||||||
body: JSON.stringify({input: message, current_draft: worldDraft}),
|
body: JSON.stringify({input: message, current_draft: worldDraft}),
|
||||||
});
|
});
|
||||||
worldDraft = proposal.draft;
|
worldDraft = proposal.draft;
|
||||||
|
clearActivityStatus();
|
||||||
appendLine('assistant', `${proposal.message}\n\nVärld: ${worldDraft.name}\nStartplats: ${worldDraft.location_name}. ${worldDraft.location_description}\nStartbelopp: ${worldDraft.starting_balance_sek} kronor. ${worldDraft.offer_name} kostar ${worldDraft.offer_price_sek} kronor.\n\nSkriv ändringar eller “godkänn”.`);
|
appendLine('assistant', `${proposal.message}\n\nVärld: ${worldDraft.name}\nStartplats: ${worldDraft.location_name}. ${worldDraft.location_description}\nStartbelopp: ${worldDraft.starting_balance_sek} kronor. ${worldDraft.offer_name} kostar ${worldDraft.offer_price_sek} kronor.\n\nSkriv ändringar eller “godkänn”.`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
clearActivityStatus();
|
||||||
appendLine('assistant', `Förslaget kunde inte tas fram: ${error.message}. Skriv “försök igen” när du vill försöka på nytt.`);
|
appendLine('assistant', `Förslaget kunde inte tas fram: ${error.message}. Skriv “försök igen” när du vill försöka på nytt.`);
|
||||||
}
|
}
|
||||||
setStage('world-draft');
|
setStage('world-draft');
|
||||||
@@ -692,6 +716,7 @@
|
|||||||
}
|
}
|
||||||
appendLine('user', message);
|
appendLine('user', message);
|
||||||
messageField.disabled = true;
|
messageField.disabled = true;
|
||||||
|
setActivityStatus('Sparar det godkända världsförslaget och skapar din startposition.');
|
||||||
try {
|
try {
|
||||||
gameState = await request('/api/world/start', {
|
gameState = await request('/api/world/start', {
|
||||||
method: 'POST', headers: {'content-type': 'application/json'}, body: JSON.stringify(worldDraft),
|
method: 'POST', headers: {'content-type': 'application/json'}, body: JSON.stringify(worldDraft),
|
||||||
@@ -699,8 +724,10 @@
|
|||||||
worldDraft = null;
|
worldDraft = null;
|
||||||
await loadSavedDialogue();
|
await loadSavedDialogue();
|
||||||
setStage('game');
|
setStage('game');
|
||||||
|
clearActivityStatus();
|
||||||
appendLine('assistant', 'Du kan fråga om platsen, dina saker eller din ekonomi, vänta, handla, prata med någon som finns här eller skriva vart du vill gå.');
|
appendLine('assistant', 'Du kan fråga om platsen, dina saker eller din ekonomi, vänta, handla, prata med någon som finns här eller skriva vart du vill gå.');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
clearActivityStatus();
|
||||||
appendLine('assistant', `Världsförslaget kunde inte sparas: ${error.message}. Förslaget finns kvar så att du kan försöka igen.`);
|
appendLine('assistant', `Världsförslaget kunde inte sparas: ${error.message}. Förslaget finns kvar så att du kan försöka igen.`);
|
||||||
}
|
}
|
||||||
messageField.disabled = false;
|
messageField.disabled = false;
|
||||||
@@ -924,6 +951,7 @@
|
|||||||
}
|
}
|
||||||
appendLine('user', message);
|
appendLine('user', message);
|
||||||
messageField.disabled = true;
|
messageField.disabled = true;
|
||||||
|
setActivityStatus('Berättaren ber AI skapa eller uppdatera ett biografiförslag utifrån det du skrev.');
|
||||||
try {
|
try {
|
||||||
const proposal = await request('/api/character/draft', {
|
const proposal = await request('/api/character/draft', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -931,8 +959,10 @@
|
|||||||
body: JSON.stringify({input: message, current_draft: characterDraft}),
|
body: JSON.stringify({input: message, current_draft: characterDraft}),
|
||||||
});
|
});
|
||||||
characterDraft = proposal.draft;
|
characterDraft = proposal.draft;
|
||||||
|
clearActivityStatus();
|
||||||
appendLine('assistant', `${proposal.message}\n\nFörslag: ${characterDraft.name}, ${characterDraft.age} år.\n${characterDraft.biography}${biographyContextText(characterDraft.life_context)}\n\nSkriv ändringar eller “godkänn”.`);
|
appendLine('assistant', `${proposal.message}\n\nFörslag: ${characterDraft.name}, ${characterDraft.age} år.\n${characterDraft.biography}${biographyContextText(characterDraft.life_context)}\n\nSkriv ändringar eller “godkänn”.`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
clearActivityStatus();
|
||||||
appendLine('assistant', `Jag kunde inte ta fram ett biografiförslag: ${error.message}. Försök igen när tjänsten svarar.`);
|
appendLine('assistant', `Jag kunde inte ta fram ett biografiförslag: ${error.message}. Försök igen när tjänsten svarar.`);
|
||||||
}
|
}
|
||||||
messageField.disabled = false;
|
messageField.disabled = false;
|
||||||
@@ -977,6 +1007,11 @@
|
|||||||
if (actionMode === 'normal') pendingDialogue = {message, idempotencyKey};
|
if (actionMode === 'normal') pendingDialogue = {message, idempotencyKey};
|
||||||
appendLine('user', message, actionMode === 'dry_run' ? {speaker: 'Torrkörning'} : actionMode === 'redo' ? {speaker: 'Gör om'} : {});
|
appendLine('user', message, actionMode === 'dry_run' ? {speaker: 'Torrkörning'} : actionMode === 'redo' ? {speaker: 'Gör om'} : {});
|
||||||
messageField.disabled = true;
|
messageField.disabled = true;
|
||||||
|
setActivityStatus(actionMode === 'dry_run'
|
||||||
|
? 'Torrkör handlingen utan att spara eller göra framsteg.'
|
||||||
|
: actionMode === 'redo'
|
||||||
|
? 'Gör om den senaste handlingen med aktuella regler.'
|
||||||
|
: '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 {
|
try {
|
||||||
let clientAssistance = null;
|
let clientAssistance = null;
|
||||||
if (actionMode === 'normal' && currentAccount && !currentAccount.is_admin && window.localGameAI) {
|
if (actionMode === 'normal' && currentAccount && !currentAccount.is_admin && window.localGameAI) {
|
||||||
@@ -1017,7 +1052,11 @@
|
|||||||
if (refreshed.world) gameState = refreshed;
|
if (refreshed.world) gameState = refreshed;
|
||||||
} catch (_) { /* The committed dialogue stays successful if this optional view refresh fails. */ }
|
} catch (_) { /* The committed dialogue stays successful if this optional view refresh fails. */ }
|
||||||
}
|
}
|
||||||
|
clearActivityStatus();
|
||||||
const speakingNpc = result.status !== 'dry_run' && ['speak', 'meet'].includes(result.intent) ? gameState.world.npc : null;
|
const speakingNpc = result.status !== 'dry_run' && ['speak', 'meet'].includes(result.intent) ? gameState.world.npc : null;
|
||||||
|
for (const change of result.world_changes || []) {
|
||||||
|
appendLine('system', change, {speaker: 'Världsändring', speak: false});
|
||||||
|
}
|
||||||
for (const ruleName of result.debug_rules_created || []) {
|
for (const ruleName of result.debug_rules_created || []) {
|
||||||
appendLine('assistant', ruleName, {speaker: 'Nya regler', speak: false});
|
appendLine('assistant', ruleName, {speaker: 'Nya regler', speak: false});
|
||||||
}
|
}
|
||||||
@@ -1031,6 +1070,7 @@
|
|||||||
}
|
}
|
||||||
refreshActionTools();
|
refreshActionTools();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
clearActivityStatus();
|
||||||
messageField.value = message;
|
messageField.value = message;
|
||||||
try {
|
try {
|
||||||
const history = [...transcript.querySelectorAll('li')].map(line => line.textContent).filter(Boolean);
|
const history = [...transcript.querySelectorAll('li')].map(line => line.textContent).filter(Boolean);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ test -s index.html
|
|||||||
grep -q '<html lang="sv">' index.html
|
grep -q '<html lang="sv">' index.html
|
||||||
grep -q 'id="frontend-version">__FRONTEND_VERSION__' index.html
|
grep -q 'id="frontend-version">__FRONTEND_VERSION__' index.html
|
||||||
grep -q '<script src="/voice.js?v=__FRONTEND_VERSION__"></script>' index.html
|
grep -q '<script src="/voice.js?v=__FRONTEND_VERSION__"></script>' index.html
|
||||||
grep -q '<script src="/static/wllama-gemma3-v1/local-ai.js"></script>' index.html
|
grep -q '<script src="/static/wllama-gemma3-v2/local-ai.js"></script>' index.html
|
||||||
grep -q '<script src="/piper-runtime.js?v=__FRONTEND_VERSION__"></script>' index.html
|
grep -q '<script src="/piper-runtime.js?v=__FRONTEND_VERSION__"></script>' index.html
|
||||||
grep -q 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0' nginx/default.conf
|
grep -q 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0' nginx/default.conf
|
||||||
grep -q 'Cross-Origin-Embedder-Policy "require-corp"' nginx/default.conf
|
grep -q 'Cross-Origin-Embedder-Policy "require-corp"' nginx/default.conf
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
const assert = require('node:assert/strict');
|
||||||
|
const fs = require('node:fs');
|
||||||
|
const path = require('node:path');
|
||||||
|
const test = require('node:test');
|
||||||
|
|
||||||
|
const source = fs.readFileSync(path.join(__dirname, '..', 'index.html'), 'utf8');
|
||||||
|
|
||||||
|
test('player sees an accessible live activity line during world and character proposals', () => {
|
||||||
|
assert.match(source, /function setActivityStatus\(message\)/);
|
||||||
|
assert.match(source, /setAttribute\('aria-live', 'polite'\)/);
|
||||||
|
assert.match(source, /AI ta fram ett förslag på startvärld och en plats/);
|
||||||
|
assert.match(source, /AI skapa eller uppdatera ett biografiförslag/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('dialogue processing explains that scene, place, or person establishment is being considered', () => {
|
||||||
|
assert.match(source, /Berättaren arbetar med din avsikt\. Den avgör om en plats, scen eller person behöver etableras/);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('local AI activity is shown separately from general narrator processing', () => {
|
||||||
|
assert.match(source, /detail\.type === 'activity' \? 'data-local-ai-activity'/);
|
||||||
|
assert.match(source, /Lokal AI: \$\{detail\.text \|\| ''\}/);
|
||||||
|
assert.match(source, /clearActivityStatus\(\);/);
|
||||||
|
});
|
||||||
@@ -6,7 +6,7 @@ const test = require('node:test');
|
|||||||
const page = fs.readFileSync(path.join(__dirname, '..', 'index.html'), 'utf8');
|
const page = fs.readFileSync(path.join(__dirname, '..', 'index.html'), 'utf8');
|
||||||
|
|
||||||
test('local AI adapter comes from the static service and starts after authenticated game entry', () => {
|
test('local AI adapter comes from the static service and starts after authenticated game entry', () => {
|
||||||
assert.match(page, /<script src="\/static\/wllama-gemma3-v1\/local-ai\.js"><\/script>/);
|
assert.match(page, /<script src="\/static\/wllama-gemma3-v2\/local-ai\.js"><\/script>/);
|
||||||
assert.match(page, /showPlay\(\);\s*if \(!currentAccount\.is_admin\) window\.localGameAI\?\.start\(currentAccount\.id\)/);
|
assert.match(page, /showPlay\(\);\s*if \(!currentAccount\.is_admin\) window\.localGameAI\?\.start\(currentAccount\.id\)/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user