feat: Integrate Kokoro TTS with WebGPU and fallback
This commit is contained in:
+55
-55
@@ -1,56 +1,56 @@
|
||||
/**
|
||||
* Interfaces for the game engine
|
||||
*/
|
||||
|
||||
import { WorldModel, GameState } from './world-model';
|
||||
import { ActionResponse, NarrativeResponse } from './llm';
|
||||
|
||||
export interface ActionResult {
|
||||
success: boolean;
|
||||
message: string;
|
||||
stateChanged: boolean;
|
||||
newState?: GameState;
|
||||
}
|
||||
|
||||
export interface GameEngine {
|
||||
loadWorld(worldModelPath: string): Promise<void>;
|
||||
getCurrentState(): GameState;
|
||||
getWorldModel(): WorldModel;
|
||||
|
||||
// Action processing
|
||||
processAction(action: ActionResponse): ActionResult;
|
||||
|
||||
// State management
|
||||
saveGame(filename: string): Promise<void>;
|
||||
loadGame(filename: string): Promise<void>;
|
||||
|
||||
// Helper methods for world interaction
|
||||
getAvailableActions(): string[];
|
||||
getVisibleObjects(): string[];
|
||||
getVisibleCharacters(): string[];
|
||||
getCurrentRoomDescription(): string;
|
||||
|
||||
// Game flow
|
||||
start(): Promise<string>; // Returns introduction text
|
||||
end(): void;
|
||||
}
|
||||
|
||||
export interface GameSession {
|
||||
engine: GameEngine;
|
||||
history: {
|
||||
playerInput: string;
|
||||
actionResponse: ActionResponse;
|
||||
actionResult: ActionResult;
|
||||
narrativeResponse: NarrativeResponse;
|
||||
}[];
|
||||
startTime: Date;
|
||||
lastInteractionTime: Date;
|
||||
}
|
||||
|
||||
export interface ActionHandler {
|
||||
execute(
|
||||
gameState: GameState,
|
||||
worldModel: WorldModel,
|
||||
action: ActionResponse
|
||||
): ActionResult;
|
||||
/**
|
||||
* Interfaces for the game engine
|
||||
*/
|
||||
|
||||
import { WorldModel, GameState } from './world-model';
|
||||
import { ActionResponse, NarrativeResponse } from './llm';
|
||||
|
||||
export interface ActionResult {
|
||||
success: boolean;
|
||||
message: string;
|
||||
stateChanged: boolean;
|
||||
newState?: GameState;
|
||||
}
|
||||
|
||||
export interface GameEngine {
|
||||
loadWorld(worldModelPath: string): Promise<void>;
|
||||
getCurrentState(): GameState;
|
||||
getWorldModel(): WorldModel;
|
||||
|
||||
// Action processing
|
||||
processAction(action: ActionResponse): ActionResult;
|
||||
|
||||
// State management
|
||||
saveGame(filename: string): Promise<void>;
|
||||
loadGame(filename: string): Promise<void>;
|
||||
|
||||
// Helper methods for world interaction
|
||||
getAvailableActions(): string[];
|
||||
getVisibleObjects(): string[];
|
||||
getVisibleCharacters(): string[];
|
||||
getCurrentRoomDescription(): string;
|
||||
|
||||
// Game flow
|
||||
start(): Promise<string>; // Returns introduction text
|
||||
end(): void;
|
||||
}
|
||||
|
||||
export interface GameSession {
|
||||
engine: GameEngine;
|
||||
history: {
|
||||
playerInput: string;
|
||||
actionResponse: ActionResponse;
|
||||
actionResult: ActionResult;
|
||||
narrativeResponse: NarrativeResponse;
|
||||
}[];
|
||||
startTime: Date;
|
||||
lastInteractionTime: Date;
|
||||
}
|
||||
|
||||
export interface ActionHandler {
|
||||
execute(
|
||||
gameState: GameState,
|
||||
worldModel: WorldModel,
|
||||
action: ActionResponse
|
||||
): ActionResult;
|
||||
}
|
||||
+51
-51
@@ -1,52 +1,52 @@
|
||||
/**
|
||||
* Interfaces for LLM integration
|
||||
*/
|
||||
|
||||
export interface LlmConfig {
|
||||
apiKey: string;
|
||||
model: string;
|
||||
temperature?: number;
|
||||
maxTokens?: number;
|
||||
topP?: number;
|
||||
frequencyPenalty?: number;
|
||||
presencePenalty?: number;
|
||||
}
|
||||
|
||||
export interface ActionRequest {
|
||||
playerInput: string;
|
||||
currentRoom: string;
|
||||
visibleObjects: string[];
|
||||
visibleCharacters: string[];
|
||||
possibleActions: string[];
|
||||
inventory: string[];
|
||||
gameContext: string;
|
||||
}
|
||||
|
||||
export interface ActionResponse {
|
||||
action: string;
|
||||
object?: string;
|
||||
target?: string;
|
||||
parameters?: Record<string, string>;
|
||||
confidence: number;
|
||||
}
|
||||
|
||||
export interface NarrativeRequest {
|
||||
action: string;
|
||||
result: string;
|
||||
roomDescription: string;
|
||||
visibleObjects: string[];
|
||||
visibleCharacters: string[];
|
||||
previousContext?: string;
|
||||
tone?: string; // e.g., "mysterious", "humorous", "dramatic"
|
||||
}
|
||||
|
||||
export interface NarrativeResponse {
|
||||
text: string;
|
||||
suggestions?: string[]; // Optional hints for the player
|
||||
}
|
||||
|
||||
export interface LlmProvider {
|
||||
initialize(config: LlmConfig): Promise<void>;
|
||||
translateAction(request: ActionRequest): Promise<ActionResponse>;
|
||||
generateNarrative(request: NarrativeRequest): Promise<NarrativeResponse>;
|
||||
/**
|
||||
* Interfaces for LLM integration
|
||||
*/
|
||||
|
||||
export interface LlmConfig {
|
||||
apiKey: string;
|
||||
model: string;
|
||||
temperature?: number;
|
||||
maxTokens?: number;
|
||||
topP?: number;
|
||||
frequencyPenalty?: number;
|
||||
presencePenalty?: number;
|
||||
}
|
||||
|
||||
export interface ActionRequest {
|
||||
playerInput: string;
|
||||
currentRoom: string;
|
||||
visibleObjects: string[];
|
||||
visibleCharacters: string[];
|
||||
possibleActions: string[];
|
||||
inventory: string[];
|
||||
gameContext: string;
|
||||
}
|
||||
|
||||
export interface ActionResponse {
|
||||
action: string;
|
||||
object?: string;
|
||||
target?: string;
|
||||
parameters?: Record<string, string>;
|
||||
confidence: number;
|
||||
}
|
||||
|
||||
export interface NarrativeRequest {
|
||||
action: string;
|
||||
result: string;
|
||||
roomDescription: string;
|
||||
visibleObjects: string[];
|
||||
visibleCharacters: string[];
|
||||
previousContext?: string;
|
||||
tone?: string; // e.g., "mysterious", "humorous", "dramatic"
|
||||
}
|
||||
|
||||
export interface NarrativeResponse {
|
||||
text: string;
|
||||
suggestions?: string[]; // Optional hints for the player
|
||||
}
|
||||
|
||||
export interface LlmProvider {
|
||||
initialize(config: LlmConfig): Promise<void>;
|
||||
translateAction(request: ActionRequest): Promise<ActionResponse>;
|
||||
generateNarrative(request: NarrativeRequest): Promise<NarrativeResponse>;
|
||||
}
|
||||
@@ -1,68 +1,68 @@
|
||||
/**
|
||||
* Core interfaces for the interactive fiction world model
|
||||
*/
|
||||
|
||||
export interface Room {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
exits: Exit[];
|
||||
objects: string[]; // References to object IDs
|
||||
characters: string[]; // References to character IDs
|
||||
}
|
||||
|
||||
export interface Exit {
|
||||
direction: string;
|
||||
targetRoomId: string;
|
||||
description?: string;
|
||||
isLocked?: boolean;
|
||||
keyId?: string; // ID of the key object needed to unlock
|
||||
}
|
||||
|
||||
export interface GameObject {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
traits: string[]; // e.g., "takeable", "container", "edible"
|
||||
states: Record<string, boolean>; // e.g., { "open": false, "lit": true }
|
||||
containedObjects?: string[]; // IDs of objects inside if this is a container
|
||||
allowedActions: string[]; // What actions can be performed on this object
|
||||
}
|
||||
|
||||
export interface Character {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
dialogue: Record<string, string>; // Topic -> response mapping
|
||||
inventory: string[]; // IDs of objects the character has
|
||||
defaultResponse: string; // Response when topic not found
|
||||
mood?: string; // Current mood affecting responses
|
||||
}
|
||||
|
||||
export interface Action {
|
||||
name: string;
|
||||
patterns: string[]; // Example natural language patterns this action matches
|
||||
requiresObject?: boolean;
|
||||
requiresTarget?: boolean;
|
||||
handler: string; // Name of method to handle this action
|
||||
}
|
||||
|
||||
export interface GameState {
|
||||
currentRoomId: string;
|
||||
inventory: string[]; // IDs of objects in player's inventory
|
||||
visitedRooms: string[]; // IDs of rooms the player has visited
|
||||
flags: Record<string, boolean>; // Game state flags
|
||||
counters: Record<string, number>; // Game state counters
|
||||
}
|
||||
|
||||
export interface WorldModel {
|
||||
title: string;
|
||||
author: string;
|
||||
version: string;
|
||||
introduction: string;
|
||||
rooms: Record<string, Room>;
|
||||
objects: Record<string, GameObject>;
|
||||
characters: Record<string, Character>;
|
||||
actions: Record<string, Action>;
|
||||
initialState: GameState;
|
||||
/**
|
||||
* Core interfaces for the interactive fiction world model
|
||||
*/
|
||||
|
||||
export interface Room {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
exits: Exit[];
|
||||
objects: string[]; // References to object IDs
|
||||
characters: string[]; // References to character IDs
|
||||
}
|
||||
|
||||
export interface Exit {
|
||||
direction: string;
|
||||
targetRoomId: string;
|
||||
description?: string;
|
||||
isLocked?: boolean;
|
||||
keyId?: string; // ID of the key object needed to unlock
|
||||
}
|
||||
|
||||
export interface GameObject {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
traits: string[]; // e.g., "takeable", "container", "edible"
|
||||
states: Record<string, boolean>; // e.g., { "open": false, "lit": true }
|
||||
containedObjects?: string[]; // IDs of objects inside if this is a container
|
||||
allowedActions: string[]; // What actions can be performed on this object
|
||||
}
|
||||
|
||||
export interface Character {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
dialogue: Record<string, string>; // Topic -> response mapping
|
||||
inventory: string[]; // IDs of objects the character has
|
||||
defaultResponse: string; // Response when topic not found
|
||||
mood?: string; // Current mood affecting responses
|
||||
}
|
||||
|
||||
export interface Action {
|
||||
name: string;
|
||||
patterns: string[]; // Example natural language patterns this action matches
|
||||
requiresObject?: boolean;
|
||||
requiresTarget?: boolean;
|
||||
handler: string; // Name of method to handle this action
|
||||
}
|
||||
|
||||
export interface GameState {
|
||||
currentRoomId: string;
|
||||
inventory: string[]; // IDs of objects in player's inventory
|
||||
visitedRooms: string[]; // IDs of rooms the player has visited
|
||||
flags: Record<string, boolean>; // Game state flags
|
||||
counters: Record<string, number>; // Game state counters
|
||||
}
|
||||
|
||||
export interface WorldModel {
|
||||
title: string;
|
||||
author: string;
|
||||
version: string;
|
||||
introduction: string;
|
||||
rooms: Record<string, Room>;
|
||||
objects: Record<string, GameObject>;
|
||||
characters: Record<string, Character>;
|
||||
actions: Record<string, Action>;
|
||||
initialState: GameState;
|
||||
}
|
||||
Reference in New Issue
Block a user