trigo / trigo-web /backend /dist /inc /trigoAgent.d.ts
k-l-lambda's picture
Deploy: fix build by keeping pre-built dist folder
63a8db2
/**
* Trigo AI Agent - Language Model-based Move Selection (Frontend/Backend Common)
*
* Platform-agnostic AI agent that accepts ONNX session from platform-specific code.
* No direct dependency on onnxruntime packages - uses dependency injection pattern.
*
* Uses ONNX language model to score and select moves by:
* 1. Getting all valid moves for current position
* 2. Scoring each move by appending it to TGN and computing token probabilities
* 3. Selecting move with highest probability (argmax)
*/
import { ModelInferencer } from "./modelInferencer";
import { TrigoGame } from "./trigo/game";
import type { Move } from "./trigo/types";
/**
* Configuration for the AI agent
*/
export interface TrigoAgentConfig {
vocabSize?: number;
seqLen?: number;
temperature?: number;
}
/**
* Move score result
*/
export interface MoveScore {
move: Move;
score: number;
logProb: number;
}
/**
* Trigo AI Agent for move generation
* Compatible with both frontend (onnxruntime-web) and backend (onnxruntime-node)
*/
export declare class TrigoAgent {
private inferencer;
constructor(inferencer: ModelInferencer);
/**
* Check if agent is initialized (checks if inferencer has a session)
*/
isInitialized(): boolean;
/**
* Convert Stone type to player string
*/
private stoneToPlayer;
/**
* Convert string to token IDs (byte-level encoding with ASCII direct mapping)
* For characters 32-127, token_id = ascii_value
* Special tokens (0-3) and newline (10) are handled by the tokenizer
*/
private stringToTokens;
/**
* Compute softmax probabilities from logits
*/
private softmax;
/**
* Score a candidate move by computing token probabilities
*
* Clones the game, applies the move, generates new TGN, and computes
* the probability of the move tokens.
*/
scoreMove(game: TrigoGame, move: Move): Promise<number>;
/**
* Extract move tokens from TGN difference
* Returns the tokens that were added between currentTGN and newTGN
*/
private extractMoveTokens;
/**
* Select the best move using the language model
*
* Scores all valid moves and returns the one with highest probability (argmax).
*/
selectBestMove(game: TrigoGame): Promise<Move | null>;
/**
* Clean up resources
*/
destroy(): void;
}
//# sourceMappingURL=trigoAgent.d.ts.map