Consolidate engine docs and naming
This commit is contained in:
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
export type EngineName = 'yaml' | 'ink' | 'zork' | string;
|
||||
export type EngineName = 'yaml' | 'ink' | 'zcode' | string;
|
||||
export interface GameMetadata {
|
||||
title: string;
|
||||
author?: string;
|
||||
|
||||
Vendored
+1
-1
@@ -17,7 +17,7 @@ function fallbackConfig(engine) {
|
||||
paths: {
|
||||
mainGameFile: engine === 'ink'
|
||||
? 'data/ink/story.ink.json'
|
||||
: engine === 'zork'
|
||||
: engine === 'zcode'
|
||||
? 'data/z-code/zork1.bin'
|
||||
: 'data/worlds/example_world.yml',
|
||||
music: 'public/music',
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"game-config.js","sourceRoot":"","sources":["../../src/config/game-config.ts"],"names":[],"mappings":";;;;;AA4DA,kCAIC;AAED,wCAsBC;AAED,4EAkBC;AAED,4CAYC;AA1HD,gDAAwB;AACxB,2BAAyD;AA+BzD,MAAM,YAAY,GAAG,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AAEtD,SAAS,cAAc,CAAC,MAAkB;IACxC,OAAO;QACL,MAAM;QACN,MAAM,EAAE,OAAO;QACf,KAAK,EAAE;YACL,YAAY,EACV,MAAM,KAAK,KAAK;gBACd,CAAC,CAAC,yBAAyB;gBAC3B,CAAC,CAAC,MAAM,KAAK,MAAM;oBACjB,CAAC,CAAC,uBAAuB;oBACzB,CAAC,CAAC,+BAA+B;YACvC,KAAK,EAAE,cAAc;YACrB,GAAG,EAAE,eAAe;YACpB,MAAM,EAAE,eAAe;SACxB;QACD,QAAQ,EAAE;YACR,KAAK,EAAE,wBAAwB;YAC/B,MAAM,EAAE,eAAe;YACvB,QAAQ,EAAE,8BAA8B;YACxC,OAAO,EAAE,OAAO;YAChB,SAAS,EAAE,EAAE;YACb,QAAQ,EAAE,OAAO;SAClB;KACF,CAAC;AACJ,CAAC;AAED,SAAgB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SAAS,IAAI,WAAW,EAAE,CAAC;QACpC,IAAI,CAAC,SAAS;YAAE,SAAS;QACzB,MAAM,YAAY,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC;QAC5C,IAAI,CAAC,IAAA,eAAU,EAAC,YAAY,CAAC,EAAE,CAAC;YAC9B,IAAA,cAAS,EAAC,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAgB,gBAAgB,CAAC,MAAwB;IACvD,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,MAAM,EAAE;YACN,KAAK,EAAE,SAAS;YAChB,GAAG,EAAE,UAAU;YACf,MAAM,EAAE,UAAU;YAClB,MAAM,EAAE,UAAU;SACnB;KACF,CAAC;AACJ,CAAC"}
|
||||
@@ -1,19 +1,19 @@
|
||||
/**
|
||||
* Zork LLM Engine
|
||||
* Z-code LLM Engine
|
||||
*
|
||||
* Runs Zork I (or any Z-machine story file) as a headless subprocess via the
|
||||
* Runs a Z-machine story file as a headless subprocess via the
|
||||
* `ifvms` CLI, and wraps every I/O exchange with OpenRouter LLM calls that
|
||||
* translate free natural-language player input into parser commands and
|
||||
* re-voice the Z-machine's raw output as polished narrative prose.
|
||||
*
|
||||
* Configuration (environment variables):
|
||||
* ZORK_STORY_FILE – path to the .z5/.z8/.bin story file (default: ./data/z-code/zork1.bin)
|
||||
* ZORK_MAX_RETRIES – maximum command retry attempts per turn (default: 3)
|
||||
* ZORK_HISTORY_SIZE – player-facing outputs stored per room (default: 5)
|
||||
* OPENROUTER_API_KEY, OPENROUTER_MODEL – required
|
||||
* ZCODE_STORY_FILE - path to the .z5/.z8/.bin story file (default: ./data/z-code/zork1.bin)
|
||||
* ZCODE_MAX_RETRIES - maximum command retry attempts per turn (default: 3)
|
||||
* ZCODE_HISTORY_SIZE - player-facing outputs stored per room (default: 5)
|
||||
* OPENROUTER_API_KEY, OPENROUTER_MODEL - required
|
||||
*/
|
||||
import { TurnResult } from '../interfaces/turn-result';
|
||||
export interface ZorkSession {
|
||||
export interface ZcodeSession {
|
||||
characterDescription: string;
|
||||
notes: string[];
|
||||
recentParagraphs: string[];
|
||||
@@ -22,14 +22,14 @@ export interface ZorkSession {
|
||||
timeOfDay: string;
|
||||
weather: string;
|
||||
virtualInventory: string[];
|
||||
/** roomName → last N player-facing output strings */
|
||||
/** roomName -> last N player-facing output strings */
|
||||
roomHistory: Record<string, string[]>;
|
||||
currentRoom: string;
|
||||
running: boolean;
|
||||
}
|
||||
export type ZorkTurnResult = TurnResult;
|
||||
export declare class ZorkLlmEngine {
|
||||
private zork;
|
||||
export type ZcodeTurnResult = TurnResult;
|
||||
export declare class ZcodeLlmEngine {
|
||||
private zmachine;
|
||||
private session;
|
||||
private prompts;
|
||||
private llm;
|
||||
@@ -49,14 +49,14 @@ export declare class ZorkLlmEngine {
|
||||
private resolveFallbackModel;
|
||||
isRunning(): boolean;
|
||||
/**
|
||||
* Start a new game: launch Zork, generate the player character, rewrite the
|
||||
* Start a new game: launch the Z-machine story, generate the player character, rewrite the
|
||||
* intro text, and return the first TurnResult for the client.
|
||||
*/
|
||||
newGame(): Promise<ZorkTurnResult>;
|
||||
newGame(): Promise<ZcodeTurnResult>;
|
||||
/**
|
||||
* Process player free-text input. Returns the next TurnResult.
|
||||
*/
|
||||
processInput(userInput: string): Promise<ZorkTurnResult>;
|
||||
processInput(userInput: string): Promise<ZcodeTurnResult>;
|
||||
private runCommandPlan;
|
||||
/**
|
||||
* Save the current game state. Returns a JSON string suitable for storing
|
||||
@@ -66,7 +66,7 @@ export declare class ZorkLlmEngine {
|
||||
/**
|
||||
* Load a previously saved game. Returns the first TurnResult after restore.
|
||||
*/
|
||||
loadGame(savedJson: string): Promise<ZorkTurnResult>;
|
||||
loadGame(savedJson: string): Promise<ZcodeTurnResult>;
|
||||
private runSingleCommandLoop;
|
||||
private generateCharacter;
|
||||
private rewriteText;
|
||||
@@ -1,17 +1,17 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Zork LLM Engine
|
||||
* Z-code LLM Engine
|
||||
*
|
||||
* Runs Zork I (or any Z-machine story file) as a headless subprocess via the
|
||||
* Runs a Z-machine story file as a headless subprocess via the
|
||||
* `ifvms` CLI, and wraps every I/O exchange with OpenRouter LLM calls that
|
||||
* translate free natural-language player input into parser commands and
|
||||
* re-voice the Z-machine's raw output as polished narrative prose.
|
||||
*
|
||||
* Configuration (environment variables):
|
||||
* ZORK_STORY_FILE – path to the .z5/.z8/.bin story file (default: ./data/z-code/zork1.bin)
|
||||
* ZORK_MAX_RETRIES – maximum command retry attempts per turn (default: 3)
|
||||
* ZORK_HISTORY_SIZE – player-facing outputs stored per room (default: 5)
|
||||
* OPENROUTER_API_KEY, OPENROUTER_MODEL – required
|
||||
* ZCODE_STORY_FILE - path to the .z5/.z8/.bin story file (default: ./data/z-code/zork1.bin)
|
||||
* ZCODE_MAX_RETRIES - maximum command retry attempts per turn (default: 3)
|
||||
* ZCODE_HISTORY_SIZE - player-facing outputs stored per room (default: 5)
|
||||
* OPENROUTER_API_KEY, OPENROUTER_MODEL - required
|
||||
*/
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
@@ -50,7 +50,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ZorkLlmEngine = void 0;
|
||||
exports.ZcodeLlmEngine = void 0;
|
||||
const child_process_1 = require("child_process");
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
@@ -60,15 +60,15 @@ const axios_1 = __importDefault(require("axios"));
|
||||
const dotenv = __importStar(require("dotenv"));
|
||||
const turn_result_1 = require("../interfaces/turn-result");
|
||||
dotenv.config();
|
||||
const DEBUG_ENABLED = /^(1|true|yes|on)$/i.test(process.env.ZORK_DEBUG ?? '');
|
||||
const DEBUG_ENABLED = /^(1|true|yes|on)$/i.test(process.env.ZCODE_DEBUG ?? '');
|
||||
function debugLog(message, details) {
|
||||
if (!DEBUG_ENABLED)
|
||||
return;
|
||||
if (typeof details === 'undefined') {
|
||||
console.log(`[ZorkLlm:debug] ${message}`);
|
||||
console.log(`[ZcodeLlm:debug] ${message}`);
|
||||
return;
|
||||
}
|
||||
console.log(`[ZorkLlm:debug] ${message}`, details);
|
||||
console.log(`[ZcodeLlm:debug] ${message}`, details);
|
||||
}
|
||||
function compactText(text, maxLength = 12000) {
|
||||
if (text.length <= maxLength)
|
||||
@@ -152,10 +152,10 @@ function isParserComplaint(output) {
|
||||
"there is no",
|
||||
].some(fragment => text.includes(fragment));
|
||||
}
|
||||
function formatExactReadOutput(command, zorkOutput) {
|
||||
function formatExactReadOutput(command, zcodeOutput) {
|
||||
const object = command.replace(/^READ\s+/i, '').trim().toLowerCase();
|
||||
const label = object ? `the ${object}` : 'it';
|
||||
const cleanedOutput = zorkOutput
|
||||
const cleanedOutput = zcodeOutput
|
||||
.split('\n')
|
||||
.filter((line, index) => index !== 0 || line.trim().toUpperCase() !== command.trim().toUpperCase())
|
||||
.join('\n')
|
||||
@@ -198,9 +198,9 @@ function evolveWeather(previous, turnCount) {
|
||||
return transitions[Math.floor(turnCount / 9) % transitions.length];
|
||||
}
|
||||
// ---------------------------------------------------------------------------
|
||||
// ZorkProcess – manages the ifvms zvm child process
|
||||
// ZcodeProcess – manages the ifvms zvm child process
|
||||
// ---------------------------------------------------------------------------
|
||||
class ZorkProcess {
|
||||
class ZcodeProcess {
|
||||
constructor() {
|
||||
this.proc = null;
|
||||
this.outputBuffer = '';
|
||||
@@ -279,7 +279,7 @@ class ZorkProcess {
|
||||
this.scheduleResolve();
|
||||
});
|
||||
}
|
||||
/** Debounced check: resolve when the buffer ends with Zork's '>' prompt. */
|
||||
/** Debounced check: resolve when the buffer ends with a Z-machine prompt. */
|
||||
scheduleResolve() {
|
||||
if (!/\n>\s*$/.test(this.outputBuffer))
|
||||
return;
|
||||
@@ -334,23 +334,23 @@ function renderTemplate(template, vars) {
|
||||
function logLlmError(scope, err) {
|
||||
if (axios_1.default.isAxiosError(err)) {
|
||||
const ax = err;
|
||||
console.error(`[ZorkLlm] ${scope} failed: ${ax.message}`);
|
||||
console.error(`[ZcodeLlm] ${scope} failed: ${ax.message}`);
|
||||
if (ax.response) {
|
||||
console.error(`[ZorkLlm] ${scope} status=${ax.response.status} data=`, ax.response.data);
|
||||
console.error(`[ZcodeLlm] ${scope} status=${ax.response.status} data=`, ax.response.data);
|
||||
if (ax.response.status === 404) {
|
||||
console.error('[ZorkLlm] Hint: OPENROUTER_MODEL is likely invalid or unavailable for your API key.');
|
||||
console.error('[ZcodeLlm] Hint: OPENROUTER_MODEL is likely invalid or unavailable for your API key.');
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
console.error(`[ZorkLlm] ${scope} failed:`, err);
|
||||
console.error(`[ZcodeLlm] ${scope} failed:`, err);
|
||||
}
|
||||
// ---------------------------------------------------------------------------
|
||||
// ZorkLlmEngine
|
||||
// ZcodeLlmEngine
|
||||
// ---------------------------------------------------------------------------
|
||||
class ZorkLlmEngine {
|
||||
class ZcodeLlmEngine {
|
||||
constructor(options = {}) {
|
||||
this.zork = new ZorkProcess();
|
||||
this.zmachine = new ZcodeProcess();
|
||||
this.session = null;
|
||||
this.resolvedFallbackModel = null;
|
||||
this.llmCallCounter = 0;
|
||||
@@ -360,10 +360,10 @@ class ZorkLlmEngine {
|
||||
if (!apiKey || !model) {
|
||||
throw new Error('Missing required environment variables: OPENROUTER_API_KEY and OPENROUTER_MODEL');
|
||||
}
|
||||
const replacement = ZorkLlmEngine.DEPRECATED_MODEL_REPLACEMENTS[model] ?? null;
|
||||
const replacement = ZcodeLlmEngine.DEPRECATED_MODEL_REPLACEMENTS[model] ?? null;
|
||||
if (replacement) {
|
||||
this.model = replacement;
|
||||
console.warn(`[ZorkLlm] Replacing deprecated model '${model}' with '${replacement}'.`);
|
||||
console.warn(`[ZcodeLlm] Replacing deprecated model '${model}' with '${replacement}'.`);
|
||||
}
|
||||
else {
|
||||
this.model = model;
|
||||
@@ -372,10 +372,10 @@ class ZorkLlmEngine {
|
||||
requestedModel: model,
|
||||
activeModel: this.model,
|
||||
});
|
||||
this.maxRetries = parseInt(process.env.ZORK_MAX_RETRIES ?? '3', 10);
|
||||
this.historySize = parseInt(process.env.ZORK_HISTORY_SIZE ?? '5', 10);
|
||||
this.storyPath = path.resolve(options.storyPath ?? process.env.ZORK_STORY_FILE ?? './data/z-code/zork1.bin');
|
||||
const promptDir = path.resolve(options.promptDir ?? './data/zork-prompts');
|
||||
this.maxRetries = parseInt(process.env.ZCODE_MAX_RETRIES ?? '3', 10);
|
||||
this.historySize = parseInt(process.env.ZCODE_HISTORY_SIZE ?? '5', 10);
|
||||
this.storyPath = path.resolve(options.storyPath ?? process.env.ZCODE_STORY_FILE ?? './data/z-code/zork1.bin');
|
||||
const promptDir = path.resolve(options.promptDir ?? './data/zcode-prompts');
|
||||
this.prompts = loadPrompts(promptDir);
|
||||
this.llm = axios_1.default.create({
|
||||
baseURL: 'https://openrouter.ai/api/v1',
|
||||
@@ -408,7 +408,7 @@ class ZorkLlmEngine {
|
||||
if (axios_1.default.isAxiosError(err) && err.response?.status === 404) {
|
||||
const fallbackModel = await this.resolveFallbackModel();
|
||||
this.model = fallbackModel;
|
||||
console.warn(`[ZorkLlm] Switching active model to '${fallbackModel}'.`);
|
||||
console.warn(`[ZcodeLlm] Switching active model to '${fallbackModel}'.`);
|
||||
const withFallbackModel = {
|
||||
...withReasoningDefaults(payload, fallbackModel),
|
||||
model: fallbackModel,
|
||||
@@ -478,23 +478,23 @@ class ZorkLlmEngine {
|
||||
}
|
||||
// ---- Public API -----------------------------------------------------------
|
||||
isRunning() {
|
||||
return this.session?.running === true && this.zork.isAlive();
|
||||
return this.session?.running === true && this.zmachine.isAlive();
|
||||
}
|
||||
/**
|
||||
* Start a new game: launch Zork, generate the player character, rewrite the
|
||||
* Start a new game: launch the Z-machine story, generate the player character, rewrite the
|
||||
* intro text, and return the first TurnResult for the client.
|
||||
*/
|
||||
async newGame() {
|
||||
// Kill any existing game
|
||||
if (this.zork.isAlive())
|
||||
this.zork.kill();
|
||||
if (this.zmachine.isAlive())
|
||||
this.zmachine.kill();
|
||||
this.nextTurnId = 1;
|
||||
if (!fs.existsSync(this.storyPath)) {
|
||||
throw new Error(`Story file not found: ${this.storyPath}\n` +
|
||||
'Place zork1.bin in ./data/z-code/ (see README in that folder).');
|
||||
}
|
||||
debugLog('launching Z-machine', { storyPath: this.storyPath });
|
||||
const rawIntro = await this.zork.launch(this.storyPath);
|
||||
const rawIntro = await this.zmachine.launch(this.storyPath);
|
||||
debugLog('Z-machine intro output', compactText(rawIntro));
|
||||
// Generate the player character before showing any text
|
||||
const characterDescription = await this.generateCharacter();
|
||||
@@ -555,7 +555,7 @@ class ZorkLlmEngine {
|
||||
for (const tool of cmdResponse.tools) {
|
||||
this.executeTool(tool);
|
||||
}
|
||||
// If the translator also supplied a Zork command, continue to game loop
|
||||
// If the translator also supplied a Z-machine command, continue to game loop
|
||||
if (!cmdResponse.command && !cmdResponse.commands?.length) {
|
||||
// Pure tool action — generate a brief acknowledgement via the rewriter
|
||||
const ack = await this.rewriteText(`(The narrator pauses. ${userInput})`);
|
||||
@@ -593,16 +593,16 @@ class ZorkLlmEngine {
|
||||
async saveGame() {
|
||||
if (!this.session)
|
||||
throw new Error('No active session to save');
|
||||
const tmpFile = path.join(os.tmpdir(), `zork-save-${Date.now()}.qzl`);
|
||||
const tmpFile = path.join(os.tmpdir(), `zcode-save-${Date.now()}.qzl`);
|
||||
try {
|
||||
// Ask Zork to save, supply the temp file path, and discard the output
|
||||
await this.zork.sendLine('SAVE');
|
||||
await this.zork.sendLine(tmpFile);
|
||||
let zorkSave = '';
|
||||
// Ask the Z-machine to save, supply the temp file path, and discard the output
|
||||
await this.zmachine.sendLine('SAVE');
|
||||
await this.zmachine.sendLine(tmpFile);
|
||||
let zcodeSave = '';
|
||||
if (fs.existsSync(tmpFile)) {
|
||||
zorkSave = fs.readFileSync(tmpFile).toString('base64');
|
||||
zcodeSave = fs.readFileSync(tmpFile).toString('base64');
|
||||
}
|
||||
return JSON.stringify({ session: this.session, zorkSave });
|
||||
return JSON.stringify({ session: this.session, zcodeSave });
|
||||
}
|
||||
finally {
|
||||
if (fs.existsSync(tmpFile))
|
||||
@@ -614,15 +614,15 @@ class ZorkLlmEngine {
|
||||
*/
|
||||
async loadGame(savedJson) {
|
||||
var _a, _b, _c, _d, _e, _f;
|
||||
const { session, zorkSave } = JSON.parse(savedJson);
|
||||
if (this.zork.isAlive())
|
||||
this.zork.kill();
|
||||
const tmpFile = path.join(os.tmpdir(), `zork-restore-${Date.now()}.qzl`);
|
||||
const { session, zcodeSave } = JSON.parse(savedJson);
|
||||
if (this.zmachine.isAlive())
|
||||
this.zmachine.kill();
|
||||
const tmpFile = path.join(os.tmpdir(), `zcode-restore-${Date.now()}.qzl`);
|
||||
try {
|
||||
fs.writeFileSync(tmpFile, Buffer.from(zorkSave, 'base64'));
|
||||
await this.zork.launch(this.storyPath);
|
||||
await this.zork.sendLine('RESTORE');
|
||||
const restoreOutput = await this.zork.sendLine(tmpFile);
|
||||
fs.writeFileSync(tmpFile, Buffer.from(zcodeSave, 'base64'));
|
||||
await this.zmachine.launch(this.storyPath);
|
||||
await this.zmachine.sendLine('RESTORE');
|
||||
const restoreOutput = await this.zmachine.sendLine(tmpFile);
|
||||
this.session = { ...session, running: true };
|
||||
(_a = this.session).rawTranscript ?? (_a.rawTranscript = []);
|
||||
(_b = this.session).recentParagraphs ?? (_b.recentParagraphs = []);
|
||||
@@ -650,7 +650,7 @@ class ZorkLlmEngine {
|
||||
attempt,
|
||||
maxRetries: this.maxRetries,
|
||||
});
|
||||
const rawOutput = await this.zork.sendLine(command);
|
||||
const rawOutput = await this.zmachine.sendLine(command);
|
||||
lastOutput = rawOutput;
|
||||
this.appendRawTranscript(command, rawOutput);
|
||||
debugLog('received Z-machine output', {
|
||||
@@ -714,10 +714,10 @@ class ZorkLlmEngine {
|
||||
return 'You are a wary but curious explorer, driven more by persistence than bravery. You have come to the old house seeking answers, carrying a notebook of unfinished questions and a habit of checking every corner twice.';
|
||||
}
|
||||
}
|
||||
async rewriteText(zorkOutput) {
|
||||
async rewriteText(zcodeOutput) {
|
||||
const cfg = this.prompts.textRewriter;
|
||||
const vars = this.buildCommonVars();
|
||||
vars['zorkOutput'] = zorkOutput;
|
||||
vars['zcodeOutput'] = zcodeOutput;
|
||||
try {
|
||||
const response = await this.createCompletion({
|
||||
messages: [
|
||||
@@ -731,7 +731,7 @@ class ZorkLlmEngine {
|
||||
}
|
||||
catch (err) {
|
||||
logLlmError('rewriteText', err);
|
||||
return zorkOutput;
|
||||
return zcodeOutput;
|
||||
}
|
||||
}
|
||||
async translateCommand(userInput) {
|
||||
@@ -753,16 +753,16 @@ class ZorkLlmEngine {
|
||||
}
|
||||
catch (err) {
|
||||
logLlmError('translateCommand', err);
|
||||
// Fallback: pass input directly to Zork parser
|
||||
// Fallback: pass input directly to Z-machine parser
|
||||
return { type: 'command', command: userInput.toUpperCase() };
|
||||
}
|
||||
}
|
||||
async evaluateOutput(userIntent, commandTried, zorkOutput, attempt) {
|
||||
async evaluateOutput(userIntent, commandTried, zcodeOutput, attempt) {
|
||||
const cfg = this.prompts.outputEvaluator;
|
||||
const vars = this.buildCommonVars();
|
||||
vars['userIntent'] = userIntent;
|
||||
vars['commandTried'] = commandTried;
|
||||
vars['zorkOutput'] = zorkOutput;
|
||||
vars['zcodeOutput'] = zcodeOutput;
|
||||
vars['attempt'] = String(attempt);
|
||||
vars['maxAttempts'] = String(this.maxRetries);
|
||||
try {
|
||||
@@ -780,7 +780,7 @@ class ZorkLlmEngine {
|
||||
catch (err) {
|
||||
logLlmError('evaluateOutput', err);
|
||||
// Fallback: accept the raw output as-is
|
||||
return { decision: 'accept', text: zorkOutput };
|
||||
return { decision: 'accept', text: zcodeOutput };
|
||||
}
|
||||
}
|
||||
// ---- Session helpers -------------------------------------------------------
|
||||
@@ -968,7 +968,7 @@ class ZorkLlmEngine {
|
||||
};
|
||||
}
|
||||
buildTurnResult(text) {
|
||||
const alive = this.zork.isAlive();
|
||||
const alive = this.zmachine.isAlive();
|
||||
if (!alive && this.session)
|
||||
this.session.running = false;
|
||||
const paragraphs = (0, turn_result_1.textToParagraphs)(text);
|
||||
@@ -981,9 +981,9 @@ class ZorkLlmEngine {
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.ZorkLlmEngine = ZorkLlmEngine;
|
||||
ZorkLlmEngine.DEPRECATED_MODEL_REPLACEMENTS = {
|
||||
exports.ZcodeLlmEngine = ZcodeLlmEngine;
|
||||
ZcodeLlmEngine.DEPRECATED_MODEL_REPLACEMENTS = {
|
||||
'anthropic/claude-3-opus-20240229': 'openai/gpt-5.5',
|
||||
'openai/gpt-5.4-mini': 'openai/gpt-5.5',
|
||||
};
|
||||
//# sourceMappingURL=zork-llm-engine.js.map
|
||||
//# sourceMappingURL=zcode-llm-engine.js.map
|
||||
Vendored
+1
File diff suppressed because one or more lines are too long
Vendored
-1
File diff suppressed because one or more lines are too long
Vendored
+5
-5
@@ -38,8 +38,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const dotenv = __importStar(require("dotenv"));
|
||||
const game_runner_1 = require("./cli/game-runner");
|
||||
// Import the server module and the startServer function for the web interface
|
||||
const server_1 = require("./server");
|
||||
// YAML CLI entry point. The web default is selected by scripts/run-engine.js.
|
||||
const server_yaml_1 = require("./server-yaml");
|
||||
const game_config_1 = require("./config/game-config");
|
||||
// Load environment variables
|
||||
console.log('Loading environment variables...');
|
||||
@@ -64,8 +64,8 @@ async function main() {
|
||||
const engineConfig = (0, game_config_1.loadGameConfig)(process.env.YAML_CONFIG_FILE || './config/engines/yaml.json', 'yaml');
|
||||
const worldFile = (0, game_config_1.projectPath)(process.env.DEFAULT_WORLD_FILE || engineConfig.paths.mainGameFile);
|
||||
console.log(`Using world file: ${worldFile}`);
|
||||
console.log(`OpenRouter API Key: ${process.env.OPENROUTER_API_KEY ? '✓ Found' : '✗ Missing'}`);
|
||||
console.log(`OpenRouter Model: ${process.env.OPENROUTER_MODEL || '✗ Not specified'}`);
|
||||
console.log(`OpenRouter API Key: ${process.env.OPENROUTER_API_KEY ? 'Found' : 'Missing'}`);
|
||||
console.log(`OpenRouter Model: ${process.env.OPENROUTER_MODEL || 'Not specified'}`);
|
||||
// Check if we should run in CLI mode
|
||||
const args = process.argv.slice(2);
|
||||
const cliMode = args.includes('--cli') || args.includes('-c');
|
||||
@@ -90,7 +90,7 @@ async function main() {
|
||||
const PORT_RANGE = 300;
|
||||
// Start the web server with port fallback
|
||||
console.log('Starting web server...');
|
||||
await (0, server_1.startServer)(PORT, PORT_RANGE);
|
||||
await (0, server_yaml_1.startServer)(PORT, PORT_RANGE);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,+CAAiC;AACjC,mDAA+C;AAC/C,8EAA8E;AAC9E,qCAAuC;AACvC,sDAAmE;AAEnE,6BAA6B;AAC7B,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;AAChD,IAAI,CAAC;IACH,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;IAC/B,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1D,CAAC;SAAM,CAAC;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,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC;YAC1E,MAAM,UAAU,GAAG,GAAG,CAAC;YAEvB,0CAA0C;YAC1C,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;YACtC,MAAM,IAAA,yBAAW,EAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;QACzC,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,OAAO,CAAC,KAAK,CAAC,aAAa,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;YACzC,OAAO,CAAC,KAAK,CAAC,gBAAgB,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;YAC/C,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,wBAAwB;AACxB,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AACvC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC;IACjD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
||||
Vendored
+1
-1
@@ -305,4 +305,4 @@ if (require.main === module) {
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=server.js.map
|
||||
//# sourceMappingURL=server-yaml.js.map
|
||||
Vendored
+1
File diff suppressed because one or more lines are too long
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Z-code LLM Server
|
||||
*
|
||||
* Starts an Express + Socket.IO server that runs Zork I through the
|
||||
* ZcodeLlmEngine and serves the same shared client UI as the YAML engine.
|
||||
*
|
||||
* Usage:
|
||||
* npm run dev:zcode (development, with file watching)
|
||||
* npm run start:zcode (production, from compiled dist/)
|
||||
*
|
||||
* Environment variables:
|
||||
* PORT – HTTP port (default: 3002)
|
||||
* ZCODE_STORY_FILE – path to the story file (default: ./data/z-code/zork1.bin)
|
||||
* OPENROUTER_API_KEY, OPENROUTER_MODEL – required
|
||||
*/
|
||||
export {};
|
||||
+28
-28
@@ -1,17 +1,17 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Zork LLM Server
|
||||
* Z-code LLM Server
|
||||
*
|
||||
* Starts an Express + Socket.IO server that runs Zork I through the
|
||||
* ZorkLlmEngine and serves the same shared client UI as the YAML engine.
|
||||
* ZcodeLlmEngine and serves the same shared client UI as the YAML engine.
|
||||
*
|
||||
* Usage:
|
||||
* npm run dev:zork (development, with file watching)
|
||||
* npm run start:zork (production, from compiled dist/)
|
||||
* npm run dev:zcode (development, with file watching)
|
||||
* npm run start:zcode (production, from compiled dist/)
|
||||
*
|
||||
* Environment variables:
|
||||
* PORT – HTTP port (default: 3002)
|
||||
* ZORK_STORY_FILE – path to the story file (default: ./data/z-code/zork1.bin)
|
||||
* ZCODE_STORY_FILE – path to the story file (default: ./data/z-code/zork1.bin)
|
||||
* OPENROUTER_API_KEY, OPENROUTER_MODEL – required
|
||||
*/
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
@@ -57,7 +57,7 @@ const express_1 = __importDefault(require("express"));
|
||||
const socket_io_1 = require("socket.io");
|
||||
const dotenv = __importStar(require("dotenv"));
|
||||
const fs_1 = require("fs");
|
||||
const zork_llm_engine_1 = require("./engine/zork-llm-engine");
|
||||
const zcode_llm_engine_1 = require("./engine/zcode-llm-engine");
|
||||
const game_config_1 = require("./config/game-config");
|
||||
dotenv.config();
|
||||
const app = (0, express_1.default)();
|
||||
@@ -66,16 +66,16 @@ const io = new socket_io_1.Server(server);
|
||||
const DEFAULT_PORT = 3002;
|
||||
const PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : DEFAULT_PORT;
|
||||
const PORT_RANGE = 300;
|
||||
const DEBUG_ENABLED = /^(1|true|yes|on)$/i.test(process.env.ZORK_DEBUG ?? '');
|
||||
const engineConfig = (0, game_config_1.loadGameConfig)(process.env.ZORK_CONFIG_FILE || './config/engines/zork.json', 'zork');
|
||||
const DEBUG_ENABLED = /^(1|true|yes|on)$/i.test(process.env.ZCODE_DEBUG ?? '');
|
||||
const engineConfig = (0, game_config_1.loadGameConfig)(process.env.ZCODE_CONFIG_FILE || './config/engines/zcode.json', 'zcode');
|
||||
function debugLog(message, details) {
|
||||
if (!DEBUG_ENABLED)
|
||||
return;
|
||||
if (typeof details === 'undefined') {
|
||||
console.log(`[zork:debug] ${message}`);
|
||||
console.log(`[zcode:debug] ${message}`);
|
||||
return;
|
||||
}
|
||||
console.log(`[zork:debug] ${message}`, details);
|
||||
console.log(`[zcode:debug] ${message}`, details);
|
||||
}
|
||||
// Serve the same shared client UI
|
||||
app.use(express_1.default.static(path_1.default.join(__dirname, '../public'), {
|
||||
@@ -111,9 +111,9 @@ function normalizeSaveSlot(slot) {
|
||||
function getOrCreateEngine(socketId) {
|
||||
let engine = sessions.get(socketId);
|
||||
if (!engine) {
|
||||
engine = new zork_llm_engine_1.ZorkLlmEngine({
|
||||
storyPath: (0, game_config_1.projectPath)(process.env.ZORK_STORY_FILE || engineConfig.paths.mainGameFile),
|
||||
promptDir: (0, game_config_1.projectPath)(engineConfig.paths.promptDir || 'data/zork-prompts'),
|
||||
engine = new zcode_llm_engine_1.ZcodeLlmEngine({
|
||||
storyPath: (0, game_config_1.projectPath)(process.env.ZCODE_STORY_FILE || engineConfig.paths.mainGameFile),
|
||||
promptDir: (0, game_config_1.projectPath)(engineConfig.paths.promptDir || 'data/zcode-prompts'),
|
||||
});
|
||||
sessions.set(socketId, engine);
|
||||
}
|
||||
@@ -189,8 +189,8 @@ async function handleGameApi(socket, method, args) {
|
||||
}
|
||||
}
|
||||
function checkRuntimeConfiguration() {
|
||||
const storyPath = (0, game_config_1.projectPath)(process.env.ZORK_STORY_FILE ?? engineConfig.paths.mainGameFile);
|
||||
const promptDir = (0, game_config_1.projectPath)(engineConfig.paths.promptDir || 'data/zork-prompts');
|
||||
const storyPath = (0, game_config_1.projectPath)(process.env.ZCODE_STORY_FILE ?? engineConfig.paths.mainGameFile);
|
||||
const promptDir = (0, game_config_1.projectPath)(engineConfig.paths.promptDir || 'data/zcode-prompts');
|
||||
const promptFiles = [
|
||||
'character-generation.yml',
|
||||
'text-rewriter.yml',
|
||||
@@ -201,17 +201,17 @@ function checkRuntimeConfiguration() {
|
||||
.map((file) => path_1.default.join(promptDir, file))
|
||||
.filter((filePath) => !(0, fs_1.existsSync)(filePath));
|
||||
if (!process.env.OPENROUTER_API_KEY) {
|
||||
console.error('[zork] Missing OPENROUTER_API_KEY in environment.');
|
||||
console.error('[zcode] Missing OPENROUTER_API_KEY in environment.');
|
||||
}
|
||||
if (!process.env.OPENROUTER_MODEL) {
|
||||
console.error('[zork] Missing OPENROUTER_MODEL in environment.');
|
||||
console.error('[zcode] Missing OPENROUTER_MODEL in environment.');
|
||||
}
|
||||
if (!(0, fs_1.existsSync)(storyPath)) {
|
||||
console.error(`[zork] Story file missing: ${storyPath}`);
|
||||
console.error('[zork] Place zork1.bin in ./data/z-code/ or set ZORK_STORY_FILE.');
|
||||
console.error(`[zcode] Story file missing: ${storyPath}`);
|
||||
console.error('[zcode] Place zork1.bin in ./data/z-code/ or set ZCODE_STORY_FILE.');
|
||||
}
|
||||
if (missingPrompts.length > 0) {
|
||||
console.error('[zork] Missing prompt files:');
|
||||
console.error('[zcode] Missing prompt files:');
|
||||
for (const filePath of missingPrompts) {
|
||||
console.error(` - ${filePath}`);
|
||||
}
|
||||
@@ -225,7 +225,7 @@ function checkRuntimeConfiguration() {
|
||||
});
|
||||
}
|
||||
io.on('connection', (socket) => {
|
||||
console.log(`[zork] Client connected: ${socket.id}`);
|
||||
console.log(`[zcode] Client connected: ${socket.id}`);
|
||||
socket.emit('gameConfig', (0, game_config_1.clientGameConfig)(engineConfig));
|
||||
socket.on('gameApi', async (request, respond) => {
|
||||
try {
|
||||
@@ -235,7 +235,7 @@ io.on('connection', (socket) => {
|
||||
respond(result);
|
||||
}
|
||||
catch (error) {
|
||||
console.error('[zork] gameApi error:', error);
|
||||
console.error('[zcode] gameApi error:', error);
|
||||
if (typeof respond === 'function') {
|
||||
respond({
|
||||
success: false,
|
||||
@@ -266,14 +266,14 @@ io.on('connection', (socket) => {
|
||||
socket.emit('narrativeResponse', toClientTurn(turn));
|
||||
}
|
||||
catch (error) {
|
||||
console.error('[zork] playerCommand error:', error);
|
||||
console.error('[zcode] playerCommand error:', error);
|
||||
socket.emit('error', {
|
||||
message: error instanceof Error ? error.message : 'An error occurred.',
|
||||
});
|
||||
}
|
||||
});
|
||||
socket.on('disconnect', () => {
|
||||
console.log(`[zork] Client disconnected: ${socket.id}`);
|
||||
console.log(`[zcode] Client disconnected: ${socket.id}`);
|
||||
sessions.delete(socket.id);
|
||||
saveSlots.delete(socket.id);
|
||||
});
|
||||
@@ -291,7 +291,7 @@ function ensureDirectories() {
|
||||
path_1.default.join(__dirname, '../public/sounds'),
|
||||
path_1.default.join(__dirname, '../public/fonts'),
|
||||
path_1.default.join(__dirname, '../data/z-code'),
|
||||
path_1.default.join(__dirname, '../data/zork-prompts'),
|
||||
path_1.default.join(__dirname, '../data/zcode-prompts'),
|
||||
];
|
||||
for (const dir of dirs) {
|
||||
if (!(0, fs_1.existsSync)(dir))
|
||||
@@ -319,7 +319,7 @@ async function startServer(initialPort, range) {
|
||||
server.removeAllListeners('error');
|
||||
server.removeAllListeners('listening');
|
||||
server.once('listening', () => {
|
||||
console.log(`[zork] Zork Narrator server running on http://localhost:${port}`);
|
||||
console.log(`[zcode] Z-code Narrator server running on http://localhost:${port}`);
|
||||
resolve();
|
||||
});
|
||||
server.once('error', (err) => {
|
||||
@@ -346,8 +346,8 @@ async function startServer(initialPort, range) {
|
||||
}
|
||||
if (require.main === module) {
|
||||
startServer(PORT, PORT_RANGE).catch((err) => {
|
||||
console.error('[zork] Failed to start:', err);
|
||||
console.error('[zcode] Failed to start:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=server-zork.js.map
|
||||
//# sourceMappingURL=server-zcode.js.map
|
||||
Vendored
+1
File diff suppressed because one or more lines are too long
Vendored
-16
@@ -1,16 +0,0 @@
|
||||
/**
|
||||
* Zork LLM Server
|
||||
*
|
||||
* Starts an Express + Socket.IO server that runs Zork I through the
|
||||
* ZorkLlmEngine and serves the same shared client UI as the YAML engine.
|
||||
*
|
||||
* Usage:
|
||||
* npm run dev:zork (development, with file watching)
|
||||
* npm run start:zork (production, from compiled dist/)
|
||||
*
|
||||
* Environment variables:
|
||||
* PORT – HTTP port (default: 3002)
|
||||
* ZORK_STORY_FILE – path to the story file (default: ./data/z-code/zork1.bin)
|
||||
* OPENROUTER_API_KEY, OPENROUTER_MODEL – required
|
||||
*/
|
||||
export {};
|
||||
Vendored
-1
File diff suppressed because one or more lines are too long
Vendored
-1
File diff suppressed because one or more lines are too long
+1
-1
@@ -279,4 +279,4 @@ if (require.main === module) {
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=test-server.js.map
|
||||
//# sourceMappingURL=test-server-yaml.js.map
|
||||
Vendored
+1
File diff suppressed because one or more lines are too long
Vendored
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user