theref-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +326 -0
- package/README.md:Zone.Identifier +0 -0
- package/dist/index.d.mts +229 -0
- package/dist/index.d.ts +229 -0
- package/dist/index.js +634 -0
- package/dist/index.mjs +602 -0
- package/package.json +36 -0
- package/package.json:Zone.Identifier +0 -0
- package/src/adapters/normalizer.ts +252 -0
- package/src/adapters/normalizer.ts:Zone.Identifier +0 -0
- package/src/client/TheRefClient.ts +444 -0
- package/src/client/TheRefClient.ts:Zone.Identifier +0 -0
- package/src/index.ts +56 -0
- package/src/index.ts:Zone.Identifier +0 -0
- package/src/types/index.ts +149 -0
- package/src/types/index.ts:Zone.Identifier +0 -0
- package/src/utils/networks.ts +39 -0
- package/src/utils/networks.ts:Zone.Identifier +0 -0
- package/tsconfig.json +16 -0
- package/tsconfig.json:Zone.Identifier +0 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
type NetworkId = "bradbury" | "studionet";
|
|
2
|
+
interface NetworkConfig {
|
|
3
|
+
id: NetworkId;
|
|
4
|
+
rpc: string;
|
|
5
|
+
chainId: number;
|
|
6
|
+
addresses: ContractAddresses;
|
|
7
|
+
}
|
|
8
|
+
interface ContractAddresses {
|
|
9
|
+
CORE: string;
|
|
10
|
+
LB: string;
|
|
11
|
+
ORG: string;
|
|
12
|
+
FEE: string;
|
|
13
|
+
TRN: string;
|
|
14
|
+
}
|
|
15
|
+
interface TheRefConfig {
|
|
16
|
+
network: NetworkId | NetworkConfig;
|
|
17
|
+
privateKey?: `0x${string}`;
|
|
18
|
+
walletAddress?: `0x${string}`;
|
|
19
|
+
wsUrl?: string;
|
|
20
|
+
retries?: number;
|
|
21
|
+
pollInterval?: number;
|
|
22
|
+
}
|
|
23
|
+
type GameStatus = "waiting" | "active" | "completed" | "draw";
|
|
24
|
+
type PlayerType = "human" | "agent";
|
|
25
|
+
interface CreateGameOptions {
|
|
26
|
+
name: string;
|
|
27
|
+
rules?: string;
|
|
28
|
+
player1: string;
|
|
29
|
+
player2?: string;
|
|
30
|
+
maxRounds?: number;
|
|
31
|
+
visibility?: "public" | "private";
|
|
32
|
+
agent1?: `0x${string}`;
|
|
33
|
+
agent2?: `0x${string}`;
|
|
34
|
+
}
|
|
35
|
+
interface GameState {
|
|
36
|
+
gameId: string;
|
|
37
|
+
gameName: string;
|
|
38
|
+
status: GameStatus;
|
|
39
|
+
player1: string;
|
|
40
|
+
player2: string;
|
|
41
|
+
agent1: string;
|
|
42
|
+
agent2: string;
|
|
43
|
+
maxRounds: number;
|
|
44
|
+
roundCount: number;
|
|
45
|
+
judgedThrough: number;
|
|
46
|
+
rules: string;
|
|
47
|
+
winner: string;
|
|
48
|
+
score: Record<string, number>;
|
|
49
|
+
playerTypes: Record<string, PlayerType>;
|
|
50
|
+
rounds: RoundResult[];
|
|
51
|
+
caller: string;
|
|
52
|
+
}
|
|
53
|
+
interface RoundResult {
|
|
54
|
+
roundNumber: number;
|
|
55
|
+
movePlayer1: string;
|
|
56
|
+
movePlayer2: string;
|
|
57
|
+
result: "player1" | "player2" | "draw" | "pending";
|
|
58
|
+
reasonType: "normal" | "invalid_move";
|
|
59
|
+
invalidPlayer: "none" | "player1" | "player2";
|
|
60
|
+
reasoning: string;
|
|
61
|
+
confidence: number;
|
|
62
|
+
status: string;
|
|
63
|
+
}
|
|
64
|
+
interface JudgmentResult {
|
|
65
|
+
winner: string;
|
|
66
|
+
isDraw: boolean;
|
|
67
|
+
score: Record<string, number>;
|
|
68
|
+
rounds: RoundResult[];
|
|
69
|
+
txHash: string;
|
|
70
|
+
payload: string;
|
|
71
|
+
}
|
|
72
|
+
type AnyMove = string | number | boolean | AnyMove[] | {
|
|
73
|
+
[key: string]: AnyMove;
|
|
74
|
+
};
|
|
75
|
+
interface NormalizedMove {
|
|
76
|
+
raw: AnyMove;
|
|
77
|
+
text: string;
|
|
78
|
+
adapter: string;
|
|
79
|
+
}
|
|
80
|
+
interface CreateTournamentOptions {
|
|
81
|
+
name: string;
|
|
82
|
+
gameName: string;
|
|
83
|
+
format: "single_elimination" | "round_robin" | "swiss";
|
|
84
|
+
maxPlayers: number;
|
|
85
|
+
rules?: string;
|
|
86
|
+
roundsPerMatch?: number;
|
|
87
|
+
prizeSplit?: number[];
|
|
88
|
+
}
|
|
89
|
+
interface Tournament {
|
|
90
|
+
tid: string;
|
|
91
|
+
name: string;
|
|
92
|
+
gameName: string;
|
|
93
|
+
format: string;
|
|
94
|
+
maxPlayers: number;
|
|
95
|
+
status: string;
|
|
96
|
+
players: string[];
|
|
97
|
+
bracket: BracketMatch[];
|
|
98
|
+
winner: string;
|
|
99
|
+
}
|
|
100
|
+
interface BracketMatch {
|
|
101
|
+
matchId: number;
|
|
102
|
+
round: number;
|
|
103
|
+
player1: string;
|
|
104
|
+
player2: string;
|
|
105
|
+
gameId: string;
|
|
106
|
+
winner: string;
|
|
107
|
+
status: string;
|
|
108
|
+
}
|
|
109
|
+
interface LeaderboardEntry {
|
|
110
|
+
player: string;
|
|
111
|
+
wins: number;
|
|
112
|
+
losses: number;
|
|
113
|
+
draws: number;
|
|
114
|
+
score: number;
|
|
115
|
+
playerType: PlayerType;
|
|
116
|
+
}
|
|
117
|
+
interface PlayerStats extends LeaderboardEntry {
|
|
118
|
+
games: number;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
declare class TheRefClient {
|
|
122
|
+
private network;
|
|
123
|
+
private glClient;
|
|
124
|
+
private retries;
|
|
125
|
+
private pollInterval;
|
|
126
|
+
private wsUrl;
|
|
127
|
+
constructor(config: TheRefConfig);
|
|
128
|
+
private write;
|
|
129
|
+
private read;
|
|
130
|
+
private get CORE();
|
|
131
|
+
private get LB();
|
|
132
|
+
private get TRN();
|
|
133
|
+
private mapGameState;
|
|
134
|
+
/**
|
|
135
|
+
* Create a new game. Returns the game ID.
|
|
136
|
+
*/
|
|
137
|
+
createGame(options: CreateGameOptions): Promise<string>;
|
|
138
|
+
/**
|
|
139
|
+
* Submit a move for a player. Accepts ANY move format — string, object, array, etc.
|
|
140
|
+
* The SDK automatically normalizes it to a string the AI judge can understand.
|
|
141
|
+
*/
|
|
142
|
+
submitMove(gameId: string, playerName: string, move: AnyMove, gameHint?: string): Promise<{
|
|
143
|
+
txHash: string;
|
|
144
|
+
normalizedMove: string;
|
|
145
|
+
}>;
|
|
146
|
+
/**
|
|
147
|
+
* Judge the game — triggers AI consensus on all pending rounds.
|
|
148
|
+
*/
|
|
149
|
+
judgeGame(gameId: string): Promise<JudgmentResult>;
|
|
150
|
+
/**
|
|
151
|
+
* End an open-ended game (max_rounds = 0). Only callable by the game creator.
|
|
152
|
+
*/
|
|
153
|
+
endGame(gameId: string): Promise<JudgmentResult>;
|
|
154
|
+
/**
|
|
155
|
+
* Get the full game state.
|
|
156
|
+
*/
|
|
157
|
+
getGameState(gameId: string): Promise<GameState>;
|
|
158
|
+
/**
|
|
159
|
+
* Get all active games.
|
|
160
|
+
*/
|
|
161
|
+
getActiveGames(): Promise<GameState[]>;
|
|
162
|
+
/**
|
|
163
|
+
* Get total number of games.
|
|
164
|
+
*/
|
|
165
|
+
getTotalGames(): Promise<number>;
|
|
166
|
+
/**
|
|
167
|
+
* Wait until both players have submitted their move for a given round.
|
|
168
|
+
* Polls every `pollInterval` ms.
|
|
169
|
+
*/
|
|
170
|
+
waitForBothMoves(gameId: string, roundNumber: number): Promise<RoundResult>;
|
|
171
|
+
/**
|
|
172
|
+
* Wait until the opponent has submitted their move for a round.
|
|
173
|
+
* isPlayer1: true if you are player1, false if player2.
|
|
174
|
+
*/
|
|
175
|
+
waitForOpponentMove(gameId: string, roundNumber: number, isPlayer1: boolean): Promise<string>;
|
|
176
|
+
/**
|
|
177
|
+
* Wait until the game reaches a specific status.
|
|
178
|
+
*/
|
|
179
|
+
waitForStatus(gameId: string, status: GameStatus): Promise<GameState>;
|
|
180
|
+
/**
|
|
181
|
+
* Play a full game automatically.
|
|
182
|
+
* moveFn is called for each round — return your move in any format.
|
|
183
|
+
*/
|
|
184
|
+
playGame(gameId: string, playerName: string, isPlayer1: boolean, moveFn: (state: GameState, round: number) => Promise<AnyMove>, gameHint?: string): Promise<JudgmentResult>;
|
|
185
|
+
getLeaderboard(gameName: string, playerType?: PlayerType | "all"): Promise<LeaderboardEntry[]>;
|
|
186
|
+
getTopPlayers(gameName: string, n?: number): Promise<LeaderboardEntry[]>;
|
|
187
|
+
getPlayerStats(gameName: string, playerName: string, playerType?: PlayerType | "all"): Promise<PlayerStats | null>;
|
|
188
|
+
createTournament(options: CreateTournamentOptions): Promise<string>;
|
|
189
|
+
joinTournament(tid: string, playerName: string, playerType?: PlayerType): Promise<void>;
|
|
190
|
+
startTournament(tid: string): Promise<void>;
|
|
191
|
+
getTournament(tid: string): Promise<Tournament | null>;
|
|
192
|
+
listTournaments(): Promise<Tournament[]>;
|
|
193
|
+
recordMatchResult(tid: string, matchId: number, winner: string): Promise<void>;
|
|
194
|
+
/** Normalize any move to a string without submitting */
|
|
195
|
+
normalizeMove(move: AnyMove, gameHint?: string): NormalizedMove;
|
|
196
|
+
/** Sleep helper */
|
|
197
|
+
private sleep;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
declare function normalizeMove(move: AnyMove, gameHint?: string): NormalizedMove;
|
|
201
|
+
|
|
202
|
+
declare const NETWORKS: Record<NetworkId, NetworkConfig>;
|
|
203
|
+
declare function resolveNetwork(network: NetworkId | NetworkConfig): NetworkConfig;
|
|
204
|
+
declare function gidToNum(gid: string): number;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Create a TheRef client.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* // Agent (server-side)
|
|
211
|
+
* const ref = createTheRef({
|
|
212
|
+
* network: "bradbury",
|
|
213
|
+
* privateKey: process.env.AGENT_KEY as `0x${string}`,
|
|
214
|
+
* });
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* // Browser wallet
|
|
218
|
+
* const ref = createTheRef({
|
|
219
|
+
* network: "bradbury",
|
|
220
|
+
* walletAddress: "0xYourWallet",
|
|
221
|
+
* });
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* // Development (Studionet, no key needed)
|
|
225
|
+
* const ref = createTheRef({ network: "studionet" });
|
|
226
|
+
*/
|
|
227
|
+
declare function createTheRef(config: TheRefConfig): TheRefClient;
|
|
228
|
+
|
|
229
|
+
export { type AnyMove, type BracketMatch, type ContractAddresses, type CreateGameOptions, type CreateTournamentOptions, type GameState, type GameStatus, type JudgmentResult, type LeaderboardEntry, NETWORKS, type NetworkConfig, type NetworkId, type NormalizedMove, type PlayerStats, type PlayerType, type RoundResult, TheRefClient, type TheRefConfig, type Tournament, createTheRef, gidToNum, normalizeMove, resolveNetwork };
|