theref-sdk 0.1.0 → 0.1.1
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/dist/index.js +16 -5
- package/dist/index.mjs +16 -5
- package/package.json +10 -2
- package/src/adapters/normalizer.ts +12 -6
package/dist/index.js
CHANGED
|
@@ -78,19 +78,25 @@ function adaptChess(move) {
|
|
|
78
78
|
}
|
|
79
79
|
if (typeof move === "object" && move !== null && !Array.isArray(move)) {
|
|
80
80
|
const m = move;
|
|
81
|
-
if (m.from && m.to) {
|
|
81
|
+
if (m.from && m.to && typeof m.from === "string" && typeof m.to === "string") {
|
|
82
82
|
const promo = m.promotion ? `=${String(m.promotion).toUpperCase()}` : "";
|
|
83
83
|
const piece = m.piece ? `${String(m.piece).toUpperCase()} ` : "";
|
|
84
|
-
return `${piece}${m.from}${m.
|
|
84
|
+
return `${piece}${m.from}${m.to}${promo}`.trim();
|
|
85
85
|
}
|
|
86
|
-
if (m.piece && m.
|
|
86
|
+
if (m.piece && m.to) {
|
|
87
87
|
const pieceMap = {
|
|
88
88
|
knight: "N",
|
|
89
89
|
bishop: "B",
|
|
90
90
|
rook: "R",
|
|
91
91
|
queen: "Q",
|
|
92
92
|
king: "K",
|
|
93
|
-
pawn: ""
|
|
93
|
+
pawn: "",
|
|
94
|
+
n: "N",
|
|
95
|
+
b: "B",
|
|
96
|
+
r: "R",
|
|
97
|
+
q: "Q",
|
|
98
|
+
k: "K",
|
|
99
|
+
p: ""
|
|
94
100
|
};
|
|
95
101
|
const p = pieceMap[String(m.piece).toLowerCase()] ?? "";
|
|
96
102
|
return `${p}${m.to}`;
|
|
@@ -144,7 +150,7 @@ function adaptCombat(move) {
|
|
|
144
150
|
if (m.player || m.character || m.unit) {
|
|
145
151
|
parts.push(String(m.player ?? m.character ?? m.unit));
|
|
146
152
|
}
|
|
147
|
-
const action = m.
|
|
153
|
+
const action = m.move ?? m.skill ?? m.ability ?? m.spell ?? m.card ?? m.action ?? m.attack;
|
|
148
154
|
if (action) parts.push(`uses ${action}`);
|
|
149
155
|
const target = m.target ?? m.enemy ?? m.opponent;
|
|
150
156
|
if (target) parts.push(`on ${target}`);
|
|
@@ -218,6 +224,11 @@ function normalizeMove(move, gameHint) {
|
|
|
218
224
|
return { raw: move, text: move.trim(), adapter: "passthrough" };
|
|
219
225
|
}
|
|
220
226
|
if (typeof move === "number") {
|
|
227
|
+
const rpsMap = { 0: "Rock", 1: "Paper", 2: "Scissors" };
|
|
228
|
+
const hintLower = (gameHint ?? "").toLowerCase();
|
|
229
|
+
if (hintLower.includes("rps") || hintLower.includes("rock") || hintLower.includes("scissors")) {
|
|
230
|
+
if (rpsMap[move] !== void 0) return { raw: move, text: rpsMap[move], adapter: "rps" };
|
|
231
|
+
}
|
|
221
232
|
return { raw: move, text: String(move), adapter: "number" };
|
|
222
233
|
}
|
|
223
234
|
if (typeof move === "boolean") {
|
package/dist/index.mjs
CHANGED
|
@@ -47,19 +47,25 @@ function adaptChess(move) {
|
|
|
47
47
|
}
|
|
48
48
|
if (typeof move === "object" && move !== null && !Array.isArray(move)) {
|
|
49
49
|
const m = move;
|
|
50
|
-
if (m.from && m.to) {
|
|
50
|
+
if (m.from && m.to && typeof m.from === "string" && typeof m.to === "string") {
|
|
51
51
|
const promo = m.promotion ? `=${String(m.promotion).toUpperCase()}` : "";
|
|
52
52
|
const piece = m.piece ? `${String(m.piece).toUpperCase()} ` : "";
|
|
53
|
-
return `${piece}${m.from}${m.
|
|
53
|
+
return `${piece}${m.from}${m.to}${promo}`.trim();
|
|
54
54
|
}
|
|
55
|
-
if (m.piece && m.
|
|
55
|
+
if (m.piece && m.to) {
|
|
56
56
|
const pieceMap = {
|
|
57
57
|
knight: "N",
|
|
58
58
|
bishop: "B",
|
|
59
59
|
rook: "R",
|
|
60
60
|
queen: "Q",
|
|
61
61
|
king: "K",
|
|
62
|
-
pawn: ""
|
|
62
|
+
pawn: "",
|
|
63
|
+
n: "N",
|
|
64
|
+
b: "B",
|
|
65
|
+
r: "R",
|
|
66
|
+
q: "Q",
|
|
67
|
+
k: "K",
|
|
68
|
+
p: ""
|
|
63
69
|
};
|
|
64
70
|
const p = pieceMap[String(m.piece).toLowerCase()] ?? "";
|
|
65
71
|
return `${p}${m.to}`;
|
|
@@ -113,7 +119,7 @@ function adaptCombat(move) {
|
|
|
113
119
|
if (m.player || m.character || m.unit) {
|
|
114
120
|
parts.push(String(m.player ?? m.character ?? m.unit));
|
|
115
121
|
}
|
|
116
|
-
const action = m.
|
|
122
|
+
const action = m.move ?? m.skill ?? m.ability ?? m.spell ?? m.card ?? m.action ?? m.attack;
|
|
117
123
|
if (action) parts.push(`uses ${action}`);
|
|
118
124
|
const target = m.target ?? m.enemy ?? m.opponent;
|
|
119
125
|
if (target) parts.push(`on ${target}`);
|
|
@@ -187,6 +193,11 @@ function normalizeMove(move, gameHint) {
|
|
|
187
193
|
return { raw: move, text: move.trim(), adapter: "passthrough" };
|
|
188
194
|
}
|
|
189
195
|
if (typeof move === "number") {
|
|
196
|
+
const rpsMap = { 0: "Rock", 1: "Paper", 2: "Scissors" };
|
|
197
|
+
const hintLower = (gameHint ?? "").toLowerCase();
|
|
198
|
+
if (hintLower.includes("rps") || hintLower.includes("rock") || hintLower.includes("scissors")) {
|
|
199
|
+
if (rpsMap[move] !== void 0) return { raw: move, text: rpsMap[move], adapter: "rps" };
|
|
200
|
+
}
|
|
190
201
|
return { raw: move, text: String(move), adapter: "number" };
|
|
191
202
|
}
|
|
192
203
|
if (typeof move === "boolean") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "theref-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Universal SDK for TheRef — the decentralized AI game referee on GenLayer",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -17,7 +17,15 @@
|
|
|
17
17
|
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
18
18
|
"test": "jest"
|
|
19
19
|
},
|
|
20
|
-
"keywords": [
|
|
20
|
+
"keywords": [
|
|
21
|
+
"genlayer",
|
|
22
|
+
"theref",
|
|
23
|
+
"ai",
|
|
24
|
+
"gaming",
|
|
25
|
+
"blockchain",
|
|
26
|
+
"sdk",
|
|
27
|
+
"agent"
|
|
28
|
+
],
|
|
21
29
|
"author": "0xZaid10",
|
|
22
30
|
"license": "MIT",
|
|
23
31
|
"dependencies": {
|
|
@@ -17,16 +17,17 @@ function adaptChess(move: AnyMove): string | null {
|
|
|
17
17
|
}
|
|
18
18
|
if (typeof move === "object" && move !== null && !Array.isArray(move)) {
|
|
19
19
|
const m = move as Record<string, AnyMove>;
|
|
20
|
-
// { from: "e2", to: "e4" }
|
|
21
|
-
if (m.from && m.to) {
|
|
20
|
+
// { from: "e2", to: "e4" } — only treat as chess if values are strings (chess squares)
|
|
21
|
+
if (m.from && m.to && typeof m.from === "string" && typeof m.to === "string") {
|
|
22
22
|
const promo = m.promotion ? `=${String(m.promotion).toUpperCase()}` : "";
|
|
23
23
|
const piece = m.piece ? `${String(m.piece).toUpperCase()} ` : "";
|
|
24
|
-
return `${piece}${m.from}${m.
|
|
24
|
+
return `${piece}${m.from}${m.to}${promo}`.trim();
|
|
25
25
|
}
|
|
26
26
|
// { piece: "knight", from: "g1", to: "f3" }
|
|
27
|
-
if (m.piece && m.
|
|
27
|
+
if (m.piece && m.to) {
|
|
28
28
|
const pieceMap: Record<string, string> = {
|
|
29
29
|
knight: "N", bishop: "B", rook: "R", queen: "Q", king: "K", pawn: "",
|
|
30
|
+
n: "N", b: "B", r: "R", q: "Q", k: "K", p: "",
|
|
30
31
|
};
|
|
31
32
|
const p = pieceMap[String(m.piece).toLowerCase()] ?? "";
|
|
32
33
|
return `${p}${m.to}`;
|
|
@@ -81,7 +82,7 @@ function adaptCombat(move: AnyMove): string | null {
|
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
// Action
|
|
84
|
-
const action = m.
|
|
85
|
+
const action = m.move ?? m.skill ?? m.ability ?? m.spell ?? m.card ?? m.action ?? m.attack;
|
|
85
86
|
if (action) parts.push(`uses ${action}`);
|
|
86
87
|
|
|
87
88
|
// Target
|
|
@@ -181,8 +182,13 @@ export function normalizeMove(move: AnyMove, gameHint?: string): NormalizedMove
|
|
|
181
182
|
return { raw: move, text: move.trim(), adapter: "passthrough" };
|
|
182
183
|
}
|
|
183
184
|
|
|
184
|
-
// 2. Number —
|
|
185
|
+
// 2. Number — try RPS first (0=Rock, 1=Paper, 2=Scissors), then generic
|
|
185
186
|
if (typeof move === "number") {
|
|
187
|
+
const rpsMap: Record<number, string> = { 0: "Rock", 1: "Paper", 2: "Scissors" };
|
|
188
|
+
const hintLower = (gameHint ?? "").toLowerCase();
|
|
189
|
+
if (hintLower.includes("rps") || hintLower.includes("rock") || hintLower.includes("scissors")) {
|
|
190
|
+
if (rpsMap[move] !== undefined) return { raw: move, text: rpsMap[move], adapter: "rps" };
|
|
191
|
+
}
|
|
186
192
|
return { raw: move, text: String(move), adapter: "number" };
|
|
187
193
|
}
|
|
188
194
|
|