@dxos/plugin-chess 0.8.4-main.84f28bd → 0.8.4-main.8baae0fced
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/LICENSE +102 -5
- package/PLUGIN.mdl +526 -0
- package/README.md +1 -1
- package/dist/lib/neutral/ChessArticle-QLLKZGPH.mjs +88 -0
- package/dist/lib/neutral/ChessArticle-QLLKZGPH.mjs.map +7 -0
- package/dist/lib/neutral/ChessCard-I5RSZZIP.mjs +19 -0
- package/dist/lib/neutral/ChessCard-I5RSZZIP.mjs.map +7 -0
- package/dist/lib/neutral/ChessPlugin.mjs +10 -0
- package/dist/lib/neutral/ChessPlugin.node.mjs +23 -0
- package/dist/lib/neutral/ChessPlugin.node.mjs.map +7 -0
- package/dist/lib/neutral/ChessPlugin.workerd.mjs +21 -0
- package/dist/lib/neutral/ChessPlugin.workerd.mjs.map +7 -0
- package/dist/lib/neutral/blueprint-definition-PZXHAYLD.mjs +15 -0
- package/dist/lib/neutral/blueprint-definition-PZXHAYLD.mjs.map +7 -0
- package/dist/lib/neutral/blueprints/index.mjs +8 -0
- package/dist/lib/neutral/capabilities/index.mjs +13 -0
- package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
- package/dist/lib/neutral/chunk-5UOTTW6U.mjs +8 -0
- package/dist/lib/neutral/chunk-5UOTTW6U.mjs.map +7 -0
- package/dist/lib/neutral/chunk-E4LZPHAQ.mjs +148 -0
- package/dist/lib/neutral/chunk-E4LZPHAQ.mjs.map +7 -0
- package/dist/lib/neutral/chunk-HVIKFYAW.mjs +29 -0
- package/dist/lib/neutral/chunk-HVIKFYAW.mjs.map +7 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/neutral/chunk-V4UMIQ6K.mjs +31 -0
- package/dist/lib/neutral/chunk-V4UMIQ6K.mjs.map +7 -0
- package/dist/lib/neutral/chunk-XWKNXG62.mjs +34 -0
- package/dist/lib/neutral/chunk-XWKNXG62.mjs.map +7 -0
- package/dist/lib/neutral/components/index.mjs +239 -0
- package/dist/lib/neutral/components/index.mjs.map +7 -0
- package/dist/lib/neutral/containers/index.mjs +11 -0
- package/dist/lib/neutral/containers/index.mjs.map +7 -0
- package/dist/lib/neutral/game-variant-24UKIBRM.mjs +40 -0
- package/dist/lib/neutral/game-variant-24UKIBRM.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +18 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/meta.mjs +8 -0
- package/dist/lib/neutral/meta.mjs.map +7 -0
- package/dist/lib/neutral/move-RQZ7BJY3.mjs +37 -0
- package/dist/lib/neutral/move-RQZ7BJY3.mjs.map +7 -0
- package/dist/lib/neutral/operation-handler-EKZKFQUG.mjs +13 -0
- package/dist/lib/neutral/operation-handler-EKZKFQUG.mjs.map +7 -0
- package/dist/lib/neutral/operations/index.mjs +8 -0
- package/dist/lib/neutral/operations/index.mjs.map +7 -0
- package/dist/lib/neutral/play-GDGCEPQL.mjs +46 -0
- package/dist/lib/neutral/play-GDGCEPQL.mjs.map +7 -0
- package/dist/lib/neutral/plugin.mjs +16 -0
- package/dist/lib/neutral/plugin.mjs.map +7 -0
- package/dist/lib/neutral/print-ZQA74KZI.mjs +29 -0
- package/dist/lib/neutral/print-ZQA74KZI.mjs.map +7 -0
- package/dist/lib/neutral/testing.mjs +8 -0
- package/dist/lib/neutral/testing.mjs.map +7 -0
- package/dist/lib/neutral/translations.mjs +34 -0
- package/dist/lib/neutral/translations.mjs.map +7 -0
- package/dist/lib/neutral/types/index.mjs +10 -0
- package/dist/lib/neutral/types/index.mjs.map +7 -0
- package/dist/types/src/ChessPlugin.d.ts +3 -1
- package/dist/types/src/ChessPlugin.d.ts.map +1 -1
- package/dist/types/src/ChessPlugin.node.d.ts +8 -0
- package/dist/types/src/ChessPlugin.node.d.ts.map +1 -0
- package/dist/types/src/ChessPlugin.test.d.ts +2 -0
- package/dist/types/src/ChessPlugin.test.d.ts.map +1 -0
- package/dist/types/src/ChessPlugin.workerd.d.ts +4 -0
- package/dist/types/src/ChessPlugin.workerd.d.ts.map +1 -0
- package/dist/types/src/blueprints/chess-blueprint.d.ts +4 -0
- package/dist/types/src/blueprints/chess-blueprint.d.ts.map +1 -0
- package/dist/types/src/blueprints/index.d.ts +2 -0
- package/dist/types/src/blueprints/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/blueprint-definition.d.ts +6 -0
- package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/game-variant.d.ts +6 -0
- package/dist/types/src/capabilities/game-variant.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +5 -3
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
- package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard/Chessboard.d.ts +38 -0
- package/dist/types/src/components/Chessboard/Chessboard.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts +57 -0
- package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard/Info.d.ts +20 -0
- package/dist/types/src/components/Chessboard/Info.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard/index.d.ts +2 -0
- package/dist/types/src/components/Chessboard/index.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard/types.d.ts +8 -0
- package/dist/types/src/components/Chessboard/types.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +1 -5
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/containers/ChessArticle/ChessArticle.d.ts +5 -0
- package/dist/types/src/containers/ChessArticle/ChessArticle.d.ts.map +1 -0
- package/dist/types/src/containers/ChessArticle/ChessArticle.stories.d.ts +56 -0
- package/dist/types/src/containers/ChessArticle/ChessArticle.stories.d.ts.map +1 -0
- package/dist/types/src/containers/ChessArticle/index.d.ts +2 -0
- package/dist/types/src/containers/ChessArticle/index.d.ts.map +1 -0
- package/dist/types/src/containers/ChessCard/ChessCard.d.ts +5 -0
- package/dist/types/src/containers/ChessCard/ChessCard.d.ts.map +1 -0
- package/dist/types/src/containers/ChessCard/ChessCard.stories.d.ts +15 -0
- package/dist/types/src/containers/ChessCard/ChessCard.stories.d.ts.map +1 -0
- package/dist/types/src/containers/ChessCard/index.d.ts +2 -0
- package/dist/types/src/containers/ChessCard/index.d.ts.map +1 -0
- package/dist/types/src/containers/index.d.ts +4 -0
- package/dist/types/src/containers/index.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -3
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/operations/index.d.ts +3 -0
- package/dist/types/src/operations/index.d.ts.map +1 -0
- package/dist/types/src/operations/move.d.ts +5 -0
- package/dist/types/src/operations/move.d.ts.map +1 -0
- package/dist/types/src/operations/play.d.ts +5 -0
- package/dist/types/src/operations/play.d.ts.map +1 -0
- package/dist/types/src/operations/print.d.ts +5 -0
- package/dist/types/src/operations/print.d.ts.map +1 -0
- package/dist/types/src/plugin.d.ts +4 -0
- package/dist/types/src/plugin.d.ts.map +1 -0
- package/dist/types/src/testing.d.ts +2 -0
- package/dist/types/src/testing.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +32 -12
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Chess.d.ts +18 -0
- package/dist/types/src/types/Chess.d.ts.map +1 -0
- package/dist/types/src/types/ChessOperation.d.ts +24 -0
- package/dist/types/src/types/ChessOperation.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +2 -2
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +119 -50
- package/src/ChessPlugin.node.ts +23 -0
- package/src/ChessPlugin.test.ts +50 -0
- package/src/ChessPlugin.tsx +20 -54
- package/src/ChessPlugin.workerd.ts +18 -0
- package/src/blueprints/chess-blueprint.ts +32 -0
- package/src/blueprints/index.ts +5 -0
- package/src/capabilities/blueprint-definition.ts +19 -0
- package/src/capabilities/game-variant.ts +42 -0
- package/src/capabilities/index.ts +9 -4
- package/src/capabilities/operation-handler.ts +14 -0
- package/src/components/Chessboard/Chessboard.stories.tsx +94 -0
- package/src/components/Chessboard/Chessboard.tsx +180 -0
- package/src/components/Chessboard/Info.tsx +193 -0
- package/src/components/Chessboard/index.ts +5 -0
- package/src/components/Chessboard/types.ts +18 -0
- package/src/components/index.ts +2 -6
- package/src/containers/ChessArticle/ChessArticle.stories.tsx +59 -0
- package/src/containers/ChessArticle/ChessArticle.tsx +108 -0
- package/src/containers/ChessArticle/index.ts +5 -0
- package/src/containers/ChessCard/ChessCard.stories.tsx +47 -0
- package/src/containers/ChessCard/ChessCard.tsx +27 -0
- package/src/containers/ChessCard/index.ts +5 -0
- package/src/containers/index.ts +8 -0
- package/src/index.ts +2 -4
- package/src/meta.ts +15 -7
- package/src/operations/index.ts +11 -0
- package/src/operations/move.ts +36 -0
- package/src/operations/play.ts +45 -0
- package/src/operations/print.ts +28 -0
- package/src/plugin.ts +11 -0
- package/src/testing.ts +7 -0
- package/src/translations.ts +18 -10
- package/src/types/Chess.ts +59 -0
- package/src/types/ChessOperation.ts +85 -0
- package/src/types/index.ts +2 -2
- package/dist/lib/browser/ChessContainer-DL5J6VIK.mjs +0 -101
- package/dist/lib/browser/ChessContainer-DL5J6VIK.mjs.map +0 -7
- package/dist/lib/browser/artifact-definition-4AMZY5LQ.mjs +0 -182
- package/dist/lib/browser/artifact-definition-4AMZY5LQ.mjs.map +0 -7
- package/dist/lib/browser/chunk-2VF6U52K.mjs +0 -8
- package/dist/lib/browser/chunk-2VF6U52K.mjs.map +0 -7
- package/dist/lib/browser/chunk-A3WEUKPK.mjs +0 -61
- package/dist/lib/browser/chunk-A3WEUKPK.mjs.map +0 -7
- package/dist/lib/browser/chunk-AZSYKAFK.mjs +0 -61
- package/dist/lib/browser/chunk-AZSYKAFK.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -96
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-KQYYX44R.mjs +0 -28
- package/dist/lib/browser/intent-resolver-KQYYX44R.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/react-surface-4TBVZUKU.mjs +0 -43
- package/dist/lib/browser/react-surface-4TBVZUKU.mjs.map +0 -7
- package/dist/lib/browser/types/index.mjs +0 -11
- package/dist/lib/node-esm/ChessContainer-WVOL2KSE.mjs +0 -102
- package/dist/lib/node-esm/ChessContainer-WVOL2KSE.mjs.map +0 -7
- package/dist/lib/node-esm/artifact-definition-TT3747JB.mjs +0 -183
- package/dist/lib/node-esm/artifact-definition-TT3747JB.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-2DRWEDVT.mjs +0 -63
- package/dist/lib/node-esm/chunk-2DRWEDVT.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-IS3Y25PL.mjs +0 -63
- package/dist/lib/node-esm/chunk-IS3Y25PL.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-TD2SWK2H.mjs +0 -10
- package/dist/lib/node-esm/chunk-TD2SWK2H.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -97
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-GXK2JROQ.mjs +0 -29
- package/dist/lib/node-esm/intent-resolver-GXK2JROQ.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/react-surface-PAUEOIBL.mjs +0 -44
- package/dist/lib/node-esm/react-surface-PAUEOIBL.mjs.map +0 -7
- package/dist/lib/node-esm/types/index.mjs +0 -12
- package/dist/types/src/capabilities/artifact-definition.d.ts +0 -11
- package/dist/types/src/capabilities/artifact-definition.d.ts.map +0 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-surface.d.ts +0 -4
- package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
- package/dist/types/src/components/ChessComponent.d.ts +0 -6
- package/dist/types/src/components/ChessComponent.d.ts.map +0 -1
- package/dist/types/src/components/ChessContainer.d.ts +0 -8
- package/dist/types/src/components/ChessContainer.d.ts.map +0 -1
- package/dist/types/src/components/ChessPanel.d.ts +0 -11
- package/dist/types/src/components/ChessPanel.d.ts.map +0 -1
- package/dist/types/src/components/Chessboard.stories.d.ts +0 -8
- package/dist/types/src/components/Chessboard.stories.d.ts.map +0 -1
- package/dist/types/src/components/PlayerSelector.d.ts +0 -8
- package/dist/types/src/components/PlayerSelector.d.ts.map +0 -1
- package/dist/types/src/types/schema.d.ts +0 -29
- package/dist/types/src/types/schema.d.ts.map +0 -1
- package/dist/types/src/types/types.d.ts +0 -32
- package/dist/types/src/types/types.d.ts.map +0 -1
- package/src/capabilities/artifact-definition.ts +0 -124
- package/src/capabilities/intent-resolver.ts +0 -26
- package/src/capabilities/react-surface.tsx +0 -30
- package/src/components/ChessComponent.tsx +0 -54
- package/src/components/ChessContainer.tsx +0 -35
- package/src/components/ChessPanel.tsx +0 -67
- package/src/components/Chessboard.stories.tsx +0 -39
- package/src/components/PlayerSelector.tsx +0 -80
- package/src/types/schema.ts +0 -34
- package/src/types/types.ts +0 -20
- /package/dist/lib/{browser/types/index.mjs.map → neutral/ChessPlugin.mjs.map} +0 -0
- /package/dist/lib/{node-esm/types → neutral/blueprints}/index.mjs.map +0 -0
package/src/meta.ts
CHANGED
|
@@ -2,16 +2,24 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
5
|
+
import { type Plugin } from '@dxos/app-framework';
|
|
6
|
+
import { meta as gameMeta } from '@dxos/plugin-game';
|
|
7
|
+
import { trim } from '@dxos/util';
|
|
6
8
|
|
|
7
|
-
export const
|
|
8
|
-
|
|
9
|
-
export const meta: PluginMeta = {
|
|
10
|
-
id: CHESS_PLUGIN,
|
|
9
|
+
export const meta: Plugin.Meta = {
|
|
10
|
+
id: 'org.dxos.plugin.chess',
|
|
11
11
|
name: 'Chess',
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
author: 'DXOS',
|
|
13
|
+
description: trim`
|
|
14
|
+
Full-featured chess game supporting multiplayer matches with friends or practice sessions against AI opponents.
|
|
15
|
+
Track game history and analyze moves in real-time.
|
|
16
|
+
`,
|
|
14
17
|
icon: 'ph--shield-chevron--regular',
|
|
18
|
+
iconHue: 'amber',
|
|
15
19
|
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-chess',
|
|
20
|
+
spec: 'PLUGIN.mdl',
|
|
16
21
|
screenshots: ['https://dxos.network/plugin-details-chess-dark.png'],
|
|
22
|
+
dependsOn: [gameMeta.id],
|
|
23
|
+
version: '0.8.3',
|
|
24
|
+
tags: ['game'],
|
|
17
25
|
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Chess as ChessJS } from 'chess.js';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
|
|
8
|
+
import { Operation } from '@dxos/compute';
|
|
9
|
+
import { Obj } from '@dxos/echo';
|
|
10
|
+
import { loadGame } from '@dxos/plugin-game';
|
|
11
|
+
|
|
12
|
+
import { Chess, ChessOperation } from '../types';
|
|
13
|
+
|
|
14
|
+
const handler: Operation.WithHandler<typeof ChessOperation.Move> = ChessOperation.Move.pipe(
|
|
15
|
+
Operation.withHandler(
|
|
16
|
+
Effect.fn(function* ({ game, move }) {
|
|
17
|
+
const { variant } = yield* loadGame(game, Chess.State);
|
|
18
|
+
const chess = new ChessJS();
|
|
19
|
+
if (variant.pgn) {
|
|
20
|
+
chess.loadPgn(variant.pgn);
|
|
21
|
+
} else if (variant.fen) {
|
|
22
|
+
chess.load(variant.fen);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
chess.move(move, { strict: false });
|
|
26
|
+
const pgn = chess.pgn();
|
|
27
|
+
Obj.update(variant, (variant) => {
|
|
28
|
+
const mutable = variant as Obj.Mutable<typeof variant>;
|
|
29
|
+
mutable.pgn = pgn;
|
|
30
|
+
});
|
|
31
|
+
return { pgn };
|
|
32
|
+
}),
|
|
33
|
+
),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
export default handler;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Chess as ChessJS } from 'chess.js';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
|
|
8
|
+
import { Operation } from '@dxos/compute';
|
|
9
|
+
import { Obj } from '@dxos/echo';
|
|
10
|
+
import { loadGame } from '@dxos/plugin-game';
|
|
11
|
+
|
|
12
|
+
import { Chess, ChessOperation } from '../types';
|
|
13
|
+
|
|
14
|
+
const handler: Operation.WithHandler<typeof ChessOperation.Play> = ChessOperation.Play.pipe(
|
|
15
|
+
Operation.withHandler(
|
|
16
|
+
Effect.fn(function* ({ game, side = 'any' }) {
|
|
17
|
+
const { variant } = yield* loadGame(game, Chess.State);
|
|
18
|
+
const chess = new ChessJS();
|
|
19
|
+
if (variant.pgn) {
|
|
20
|
+
chess.loadPgn(variant.pgn);
|
|
21
|
+
} else if (variant.fen) {
|
|
22
|
+
chess.load(variant.fen);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (
|
|
26
|
+
!(side === 'any' || (chess.turn() === 'w' && side === 'white') || (chess.turn() === 'b' && side === 'black'))
|
|
27
|
+
) {
|
|
28
|
+
return { move: undefined, pgn: variant.pgn ?? '' };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const moves = chess.moves();
|
|
32
|
+
const move = moves[Math.floor(Math.random() * moves.length)];
|
|
33
|
+
|
|
34
|
+
chess.move(move, { strict: false });
|
|
35
|
+
const pgn = chess.pgn();
|
|
36
|
+
Obj.update(variant, (variant) => {
|
|
37
|
+
const mutable = variant as Obj.Mutable<typeof variant>;
|
|
38
|
+
mutable.pgn = pgn;
|
|
39
|
+
});
|
|
40
|
+
return { move, pgn };
|
|
41
|
+
}),
|
|
42
|
+
),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
export default handler;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Chess as ChessJS } from 'chess.js';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
|
|
8
|
+
import { Operation } from '@dxos/compute';
|
|
9
|
+
|
|
10
|
+
import { ChessOperation } from '../types';
|
|
11
|
+
|
|
12
|
+
const handler: Operation.WithHandler<typeof ChessOperation.Print> = ChessOperation.Print.pipe(
|
|
13
|
+
Operation.withHandler(
|
|
14
|
+
Effect.fn(function* ({ pgn, fen }) {
|
|
15
|
+
try {
|
|
16
|
+
const chess = new ChessJS(fen);
|
|
17
|
+
if (pgn) {
|
|
18
|
+
chess.loadPgn(pgn);
|
|
19
|
+
}
|
|
20
|
+
return { ascii: chess.ascii() };
|
|
21
|
+
} catch {
|
|
22
|
+
return { ascii: '' };
|
|
23
|
+
}
|
|
24
|
+
}),
|
|
25
|
+
),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export default handler;
|
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Plugin } from '@dxos/app-framework';
|
|
6
|
+
|
|
7
|
+
import { meta } from './meta';
|
|
8
|
+
|
|
9
|
+
export const ChessPlugin = Plugin.lazy(meta, () => import('#plugin'));
|
|
10
|
+
|
|
11
|
+
export { ChessOperationHandlerSet } from './operations';
|
package/src/testing.ts
ADDED
package/src/translations.ts
CHANGED
|
@@ -4,22 +4,30 @@
|
|
|
4
4
|
|
|
5
5
|
import { type Resource } from '@dxos/react-ui';
|
|
6
6
|
|
|
7
|
-
import { meta } from '
|
|
8
|
-
import {
|
|
7
|
+
import { meta } from '#meta';
|
|
8
|
+
import { Chess } from '#types';
|
|
9
9
|
|
|
10
10
|
export const translations = [
|
|
11
11
|
{
|
|
12
12
|
'en-US': {
|
|
13
|
-
[
|
|
14
|
-
'typename
|
|
15
|
-
'typename
|
|
16
|
-
'typename
|
|
17
|
-
'typename
|
|
18
|
-
'object name placeholder': 'New game',
|
|
13
|
+
[Chess.State.typename]: {
|
|
14
|
+
'typename.label': 'Chess',
|
|
15
|
+
'typename.label_zero': 'Chess games',
|
|
16
|
+
'typename.label_one': 'Chess game',
|
|
17
|
+
'typename.label_other': 'Chess games',
|
|
19
18
|
},
|
|
20
19
|
[meta.id]: {
|
|
21
|
-
'plugin
|
|
22
|
-
'
|
|
20
|
+
'plugin.name': 'Chess',
|
|
21
|
+
'new-game.button': 'New game',
|
|
22
|
+
'delete-game.label': 'Delete',
|
|
23
|
+
'game.checkmate.label': 'Checkmate',
|
|
24
|
+
'game.stalemate.label': 'Stalemate',
|
|
25
|
+
'game.draw.label': 'Draw',
|
|
26
|
+
'game.check.label': 'Check',
|
|
27
|
+
'select-player.button': 'Select player',
|
|
28
|
+
'toggle-info.button': 'Toggle info',
|
|
29
|
+
'close-info.button': 'Close info',
|
|
30
|
+
'flip-board.button': 'Flip board',
|
|
23
31
|
},
|
|
24
32
|
},
|
|
25
33
|
},
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Chess as ChessJS } from 'chess.js';
|
|
6
|
+
import * as Schema from 'effect/Schema';
|
|
7
|
+
|
|
8
|
+
import { BlueprintsAnnotation } from '@dxos/app-toolkit';
|
|
9
|
+
import { Annotation, Obj, Type } from '@dxos/echo';
|
|
10
|
+
import { FormInputAnnotation, SystemTypeAnnotation } from '@dxos/echo/internal';
|
|
11
|
+
import { log } from '@dxos/log';
|
|
12
|
+
|
|
13
|
+
export const BLUEPRINT_KEY = 'org.dxos.blueprint.chess';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Chess variant state. Referenced by the base `Game` object via `Game.variant`.
|
|
17
|
+
* Players, name, and other game-shared fields live on the base `Game`.
|
|
18
|
+
*/
|
|
19
|
+
export const State = Schema.Struct({
|
|
20
|
+
pgn: Schema.String.annotations({
|
|
21
|
+
description: 'Portable Game Notation.',
|
|
22
|
+
}).pipe(FormInputAnnotation.set(false), Schema.optional),
|
|
23
|
+
fen: Schema.String.annotations({
|
|
24
|
+
description: 'Forsyth-Edwards Notation.',
|
|
25
|
+
}).pipe(FormInputAnnotation.set(false), Schema.optional),
|
|
26
|
+
}).pipe(
|
|
27
|
+
Type.object({
|
|
28
|
+
typename: 'org.dxos.type.chess.state',
|
|
29
|
+
version: '0.1.0',
|
|
30
|
+
}),
|
|
31
|
+
Annotation.IconAnnotation.set({
|
|
32
|
+
icon: 'ph--shield-chevron--regular',
|
|
33
|
+
hue: 'amber',
|
|
34
|
+
}),
|
|
35
|
+
BlueprintsAnnotation.set([BLUEPRINT_KEY]),
|
|
36
|
+
// Implementation detail of the unified `Game` schema. The user-facing object is `Game`;
|
|
37
|
+
// this state is only ever referenced via `Game.variant`. SystemType keeps it out of the
|
|
38
|
+
// navtree's typed branches so an orphaned state object doesn't reappear after the
|
|
39
|
+
// wrapping Game is deleted.
|
|
40
|
+
SystemTypeAnnotation.set(true),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
export interface State extends Schema.Schema.Type<typeof State> {}
|
|
44
|
+
|
|
45
|
+
export const make = ({ pgn, fen }: { pgn?: string; fen?: string } = {}): State => {
|
|
46
|
+
const chess = new ChessJS();
|
|
47
|
+
if (pgn) {
|
|
48
|
+
try {
|
|
49
|
+
chess.loadPgn(pgn);
|
|
50
|
+
} catch {
|
|
51
|
+
log.warn(pgn);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return Obj.make(State, {
|
|
56
|
+
pgn,
|
|
57
|
+
fen,
|
|
58
|
+
});
|
|
59
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
// @import-as-namespace
|
|
6
|
+
|
|
7
|
+
import * as Schema from 'effect/Schema';
|
|
8
|
+
|
|
9
|
+
import { Operation } from '@dxos/compute';
|
|
10
|
+
import { Database } from '@dxos/echo';
|
|
11
|
+
import { GameRef } from '@dxos/plugin-game';
|
|
12
|
+
|
|
13
|
+
import * as Chess from './Chess';
|
|
14
|
+
|
|
15
|
+
export const Move = Operation.make({
|
|
16
|
+
meta: {
|
|
17
|
+
key: 'org.dxos.function.chess.move',
|
|
18
|
+
name: 'Move',
|
|
19
|
+
description: 'Makes a move in the given chess game.',
|
|
20
|
+
},
|
|
21
|
+
input: Schema.Struct({
|
|
22
|
+
game: GameRef(Chess.State).annotations({
|
|
23
|
+
description: 'The ID of the game object (variant must be Chess).',
|
|
24
|
+
}),
|
|
25
|
+
move: Schema.String.annotations({
|
|
26
|
+
description: 'The move to make in the chess game.',
|
|
27
|
+
examples: ['e4', 'Bf3'],
|
|
28
|
+
}),
|
|
29
|
+
}),
|
|
30
|
+
output: Schema.Struct({
|
|
31
|
+
pgn: Schema.String.annotations({
|
|
32
|
+
description: 'The PGN of the game after the move was played.',
|
|
33
|
+
}),
|
|
34
|
+
}),
|
|
35
|
+
services: [Database.Service],
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export const Play = Operation.make({
|
|
39
|
+
meta: {
|
|
40
|
+
key: 'org.dxos.function.chess.play',
|
|
41
|
+
name: 'Play',
|
|
42
|
+
description: 'Uses the chess engine to play the next move.',
|
|
43
|
+
},
|
|
44
|
+
input: Schema.Struct({
|
|
45
|
+
game: GameRef(Chess.State).annotations({
|
|
46
|
+
description: 'The ID of the game object (variant must be Chess).',
|
|
47
|
+
}),
|
|
48
|
+
side: Schema.optional(Schema.Literal('white', 'black', 'any')).annotations({
|
|
49
|
+
description: 'The side to play.',
|
|
50
|
+
defaultValue: 'any',
|
|
51
|
+
}),
|
|
52
|
+
}),
|
|
53
|
+
output: Schema.Struct({
|
|
54
|
+
pgn: Schema.String.annotations({
|
|
55
|
+
description: 'The PGN of the game after the move was played.',
|
|
56
|
+
}),
|
|
57
|
+
move: Schema.optional(Schema.String).annotations({
|
|
58
|
+
description: 'The move that was played.',
|
|
59
|
+
}),
|
|
60
|
+
}),
|
|
61
|
+
services: [Database.Service],
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
export const Print = Operation.make({
|
|
65
|
+
meta: {
|
|
66
|
+
key: 'org.dxos.function.chess.print',
|
|
67
|
+
name: 'Print game',
|
|
68
|
+
description: 'Prints the chess game to ASCII.',
|
|
69
|
+
},
|
|
70
|
+
input: Schema.Struct({
|
|
71
|
+
pgn: Schema.optional(
|
|
72
|
+
Schema.String.annotations({
|
|
73
|
+
description: 'Portable Game Notation.',
|
|
74
|
+
}),
|
|
75
|
+
),
|
|
76
|
+
fen: Schema.optional(
|
|
77
|
+
Schema.String.annotations({
|
|
78
|
+
description: 'Forsyth-Edwards Notation.',
|
|
79
|
+
}),
|
|
80
|
+
),
|
|
81
|
+
}),
|
|
82
|
+
output: Schema.Struct({
|
|
83
|
+
ascii: Schema.String,
|
|
84
|
+
}),
|
|
85
|
+
});
|
package/src/types/index.ts
CHANGED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ChessComponent
|
|
3
|
-
} from "./chunk-AZSYKAFK.mjs";
|
|
4
|
-
|
|
5
|
-
// src/components/ChessContainer.tsx
|
|
6
|
-
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
7
|
-
import React2 from "react";
|
|
8
|
-
import { getSpace } from "@dxos/react-client/echo";
|
|
9
|
-
import { StackItem } from "@dxos/react-ui-stack";
|
|
10
|
-
|
|
11
|
-
// src/components/PlayerSelector.tsx
|
|
12
|
-
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
13
|
-
import { CrownCross } from "@phosphor-icons/react";
|
|
14
|
-
import React from "react";
|
|
15
|
-
import { generateName } from "@dxos/display-name";
|
|
16
|
-
import { useMembers } from "@dxos/react-client/echo";
|
|
17
|
-
import { Input, Select, useThemeContext } from "@dxos/react-ui";
|
|
18
|
-
import { getSize, mx } from "@dxos/react-ui-theme";
|
|
19
|
-
var PlayerSelector = ({ space, game }) => {
|
|
20
|
-
var _effect = _useSignals();
|
|
21
|
-
try {
|
|
22
|
-
const members = useMembers(space.key);
|
|
23
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
24
|
-
role: "none",
|
|
25
|
-
className: "grid grid-cols-2 gap-8"
|
|
26
|
-
}, /* @__PURE__ */ React.createElement("div", {
|
|
27
|
-
role: "none",
|
|
28
|
-
className: "flex flex-row-reverse items-center gap-2"
|
|
29
|
-
}, /* @__PURE__ */ React.createElement(PlayerSelect, {
|
|
30
|
-
side: "white",
|
|
31
|
-
value: game.playerWhite,
|
|
32
|
-
onValueChange: (player) => game.playerWhite = player,
|
|
33
|
-
members
|
|
34
|
-
})), /* @__PURE__ */ React.createElement("div", {
|
|
35
|
-
role: "none",
|
|
36
|
-
className: "flex flex-row items-center gap-2"
|
|
37
|
-
}, /* @__PURE__ */ React.createElement(PlayerSelect, {
|
|
38
|
-
side: "black",
|
|
39
|
-
value: game.playerBlack,
|
|
40
|
-
onValueChange: (player) => game.playerBlack = player,
|
|
41
|
-
members
|
|
42
|
-
})));
|
|
43
|
-
} finally {
|
|
44
|
-
_effect.f();
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
var PlayerSelect = ({ side, value, onValueChange, members }) => {
|
|
48
|
-
var _effect = _useSignals();
|
|
49
|
-
try {
|
|
50
|
-
const { themeMode } = useThemeContext();
|
|
51
|
-
const iconFillMode = side === "black" && themeMode === "light" || side === "white" && themeMode === "dark" ? "fill" : void 0;
|
|
52
|
-
return /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement(Input.Label, null, /* @__PURE__ */ React.createElement(CrownCross, {
|
|
53
|
-
className: mx(getSize(6)),
|
|
54
|
-
weight: iconFillMode,
|
|
55
|
-
"aria-label": `Chess icon for side ${side}`
|
|
56
|
-
})), /* @__PURE__ */ React.createElement(Select.Root, {
|
|
57
|
-
value,
|
|
58
|
-
onValueChange
|
|
59
|
-
}, /* @__PURE__ */ React.createElement(Select.TriggerButton, {
|
|
60
|
-
placeholder: "Select player"
|
|
61
|
-
}), /* @__PURE__ */ React.createElement(Select.Portal, null, /* @__PURE__ */ React.createElement(Select.Content, null, /* @__PURE__ */ React.createElement(Select.Viewport, null, members.map((member) => {
|
|
62
|
-
const memberKey = member.identity.identityKey.toHex();
|
|
63
|
-
const displayName = member.identity?.profile?.displayName || generateName(memberKey);
|
|
64
|
-
return /* @__PURE__ */ React.createElement(Select.Option, {
|
|
65
|
-
key: memberKey,
|
|
66
|
-
value: memberKey
|
|
67
|
-
}, displayName);
|
|
68
|
-
}))))));
|
|
69
|
-
} finally {
|
|
70
|
-
_effect.f();
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// src/components/ChessContainer.tsx
|
|
75
|
-
var ChessContainer = ({ game }) => {
|
|
76
|
-
var _effect = _useSignals2();
|
|
77
|
-
try {
|
|
78
|
-
const space = getSpace(game);
|
|
79
|
-
if (!space) {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
return /* @__PURE__ */ React2.createElement(StackItem.Content, null, /* @__PURE__ */ React2.createElement("div", {
|
|
83
|
-
role: "none",
|
|
84
|
-
className: "grid grid-rows-[60px_1fr_60px] grow overflow-hidden"
|
|
85
|
-
}, /* @__PURE__ */ React2.createElement("div", null), /* @__PURE__ */ React2.createElement("div", {
|
|
86
|
-
className: "flex m-4 overflow-hidden"
|
|
87
|
-
}, /* @__PURE__ */ React2.createElement(ChessComponent, {
|
|
88
|
-
game
|
|
89
|
-
})), /* @__PURE__ */ React2.createElement(PlayerSelector, {
|
|
90
|
-
space,
|
|
91
|
-
game
|
|
92
|
-
})));
|
|
93
|
-
} finally {
|
|
94
|
-
_effect.f();
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
var ChessContainer_default = ChessContainer;
|
|
98
|
-
export {
|
|
99
|
-
ChessContainer_default as default
|
|
100
|
-
};
|
|
101
|
-
//# sourceMappingURL=ChessContainer-DL5J6VIK.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/ChessContainer.tsx", "../../../src/components/PlayerSelector.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport React from 'react';\n\nimport { getSpace } from '@dxos/react-client/echo';\nimport { StackItem } from '@dxos/react-ui-stack';\n\nimport { ChessComponent } from './ChessComponent';\nimport { PlayerSelector } from './PlayerSelector';\nimport { type ChessType } from '../types';\n\nconst ChessContainer = ({ game }: { game: ChessType; role?: string }) => {\n const space = getSpace(game);\n if (!space) {\n return null;\n }\n\n return (\n <StackItem.Content>\n <div role='none' className='grid grid-rows-[60px_1fr_60px] grow overflow-hidden'>\n <div />\n\n <div className='flex m-4 overflow-hidden'>\n <ChessComponent game={game} />\n </div>\n\n <PlayerSelector space={space} game={game} />\n </div>\n </StackItem.Content>\n );\n};\n\nexport default ChessContainer;\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { CrownCross } from '@phosphor-icons/react';\nimport React from 'react';\n\nimport { generateName } from '@dxos/display-name';\nimport { useMembers, type Space, type SpaceMember } from '@dxos/react-client/echo';\nimport { Input, Select, useThemeContext } from '@dxos/react-ui';\nimport { getSize, mx } from '@dxos/react-ui-theme';\n\nimport { type ChessType } from '../types';\n\nexport const PlayerSelector = ({ space, game }: { space: Space; game: ChessType }) => {\n const members = useMembers(space.key);\n\n return (\n <div role='none' className='grid grid-cols-2 gap-8'>\n <div role='none' className='flex flex-row-reverse items-center gap-2'>\n <PlayerSelect\n side='white'\n value={game.playerWhite}\n onValueChange={(player) => (game.playerWhite = player)}\n members={members}\n />\n </div>\n <div role='none' className='flex flex-row items-center gap-2'>\n <PlayerSelect\n side='black'\n value={game.playerBlack}\n onValueChange={(player) => (game.playerBlack = player)}\n members={members}\n />\n </div>\n </div>\n );\n};\n\nconst PlayerSelect = ({\n side,\n value,\n onValueChange,\n members,\n}: {\n side: 'white' | 'black';\n value: string | undefined;\n onValueChange: (player: string) => void;\n members: SpaceMember[];\n}) => {\n const { themeMode } = useThemeContext();\n const iconFillMode =\n (side === 'black' && themeMode === 'light') || (side === 'white' && themeMode === 'dark') ? 'fill' : undefined;\n\n return (\n <Input.Root>\n <Input.Label>\n <CrownCross className={mx(getSize(6))} weight={iconFillMode} aria-label={`Chess icon for side ${side}`} />\n </Input.Label>\n <Select.Root value={value} onValueChange={onValueChange}>\n <Select.TriggerButton placeholder={'Select player'} />\n <Select.Portal>\n <Select.Content>\n <Select.Viewport>\n {members.map((member) => {\n const memberKey = member.identity.identityKey.toHex();\n const displayName = member.identity?.profile?.displayName || generateName(memberKey);\n return (\n <Select.Option key={memberKey} value={memberKey}>\n {displayName}\n </Select.Option>\n );\n })}\n </Select.Viewport>\n </Select.Content>\n </Select.Portal>\n </Select.Root>\n </Input.Root>\n );\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;AAIA,OAAOA,YAAW;AAElB,SAASC,gBAAgB;AACzB,SAASC,iBAAiB;;;;ACH1B,SAASC,kBAAkB;AAC3B,OAAOC,WAAW;AAElB,SAASC,oBAAoB;AAC7B,SAASC,kBAAgD;AACzD,SAASC,OAAOC,QAAQC,uBAAuB;AAC/C,SAASC,SAASC,UAAU;AAIrB,IAAMC,iBAAiB,CAAC,EAAEC,OAAOC,KAAI,MAAqC;;;AAC/E,UAAMC,UAAUC,WAAWH,MAAMI,GAAG;AAEpC,WACE,sBAAA,cAACC,OAAAA;MAAIC,MAAK;MAAOC,WAAU;OACzB,sBAAA,cAACF,OAAAA;MAAIC,MAAK;MAAOC,WAAU;OACzB,sBAAA,cAACC,cAAAA;MACCC,MAAK;MACLC,OAAOT,KAAKU;MACZC,eAAe,CAACC,WAAYZ,KAAKU,cAAcE;MAC/CX;SAGJ,sBAAA,cAACG,OAAAA;MAAIC,MAAK;MAAOC,WAAU;OACzB,sBAAA,cAACC,cAAAA;MACCC,MAAK;MACLC,OAAOT,KAAKa;MACZF,eAAe,CAACC,WAAYZ,KAAKa,cAAcD;MAC/CX;;;;;AAKV;AAEA,IAAMM,eAAe,CAAC,EACpBC,MACAC,OACAE,eACAV,QAAO,MAMR;;;AACC,UAAM,EAAEa,UAAS,IAAKC,gBAAAA;AACtB,UAAMC,eACHR,SAAS,WAAWM,cAAc,WAAaN,SAAS,WAAWM,cAAc,SAAU,SAASG;AAEvG,WACE,sBAAA,cAACC,MAAMC,MAAI,MACT,sBAAA,cAACD,MAAME,OAAK,MACV,sBAAA,cAACC,YAAAA;MAAWf,WAAWgB,GAAGC,QAAQ,CAAA,CAAA;MAAKC,QAAQR;MAAcS,cAAY,uBAAuBjB,IAAAA;SAElG,sBAAA,cAACkB,OAAOP,MAAI;MAACV;MAAcE;OACzB,sBAAA,cAACe,OAAOC,eAAa;MAACC,aAAa;QACnC,sBAAA,cAACF,OAAOG,QAAM,MACZ,sBAAA,cAACH,OAAOI,SAAO,MACb,sBAAA,cAACJ,OAAOK,UAAQ,MACb9B,QAAQ+B,IAAI,CAACC,WAAAA;AACZ,YAAMC,YAAYD,OAAOE,SAASC,YAAYC,MAAK;AACnD,YAAMC,cAAcL,OAAOE,UAAUI,SAASD,eAAeE,aAAaN,SAAAA;AAC1E,aACE,sBAAA,cAACR,OAAOe,QAAM;QAACtC,KAAK+B;QAAWzB,OAAOyB;SACnCI,WAAAA;IAGP,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;;;AAOd;;;ADlEA,IAAMI,iBAAiB,CAAC,EAAEC,KAAI,MAAsC;;;AAClE,UAAMC,QAAQC,SAASF,IAAAA;AACvB,QAAI,CAACC,OAAO;AACV,aAAO;IACT;AAEA,WACE,gBAAAE,OAAA,cAACC,UAAUC,SAAO,MAChB,gBAAAF,OAAA,cAACG,OAAAA;MAAIC,MAAK;MAAOC,WAAU;OACzB,gBAAAL,OAAA,cAACG,OAAAA,IAAAA,GAED,gBAAAH,OAAA,cAACG,OAAAA;MAAIE,WAAU;OACb,gBAAAL,OAAA,cAACM,gBAAAA;MAAeT;SAGlB,gBAAAG,OAAA,cAACO,gBAAAA;MAAeT;MAAcD;;;;;AAItC;AAEA,IAAA,yBAAeD;",
|
|
6
|
-
"names": ["React", "getSpace", "StackItem", "CrownCross", "React", "generateName", "useMembers", "Input", "Select", "useThemeContext", "getSize", "mx", "PlayerSelector", "space", "game", "members", "useMembers", "key", "div", "role", "className", "PlayerSelect", "side", "value", "playerWhite", "onValueChange", "player", "playerBlack", "themeMode", "useThemeContext", "iconFillMode", "undefined", "Input", "Root", "Label", "CrownCross", "mx", "getSize", "weight", "aria-label", "Select", "TriggerButton", "placeholder", "Portal", "Content", "Viewport", "map", "member", "memberKey", "identity", "identityKey", "toHex", "displayName", "profile", "generateName", "Option", "ChessContainer", "game", "space", "getSpace", "React", "StackItem", "Content", "div", "role", "className", "ChessComponent", "PlayerSelector"]
|
|
7
|
-
}
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ChessAction,
|
|
3
|
-
ChessType,
|
|
4
|
-
meta
|
|
5
|
-
} from "./chunk-A3WEUKPK.mjs";
|
|
6
|
-
|
|
7
|
-
// src/capabilities/artifact-definition.ts
|
|
8
|
-
import { Chess } from "chess.js";
|
|
9
|
-
import { pipe, Schema } from "effect";
|
|
10
|
-
import { createTool, ToolResult } from "@dxos/ai";
|
|
11
|
-
import { Capabilities, chain, contributes, createIntent } from "@dxos/app-framework";
|
|
12
|
-
import { ArtifactId, defineArtifact } from "@dxos/artifact";
|
|
13
|
-
import { createArtifactElement, VersionPin } from "@dxos/assistant";
|
|
14
|
-
import { Obj } from "@dxos/echo";
|
|
15
|
-
import { invariant } from "@dxos/invariant";
|
|
16
|
-
import { SpaceAction } from "@dxos/plugin-space/types";
|
|
17
|
-
import { Filter } from "@dxos/react-client/echo";
|
|
18
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-chess/src/capabilities/artifact-definition.ts";
|
|
19
|
-
var artifact_definition_default = () => {
|
|
20
|
-
const definition = defineArtifact({
|
|
21
|
-
id: `artifact:${meta.id}`,
|
|
22
|
-
name: meta.name,
|
|
23
|
-
description: "Provides a simple chess engine.",
|
|
24
|
-
instructions: `
|
|
25
|
-
- If the user's message relates to a chess game, you must return the chess game inside the artifact tag as a valid FEN string with no additional text.
|
|
26
|
-
- Always inspect the chess game at the start of every prompt realting to a chess game, as it might have changed since the interaction.
|
|
27
|
-
`,
|
|
28
|
-
schema: ChessType,
|
|
29
|
-
tools: [
|
|
30
|
-
createTool(meta.id, {
|
|
31
|
-
name: "create",
|
|
32
|
-
description: "Create a new chess game. Returns the artifact definition for the game.",
|
|
33
|
-
caption: "Creating chess game...",
|
|
34
|
-
schema: Schema.Struct({
|
|
35
|
-
fen: Schema.String.annotations({
|
|
36
|
-
description: "The state of the chess game in the FEN format."
|
|
37
|
-
})
|
|
38
|
-
}),
|
|
39
|
-
execute: async ({ fen }, { extensions }) => {
|
|
40
|
-
invariant(extensions?.space, "No space", {
|
|
41
|
-
F: __dxlog_file,
|
|
42
|
-
L: 47,
|
|
43
|
-
S: void 0,
|
|
44
|
-
A: [
|
|
45
|
-
"extensions?.space",
|
|
46
|
-
"'No space'"
|
|
47
|
-
]
|
|
48
|
-
});
|
|
49
|
-
invariant(extensions?.dispatch, "No intent dispatcher", {
|
|
50
|
-
F: __dxlog_file,
|
|
51
|
-
L: 48,
|
|
52
|
-
S: void 0,
|
|
53
|
-
A: [
|
|
54
|
-
"extensions?.dispatch",
|
|
55
|
-
"'No intent dispatcher'"
|
|
56
|
-
]
|
|
57
|
-
});
|
|
58
|
-
const intent = pipe(createIntent(ChessAction.Create, {
|
|
59
|
-
fen
|
|
60
|
-
}), chain(SpaceAction.AddObject, {
|
|
61
|
-
target: extensions.space
|
|
62
|
-
}));
|
|
63
|
-
const { data, error } = await extensions.dispatch(intent);
|
|
64
|
-
if (!data || error) {
|
|
65
|
-
return ToolResult.Error(error?.message ?? "Failed to create chess game");
|
|
66
|
-
}
|
|
67
|
-
return ToolResult.Success(createArtifactElement(data.id), [
|
|
68
|
-
VersionPin.createBlock(VersionPin.fromObject(data.object))
|
|
69
|
-
]);
|
|
70
|
-
}
|
|
71
|
-
}),
|
|
72
|
-
createTool(meta.id, {
|
|
73
|
-
name: "list",
|
|
74
|
-
description: "Query all active chess games.",
|
|
75
|
-
caption: "Getting games...",
|
|
76
|
-
schema: Schema.Struct({}),
|
|
77
|
-
execute: async (_, { extensions }) => {
|
|
78
|
-
invariant(extensions?.space, "No space", {
|
|
79
|
-
F: __dxlog_file,
|
|
80
|
-
L: 69,
|
|
81
|
-
S: void 0,
|
|
82
|
-
A: [
|
|
83
|
-
"extensions?.space",
|
|
84
|
-
"'No space'"
|
|
85
|
-
]
|
|
86
|
-
});
|
|
87
|
-
const { objects: games } = await extensions.space.db.query(Filter.type(ChessType)).run();
|
|
88
|
-
invariant(games.length > 0, "No chess games found", {
|
|
89
|
-
F: __dxlog_file,
|
|
90
|
-
L: 71,
|
|
91
|
-
S: void 0,
|
|
92
|
-
A: [
|
|
93
|
-
"games.length > 0",
|
|
94
|
-
"'No chess games found'"
|
|
95
|
-
]
|
|
96
|
-
});
|
|
97
|
-
return ToolResult.Success(games);
|
|
98
|
-
}
|
|
99
|
-
}),
|
|
100
|
-
createTool(meta.id, {
|
|
101
|
-
name: "inspect",
|
|
102
|
-
description: "Get the current state of the chess game.",
|
|
103
|
-
caption: "Inspecting game...",
|
|
104
|
-
schema: Schema.Struct({
|
|
105
|
-
id: ArtifactId
|
|
106
|
-
}),
|
|
107
|
-
execute: async ({ id }, { extensions }) => {
|
|
108
|
-
invariant(extensions?.space, "No space", {
|
|
109
|
-
F: __dxlog_file,
|
|
110
|
-
L: 82,
|
|
111
|
-
S: void 0,
|
|
112
|
-
A: [
|
|
113
|
-
"extensions?.space",
|
|
114
|
-
"'No space'"
|
|
115
|
-
]
|
|
116
|
-
});
|
|
117
|
-
const game = await extensions.space.db.query(Filter.ids(ArtifactId.toDXN(id, extensions.space.id).toString())).first();
|
|
118
|
-
invariant(Obj.instanceOf(ChessType, game), void 0, {
|
|
119
|
-
F: __dxlog_file,
|
|
120
|
-
L: 86,
|
|
121
|
-
S: void 0,
|
|
122
|
-
A: [
|
|
123
|
-
"Obj.instanceOf(ChessType, game)",
|
|
124
|
-
""
|
|
125
|
-
]
|
|
126
|
-
});
|
|
127
|
-
return ToolResult.Success(game.fen);
|
|
128
|
-
}
|
|
129
|
-
}),
|
|
130
|
-
createTool(meta.id, {
|
|
131
|
-
name: "move",
|
|
132
|
-
description: "Make a move in the chess game.",
|
|
133
|
-
caption: "Making chess move...",
|
|
134
|
-
schema: Schema.Struct({
|
|
135
|
-
id: ArtifactId,
|
|
136
|
-
move: Schema.String.annotations({
|
|
137
|
-
description: "The move to make in the chess game.",
|
|
138
|
-
examples: [
|
|
139
|
-
"e4",
|
|
140
|
-
"Bf3"
|
|
141
|
-
]
|
|
142
|
-
})
|
|
143
|
-
}),
|
|
144
|
-
execute: async ({ id, move }, { extensions }) => {
|
|
145
|
-
invariant(extensions?.space, "No space", {
|
|
146
|
-
F: __dxlog_file,
|
|
147
|
-
L: 103,
|
|
148
|
-
S: void 0,
|
|
149
|
-
A: [
|
|
150
|
-
"extensions?.space",
|
|
151
|
-
"'No space'"
|
|
152
|
-
]
|
|
153
|
-
});
|
|
154
|
-
const game = await extensions.space.db.query(Filter.ids(ArtifactId.toDXN(id, extensions.space.id).toString())).first();
|
|
155
|
-
invariant(Obj.instanceOf(ChessType, game), void 0, {
|
|
156
|
-
F: __dxlog_file,
|
|
157
|
-
L: 107,
|
|
158
|
-
S: void 0,
|
|
159
|
-
A: [
|
|
160
|
-
"Obj.instanceOf(ChessType, game)",
|
|
161
|
-
""
|
|
162
|
-
]
|
|
163
|
-
});
|
|
164
|
-
const board = new Chess(game.fen);
|
|
165
|
-
try {
|
|
166
|
-
board.move(move);
|
|
167
|
-
} catch (error) {
|
|
168
|
-
return ToolResult.Error(error.message);
|
|
169
|
-
}
|
|
170
|
-
game.pgn = board.pgn();
|
|
171
|
-
game.fen = board.fen();
|
|
172
|
-
return ToolResult.Success(game.fen);
|
|
173
|
-
}
|
|
174
|
-
})
|
|
175
|
-
]
|
|
176
|
-
});
|
|
177
|
-
return contributes(Capabilities.ArtifactDefinition, definition);
|
|
178
|
-
};
|
|
179
|
-
export {
|
|
180
|
-
artifact_definition_default as default
|
|
181
|
-
};
|
|
182
|
-
//# sourceMappingURL=artifact-definition-4AMZY5LQ.mjs.map
|