@kradle/challenges-sdk 0.21.0 → 0.22.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/CHANGELOG.md +34 -1
- package/LLM_README.md +127 -8
- package/README.md +113 -0
- package/dist/engine.d.ts +1 -0
- package/dist/engine.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/runtime/dialog.d.ts +83 -0
- package/dist/runtime/dialog.d.ts.map +1 -0
- package/dist/runtime/dialog.js +95 -0
- package/dist/runtime/dialog.js.map +1 -0
- package/dist/runtime/reducer.d.ts +18 -1
- package/dist/runtime/reducer.d.ts.map +1 -1
- package/dist/runtime/reducer.js +120 -3
- package/dist/runtime/reducer.js.map +1 -1
- package/dist/runtime/types.d.ts +52 -9
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/runtime/types.js.map +1 -1
- package/dist/runtime/wire.d.ts +51 -1
- package/dist/runtime/wire.d.ts.map +1 -1
- package/dist/runtime/wire.js +1 -0
- package/dist/runtime/wire.js.map +1 -1
- package/dist/test/harness.d.ts +14 -0
- package/dist/test/harness.d.ts.map +1 -1
- package/dist/test/harness.js +23 -2
- package/dist/test/harness.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../src/runtime/reducer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../src/runtime/reducer.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAe,KAAK,UAAU,EAAqC,MAAM,aAAa,CAAC;AAG9F,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,KAAK,EAAW,MAAM,WAAW,CAAC;AAC/D,OAAO,KAAK,EAEX,SAAS,EACT,UAAU,EACV,eAAe,EAGf,QAAQ,EAIR,OAAO,EACP,SAAS,EAGT,SAAS,EAET,KAAK,EACL,MAAM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CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,EAAE,CAqB1D;AAmKD,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,GAAG;IAC/C,IAAI,EAAE,MAAM,KAAK,CAAC;IAClB,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,KAAK;QAAE,KAAK,EAAE,KAAK,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;CAC5E,CA43DA"}
|
package/dist/runtime/reducer.js
CHANGED
|
@@ -22,6 +22,7 @@ exports.parseBlockState = parseBlockState;
|
|
|
22
22
|
exports.blockSpecString = blockSpecString;
|
|
23
23
|
exports.splitBatches = splitBatches;
|
|
24
24
|
exports.createReducer = createReducer;
|
|
25
|
+
const dialog_js_1 = require("./dialog.js");
|
|
25
26
|
const chat_js_1 = require("./chat.js");
|
|
26
27
|
const errors_js_1 = require("./errors.js");
|
|
27
28
|
const time_js_1 = require("./time.js");
|
|
@@ -197,7 +198,9 @@ function splitBatches(effects) {
|
|
|
197
198
|
for (const e of effects) {
|
|
198
199
|
const v = fillVolume(e);
|
|
199
200
|
if (v > exports.MAX_FILL_VOLUME) {
|
|
200
|
-
throw (0, errors_js_1.apiError)("fill_too_large", `a ${e.kind} of ${v} blocks exceeds ${exports.MAX_FILL_VOLUME}; split it`, {
|
|
201
|
+
throw (0, errors_js_1.apiError)("fill_too_large", `a ${e.kind} of ${v} blocks exceeds ${exports.MAX_FILL_VOLUME}; split it`, {
|
|
202
|
+
path: "setup",
|
|
203
|
+
});
|
|
201
204
|
}
|
|
202
205
|
if (current.length >= exports.MAX_BATCH_EFFECTS || volume + v > exports.MAX_FILL_VOLUME) {
|
|
203
206
|
out.push(current);
|
|
@@ -366,8 +369,10 @@ function createReducer(def) {
|
|
|
366
369
|
votes: Object.fromEntries(voteIds.map((id) => [id, { open: false, round: 0, cast: {} }])),
|
|
367
370
|
walks: {},
|
|
368
371
|
batches: {},
|
|
372
|
+
commands: {},
|
|
369
373
|
containers: {},
|
|
370
374
|
world: (0, world_js_1.emptyWorld)(),
|
|
375
|
+
dialogs: {},
|
|
371
376
|
nextId: 0,
|
|
372
377
|
winners: [],
|
|
373
378
|
endState: "",
|
|
@@ -634,6 +639,36 @@ function createReducer(def) {
|
|
|
634
639
|
const abstaining = players().filter((p) => !p.eliminated && v.cast[p.name] === undefined);
|
|
635
640
|
return { counts, leaders, abstaining };
|
|
636
641
|
},
|
|
642
|
+
dialog(player, definition) {
|
|
643
|
+
write("dialog");
|
|
644
|
+
if (s.status !== "PLAYING")
|
|
645
|
+
throw (0, errors_js_1.apiError)("dialog_stage", "dialog: the game must be in play");
|
|
646
|
+
if (!s.capabilities.includes("dialogs"))
|
|
647
|
+
throw (0, errors_js_1.unavailableError)("dialogs_unavailable", "dialog: this server does not support dialog responses");
|
|
648
|
+
const p = s.players[player?.name];
|
|
649
|
+
if (!p?.human || !p.connected)
|
|
650
|
+
throw (0, errors_js_1.apiError)("dialog_player", "dialog: select a connected human participant");
|
|
651
|
+
(0, dialog_js_1.validateDialog)(definition);
|
|
652
|
+
const timeoutTicks = (0, time_js_1.toTicks)(definition.timeout ?? "60s");
|
|
653
|
+
if (!Number.isInteger(timeoutTicks) || timeoutTicks < 1 || timeoutTicks > 72000)
|
|
654
|
+
throw (0, errors_js_1.apiError)("dialog_timeout", "dialog: timeout must be from one tick to one hour");
|
|
655
|
+
const { timeout: _timeout, ...dialog } = compact(snapshot(definition));
|
|
656
|
+
const requestId = `dialog:${s.nextId++}`;
|
|
657
|
+
s.dialogs ??= {};
|
|
658
|
+
s.dialogs[p.name] = { requestId, dialog, expires: s.tick + timeoutTicks };
|
|
659
|
+
push({ kind: "dialog", player: p.name, requestId, dialog, timeoutTicks });
|
|
660
|
+
},
|
|
661
|
+
clearDialog(player) {
|
|
662
|
+
write("clearDialog");
|
|
663
|
+
const p = s.players[player?.name];
|
|
664
|
+
if (!p?.human)
|
|
665
|
+
throw (0, errors_js_1.apiError)("dialog_player", "clearDialog: select a human participant");
|
|
666
|
+
if (!s.capabilities.includes("dialogs"))
|
|
667
|
+
throw (0, errors_js_1.unavailableError)("dialogs_unavailable", "clearDialog: this server does not support dialog responses");
|
|
668
|
+
if (s.dialogs)
|
|
669
|
+
delete s.dialogs[p.name];
|
|
670
|
+
push({ kind: "clear_dialog", player: p.name });
|
|
671
|
+
},
|
|
637
672
|
// ---- notifications
|
|
638
673
|
say(message) {
|
|
639
674
|
notify("say");
|
|
@@ -830,10 +865,20 @@ function createReducer(def) {
|
|
|
830
865
|
}));
|
|
831
866
|
push({ kind: "container", at: { ...at }, items: out });
|
|
832
867
|
},
|
|
833
|
-
command(cmd) {
|
|
868
|
+
command(cmd, name) {
|
|
834
869
|
write("command");
|
|
835
870
|
r.actions.push({ type: "log", message: `raw command: ${cmd}` });
|
|
836
|
-
|
|
871
|
+
if (name === undefined) {
|
|
872
|
+
push({ kind: "command", cmd });
|
|
873
|
+
return;
|
|
874
|
+
}
|
|
875
|
+
if (typeof name !== "string")
|
|
876
|
+
throw (0, errors_js_1.apiError)("invalid_value", "command: the name must be a string", { value: name });
|
|
877
|
+
if (s.status !== "PLAYING")
|
|
878
|
+
throw (0, errors_js_1.apiError)("lifecycle", `command("${cmd}", "${name}"): a result needs a running game, not .setup (status ${s.status})`);
|
|
879
|
+
const id = `cmd:${s.nextId++}`;
|
|
880
|
+
s.commands[id] = { name };
|
|
881
|
+
push({ kind: "command", cmd, id });
|
|
837
882
|
},
|
|
838
883
|
// ---- flow
|
|
839
884
|
startPhase(name) {
|
|
@@ -936,6 +981,11 @@ function createReducer(def) {
|
|
|
936
981
|
// The transport id is unique for the run; the public name repeats once its batch is done.
|
|
937
982
|
const id = `batch:${s.nextId++}`;
|
|
938
983
|
s.batches[id] = name;
|
|
984
|
+
for (const e of effects) {
|
|
985
|
+
const c = e.kind === "command" && e.id !== undefined ? s.commands[e.id] : undefined;
|
|
986
|
+
if (c)
|
|
987
|
+
c.batch = id;
|
|
988
|
+
}
|
|
939
989
|
r.actions.push({ type: "batch", id, effects });
|
|
940
990
|
},
|
|
941
991
|
};
|
|
@@ -978,6 +1028,19 @@ function createReducer(def) {
|
|
|
978
1028
|
run(r, "handler", local, g, e);
|
|
979
1029
|
resolvePhaseRequest(r);
|
|
980
1030
|
}
|
|
1031
|
+
/** A named command's answer: it leaves the pending set and reaches `on.commandResult`. An unknown id is ignored. */
|
|
1032
|
+
function commandDone(r, id, ok, value, error) {
|
|
1033
|
+
const c = r.s.commands[id];
|
|
1034
|
+
if (!c)
|
|
1035
|
+
return;
|
|
1036
|
+
delete r.s.commands[id];
|
|
1037
|
+
fire(r, "commandResult", () => compact({
|
|
1038
|
+
name: c.name,
|
|
1039
|
+
ok,
|
|
1040
|
+
value: ok && value !== undefined ? snapshot(value) : undefined,
|
|
1041
|
+
error: ok ? undefined : (error ?? "the command failed"),
|
|
1042
|
+
}));
|
|
1043
|
+
}
|
|
981
1044
|
/** The contexts of a reduction, one per mode, built on first use. */
|
|
982
1045
|
const ctxCache = new WeakMap();
|
|
983
1046
|
function ctxOf(r, mode) {
|
|
@@ -1186,8 +1249,14 @@ function createReducer(def) {
|
|
|
1186
1249
|
assertJson(judge, "judgeContext");
|
|
1187
1250
|
gameOver.judgeContext = judge;
|
|
1188
1251
|
}
|
|
1252
|
+
clearDialogs(s, r.actions);
|
|
1189
1253
|
r.actions.push(gameOver);
|
|
1190
1254
|
}
|
|
1255
|
+
function clearDialogs(s, actions) {
|
|
1256
|
+
for (const player of Object.keys(s.dialogs ?? {}))
|
|
1257
|
+
actions.push({ type: "effect", effect: { kind: "clear_dialog", player } });
|
|
1258
|
+
s.dialogs = {};
|
|
1259
|
+
}
|
|
1191
1260
|
/** The SDK's own terminal result: no author callback runs. */
|
|
1192
1261
|
function failRun(s, actions, endState, message, data) {
|
|
1193
1262
|
actions.push(compact({ type: "log", message, data }));
|
|
@@ -1202,6 +1271,7 @@ function createReducer(def) {
|
|
|
1202
1271
|
const achievements = {};
|
|
1203
1272
|
for (const p of Object.values(s.players))
|
|
1204
1273
|
achievements[p.name] = [...p.achievements];
|
|
1274
|
+
clearDialogs(s, actions);
|
|
1205
1275
|
actions.push({ type: "game_over", winners: [], endState, reason: "error", achievements });
|
|
1206
1276
|
}
|
|
1207
1277
|
// ------------------------------------------------------------ lifecycle
|
|
@@ -1762,6 +1832,8 @@ function createReducer(def) {
|
|
|
1762
1832
|
return;
|
|
1763
1833
|
}
|
|
1764
1834
|
p.connected = false;
|
|
1835
|
+
if (s.dialogs)
|
|
1836
|
+
delete s.dialogs[p.name];
|
|
1765
1837
|
if (playing())
|
|
1766
1838
|
fire(r, "left", { player: viewOf(r, p) });
|
|
1767
1839
|
break;
|
|
@@ -1770,6 +1842,12 @@ function createReducer(def) {
|
|
|
1770
1842
|
r.isTick = true;
|
|
1771
1843
|
s.dt = e.serverTick - s.tick;
|
|
1772
1844
|
s.tick = e.serverTick;
|
|
1845
|
+
for (const [player, d] of Object.entries(s.dialogs ?? {})) {
|
|
1846
|
+
if (s.tick < d.expires)
|
|
1847
|
+
continue;
|
|
1848
|
+
delete s.dialogs[player];
|
|
1849
|
+
r.actions.push({ type: "effect", effect: { kind: "clear_dialog", player } });
|
|
1850
|
+
}
|
|
1773
1851
|
if (e.entities)
|
|
1774
1852
|
s.world = (0, world_js_1.moveEntities)(s.world, e.entities);
|
|
1775
1853
|
if (e.time !== undefined && e.time !== s.world.time)
|
|
@@ -1813,6 +1891,11 @@ function createReducer(def) {
|
|
|
1813
1891
|
play(r);
|
|
1814
1892
|
return;
|
|
1815
1893
|
}
|
|
1894
|
+
// A command of the batch with no result yet did not run: the batch was refused before the engine got it.
|
|
1895
|
+
for (const [id, c] of Object.entries(s.commands)) {
|
|
1896
|
+
if (c.batch === e.id)
|
|
1897
|
+
commandDone(r, id, false, undefined, e.detail ?? "the command did not run");
|
|
1898
|
+
}
|
|
1816
1899
|
const batchName = s.batches[e.id];
|
|
1817
1900
|
if (batchName !== undefined) {
|
|
1818
1901
|
delete s.batches[e.id];
|
|
@@ -1835,8 +1918,18 @@ function createReducer(def) {
|
|
|
1835
1918
|
}
|
|
1836
1919
|
break;
|
|
1837
1920
|
}
|
|
1921
|
+
case "command_result":
|
|
1922
|
+
commandDone(r, e.id, e.ok, e.value, e.error);
|
|
1923
|
+
break;
|
|
1838
1924
|
case "effect_failed":
|
|
1925
|
+
if (e.effect?.kind === "dialog") {
|
|
1926
|
+
const effect = e.effect;
|
|
1927
|
+
if (s.dialogs?.[effect.player]?.requestId === effect.requestId)
|
|
1928
|
+
delete s.dialogs[effect.player];
|
|
1929
|
+
}
|
|
1839
1930
|
r.actions.push({ type: "log", message: `effect failed: ${e.kind}: ${e.detail}` });
|
|
1931
|
+
if (e.effect?.kind === "command" && e.effect.id !== undefined)
|
|
1932
|
+
commandDone(r, e.effect.id, false, undefined, e.detail);
|
|
1840
1933
|
if (playing()) {
|
|
1841
1934
|
fire(r, "effectFailed", {
|
|
1842
1935
|
kind: e.kind,
|
|
@@ -1872,6 +1965,8 @@ function createReducer(def) {
|
|
|
1872
1965
|
break;
|
|
1873
1966
|
}
|
|
1874
1967
|
case "player_died": {
|
|
1968
|
+
if (s.dialogs)
|
|
1969
|
+
delete s.dialogs[e.name];
|
|
1875
1970
|
const p = resolve(e.name);
|
|
1876
1971
|
if (!p)
|
|
1877
1972
|
return;
|
|
@@ -2095,6 +2190,28 @@ function createReducer(def) {
|
|
|
2095
2190
|
case "vote_attempt":
|
|
2096
2191
|
voteAttempt(r, e);
|
|
2097
2192
|
break;
|
|
2193
|
+
case "dialog_response": {
|
|
2194
|
+
const p = resolve(e.player);
|
|
2195
|
+
const d = s.dialogs?.[e.player];
|
|
2196
|
+
if (!playing() ||
|
|
2197
|
+
!p?.human ||
|
|
2198
|
+
!p.connected ||
|
|
2199
|
+
!d ||
|
|
2200
|
+
s.tick >= d.expires ||
|
|
2201
|
+
d.requestId !== e.requestId ||
|
|
2202
|
+
d.dialog.id !== e.dialogId ||
|
|
2203
|
+
!d.dialog.buttons.some((b) => b.id === e.buttonId) ||
|
|
2204
|
+
!(0, dialog_js_1.validDialogValues)(d.dialog, e.inputs))
|
|
2205
|
+
break;
|
|
2206
|
+
delete s.dialogs[e.player];
|
|
2207
|
+
fire(r, "dialogResponse", {
|
|
2208
|
+
player: viewOf(r, p),
|
|
2209
|
+
dialogId: e.dialogId,
|
|
2210
|
+
buttonId: e.buttonId,
|
|
2211
|
+
inputs: snapshot(e.inputs),
|
|
2212
|
+
});
|
|
2213
|
+
break;
|
|
2214
|
+
}
|
|
2098
2215
|
case "custom": {
|
|
2099
2216
|
if (!playing())
|
|
2100
2217
|
return;
|