@dxos/plugin-chess 0.7.5-feature-compute.4d9d99a → 0.7.5-labs.071a3e2
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/lib/browser/ChessContainer-2MMUB5S7.mjs +86 -0
- package/dist/lib/browser/ChessContainer-2MMUB5S7.mjs.map +7 -0
- package/dist/lib/browser/artifact-LGQPNR6M.mjs +174 -0
- package/dist/lib/browser/artifact-LGQPNR6M.mjs.map +7 -0
- package/dist/lib/browser/chunk-672NU6IC.mjs +8 -0
- package/dist/lib/browser/chunk-672NU6IC.mjs.map +7 -0
- package/dist/lib/browser/{chunk-TRMP2D26.mjs → chunk-GKM6RRDX.mjs} +17 -11
- package/dist/lib/browser/chunk-GKM6RRDX.mjs.map +7 -0
- package/dist/lib/browser/chunk-RGPTBDH7.mjs +41 -0
- package/dist/lib/browser/chunk-RGPTBDH7.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +29 -28
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/intent-resolver-VPK5QRXH.mjs +28 -0
- package/dist/lib/browser/intent-resolver-VPK5QRXH.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react-surface-ZILDX6DE.mjs +42 -0
- package/dist/lib/browser/react-surface-ZILDX6DE.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +3 -3
- package/dist/lib/node/ChessContainer-CMYJDMSG.cjs +108 -0
- package/dist/lib/node/ChessContainer-CMYJDMSG.cjs.map +7 -0
- package/dist/lib/node/artifact-IKDPRF5X.cjs +189 -0
- package/dist/lib/node/artifact-IKDPRF5X.cjs.map +7 -0
- package/dist/lib/node/{chunk-NQRTWXBJ.cjs → chunk-3TTH3HKL.cjs} +19 -13
- package/dist/lib/node/chunk-3TTH3HKL.cjs.map +7 -0
- package/dist/lib/node/{chunk-DI3I3BWN.cjs → chunk-TEZPML34.cjs} +5 -5
- package/dist/lib/node/chunk-TEZPML34.cjs.map +7 -0
- package/dist/lib/node/{ChessContainer-TSXBWAED.cjs → chunk-YTD6SK5V.cjs} +37 -16
- package/dist/lib/node/chunk-YTD6SK5V.cjs.map +7 -0
- package/dist/lib/node/index.cjs +48 -44
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/{intent-resolver-7CF7WQVU.cjs → intent-resolver-PUM2BVGU.cjs} +20 -11
- package/dist/lib/node/intent-resolver-PUM2BVGU.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/{react-surface-X5VT3F77.cjs → react-surface-KYLF2XNL.cjs} +29 -18
- package/dist/lib/node/react-surface-KYLF2XNL.cjs.map +7 -0
- package/dist/lib/node/types/index.cjs +6 -6
- package/dist/lib/node/types/index.cjs.map +1 -1
- package/dist/lib/node-esm/ChessContainer-WV2CO5WO.mjs +87 -0
- package/dist/lib/node-esm/ChessContainer-WV2CO5WO.mjs.map +7 -0
- package/dist/lib/node-esm/artifact-3KNX2TLP.mjs +175 -0
- package/dist/lib/node-esm/artifact-3KNX2TLP.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-GJW6TXCL.mjs +43 -0
- package/dist/lib/node-esm/chunk-GJW6TXCL.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-OJWLLKVP.mjs → chunk-GQA2DRUZ.mjs} +17 -11
- package/dist/lib/node-esm/chunk-GQA2DRUZ.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-RMXO453C.mjs → chunk-YXXJHXSV.mjs} +2 -2
- package/dist/lib/node-esm/chunk-YXXJHXSV.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +29 -28
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/{intent-resolver-NWEEQVXB.mjs → intent-resolver-IR3YUZIG.mjs} +18 -9
- package/dist/lib/node-esm/intent-resolver-IR3YUZIG.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/react-surface-VI6Q4BJT.mjs +43 -0
- package/dist/lib/node-esm/react-surface-VI6Q4BJT.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +3 -3
- package/dist/types/src/ChessPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/artifact.d.ts +11 -0
- package/dist/types/src/capabilities/artifact.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +3 -2
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/ChessComponent.d.ts +6 -0
- package/dist/types/src/components/ChessComponent.d.ts.map +1 -0
- package/dist/types/src/components/ChessContainer.d.ts +4 -3
- package/dist/types/src/components/ChessContainer.d.ts.map +1 -1
- package/dist/types/src/components/ChessPanel.d.ts +11 -0
- package/dist/types/src/components/ChessPanel.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard.stories.d.ts +8 -0
- package/dist/types/src/components/Chessboard.stories.d.ts.map +1 -0
- package/dist/types/src/components/PlayerSelector.d.ts +8 -0
- package/dist/types/src/components/PlayerSelector.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +3 -3
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +1 -0
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/types/schema.d.ts +4 -2
- package/dist/types/src/types/schema.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +4 -3
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -20
- package/src/ChessPlugin.tsx +14 -17
- package/src/capabilities/artifact.ts +109 -0
- package/src/capabilities/index.ts +1 -0
- package/src/capabilities/intent-resolver.ts +13 -5
- package/src/capabilities/react-surface.tsx +12 -5
- package/src/components/ChessComponent.tsx +48 -0
- package/src/components/ChessContainer.tsx +14 -4
- package/src/components/ChessPanel.tsx +67 -0
- package/src/components/Chessboard.stories.tsx +39 -0
- package/src/components/{Chess.tsx → PlayerSelector.tsx} +3 -50
- package/src/components/index.ts +1 -2
- package/src/index.ts +1 -0
- package/src/meta.ts +3 -1
- package/src/translations.ts +2 -2
- package/src/types/schema.ts +3 -1
- package/src/types/types.ts +6 -5
- package/dist/lib/browser/ChessContainer-EG4RG2MG.mjs +0 -26
- package/dist/lib/browser/ChessContainer-EG4RG2MG.mjs.map +0 -7
- package/dist/lib/browser/chunk-6NAJOKLY.mjs +0 -548
- package/dist/lib/browser/chunk-6NAJOKLY.mjs.map +0 -7
- package/dist/lib/browser/chunk-E24G3MMK.mjs +0 -8
- package/dist/lib/browser/chunk-E24G3MMK.mjs.map +0 -7
- package/dist/lib/browser/chunk-TRMP2D26.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-HTTI4M6I.mjs +0 -19
- package/dist/lib/browser/intent-resolver-HTTI4M6I.mjs.map +0 -7
- package/dist/lib/browser/react-surface-O2LZGJGS.mjs +0 -28
- package/dist/lib/browser/react-surface-O2LZGJGS.mjs.map +0 -7
- package/dist/lib/node/ChessContainer-TSXBWAED.cjs.map +0 -7
- package/dist/lib/node/chunk-DI3I3BWN.cjs.map +0 -7
- package/dist/lib/node/chunk-NQRTWXBJ.cjs.map +0 -7
- package/dist/lib/node/chunk-P2LVKNZF.cjs +0 -574
- package/dist/lib/node/chunk-P2LVKNZF.cjs.map +0 -7
- package/dist/lib/node/intent-resolver-7CF7WQVU.cjs.map +0 -7
- package/dist/lib/node/react-surface-X5VT3F77.cjs.map +0 -7
- package/dist/lib/node-esm/ChessContainer-GP2KGMVU.mjs +0 -27
- package/dist/lib/node-esm/ChessContainer-GP2KGMVU.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-6DPPWWHM.mjs +0 -550
- package/dist/lib/node-esm/chunk-6DPPWWHM.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-OJWLLKVP.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-RMXO453C.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-NWEEQVXB.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-S4UTZKHT.mjs +0 -29
- package/dist/lib/node-esm/react-surface-S4UTZKHT.mjs.map +0 -7
- package/dist/types/src/components/Chess.d.ts +0 -9
- package/dist/types/src/components/Chess.d.ts.map +0 -1
- package/dist/types/src/components/Chessboard/Chessboard.d.ts +0 -37
- package/dist/types/src/components/Chessboard/Chessboard.d.ts.map +0 -1
- package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts +0 -24
- package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts.map +0 -1
- package/dist/types/src/components/Chessboard/index.d.ts +0 -2
- package/dist/types/src/components/Chessboard/index.d.ts.map +0 -1
- package/dist/types/src/components/Chessboard/pieces/custom.d.ts +0 -3
- package/dist/types/src/components/Chessboard/pieces/custom.d.ts.map +0 -1
- package/dist/types/src/components/Chessboard/pieces/index.d.ts +0 -4
- package/dist/types/src/components/Chessboard/pieces/index.d.ts.map +0 -1
- package/dist/types/src/components/Chessboard/pieces/phosphor.d.ts +0 -3
- package/dist/types/src/components/Chessboard/pieces/phosphor.d.ts.map +0 -1
- package/dist/types/src/components/Chessboard/pieces/riohacha.d.ts +0 -3
- package/dist/types/src/components/Chessboard/pieces/riohacha.d.ts.map +0 -1
- package/src/components/Chessboard/Chessboard.stories.tsx +0 -56
- package/src/components/Chessboard/Chessboard.tsx +0 -183
- package/src/components/Chessboard/index.ts +0 -5
- package/src/components/Chessboard/pieces/custom.tsx +0 -82
- package/src/components/Chessboard/pieces/index.ts +0 -7
- package/src/components/Chessboard/pieces/phosphor.tsx +0 -71
- package/src/components/Chessboard/pieces/riohacha.tsx +0 -166
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Chess } from 'chess.js';
|
|
6
|
+
import { pipe } from 'effect';
|
|
7
|
+
|
|
8
|
+
import { Capabilities, chain, contributes, createIntent, type PromiseIntentDispatcher } from '@dxos/app-framework';
|
|
9
|
+
import { defineArtifact, defineTool, ToolResult } from '@dxos/artifact';
|
|
10
|
+
import { createArtifactElement } from '@dxos/assistant';
|
|
11
|
+
import { isInstanceOf, ObjectId, S } from '@dxos/echo-schema';
|
|
12
|
+
import { invariant } from '@dxos/invariant';
|
|
13
|
+
import { SpaceAction } from '@dxos/plugin-space/types';
|
|
14
|
+
import { Filter, type Space } from '@dxos/react-client/echo';
|
|
15
|
+
|
|
16
|
+
import { ChessAction, ChessType } from '../types';
|
|
17
|
+
|
|
18
|
+
// TODO(burdon): Factor out.
|
|
19
|
+
declare global {
|
|
20
|
+
interface ToolContextExtensions {
|
|
21
|
+
space?: Space;
|
|
22
|
+
dispatch?: PromiseIntentDispatcher;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default () => {
|
|
27
|
+
const definition = defineArtifact({
|
|
28
|
+
id: 'plugin-chess',
|
|
29
|
+
instructions: `
|
|
30
|
+
Chess:
|
|
31
|
+
- 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.
|
|
32
|
+
`,
|
|
33
|
+
schema: ChessType,
|
|
34
|
+
tools: [
|
|
35
|
+
defineTool({
|
|
36
|
+
name: 'chess_new',
|
|
37
|
+
description: 'Create a new chess game. Returns the artifact definition for the game',
|
|
38
|
+
schema: S.Struct({
|
|
39
|
+
fen: S.String.annotations({ description: 'The state of the chess game in the FEN format.' }),
|
|
40
|
+
}),
|
|
41
|
+
execute: async ({ fen }, { extensions }) => {
|
|
42
|
+
invariant(extensions?.space, 'No space');
|
|
43
|
+
invariant(extensions?.dispatch, 'No intent dispatcher');
|
|
44
|
+
const intent = pipe(
|
|
45
|
+
createIntent(ChessAction.Create, { fen }),
|
|
46
|
+
chain(SpaceAction.AddObject, { target: extensions.space }),
|
|
47
|
+
);
|
|
48
|
+
const { data, error } = await extensions.dispatch(intent);
|
|
49
|
+
if (!data || error) {
|
|
50
|
+
return ToolResult.Error(error?.message ?? 'Failed to create chess game');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return ToolResult.Success(createArtifactElement(data.id));
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
defineTool({
|
|
57
|
+
name: 'chess_query',
|
|
58
|
+
description: 'Query all active chess games.',
|
|
59
|
+
schema: S.Struct({}),
|
|
60
|
+
execute: async (_, { extensions }) => {
|
|
61
|
+
invariant(extensions?.space, 'No space');
|
|
62
|
+
const { objects: games } = await extensions.space.db.query(Filter.schema(ChessType)).run();
|
|
63
|
+
invariant(games.length > 0, 'No chess games found');
|
|
64
|
+
return ToolResult.Success(games);
|
|
65
|
+
},
|
|
66
|
+
}),
|
|
67
|
+
defineTool({
|
|
68
|
+
name: 'chess_inspect',
|
|
69
|
+
description: 'Get the current state of the chess game.',
|
|
70
|
+
schema: S.Struct({ id: ObjectId }),
|
|
71
|
+
execute: async ({ id }, { extensions }) => {
|
|
72
|
+
invariant(extensions?.space, 'No space');
|
|
73
|
+
const { objects: games } = await extensions.space.db.query(Filter.schema(ChessType)).run();
|
|
74
|
+
const game = games.find((game) => game.id === id);
|
|
75
|
+
invariant(isInstanceOf(ChessType, game));
|
|
76
|
+
return ToolResult.Success(game.fen);
|
|
77
|
+
},
|
|
78
|
+
}),
|
|
79
|
+
defineTool({
|
|
80
|
+
name: 'chess_move',
|
|
81
|
+
description: 'Make a move in the chess game.',
|
|
82
|
+
schema: S.Struct({
|
|
83
|
+
id: ObjectId,
|
|
84
|
+
move: S.String.annotations({
|
|
85
|
+
description: 'The move to make in the chess game.',
|
|
86
|
+
examples: ['e4', 'Bf3'],
|
|
87
|
+
}),
|
|
88
|
+
}),
|
|
89
|
+
execute: async ({ id, move }, { extensions }) => {
|
|
90
|
+
invariant(extensions?.space, 'No space');
|
|
91
|
+
const { objects: games } = await extensions.space.db.query(Filter.schema(ChessType)).run();
|
|
92
|
+
const game = games.find((game) => game.id === id);
|
|
93
|
+
invariant(isInstanceOf(ChessType, game));
|
|
94
|
+
const board = new Chess(game.fen);
|
|
95
|
+
try {
|
|
96
|
+
board.move(move);
|
|
97
|
+
} catch (error: any) {
|
|
98
|
+
return ToolResult.Error(error.message);
|
|
99
|
+
}
|
|
100
|
+
game.pgn = board.pgn();
|
|
101
|
+
game.fen = board.fen();
|
|
102
|
+
return ToolResult.Success(game.fen);
|
|
103
|
+
},
|
|
104
|
+
}),
|
|
105
|
+
],
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return contributes(Capabilities.ArtifactDefinition, definition);
|
|
109
|
+
};
|
|
@@ -2,17 +2,25 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { Chess } from 'chess.js';
|
|
6
|
+
|
|
5
7
|
import { Capabilities, contributes, createResolver } from '@dxos/app-framework';
|
|
6
8
|
import { create } from '@dxos/live-object';
|
|
7
9
|
|
|
8
|
-
import { ChessAction,
|
|
10
|
+
import { ChessAction, ChessType } from '../types';
|
|
9
11
|
|
|
10
12
|
export default () =>
|
|
11
13
|
contributes(
|
|
12
14
|
Capabilities.IntentResolver,
|
|
13
|
-
createResolver(
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
createResolver({
|
|
16
|
+
intent: ChessAction.Create,
|
|
17
|
+
resolve: ({ name, fen }) => {
|
|
18
|
+
const pgn = fen ? new Chess(fen).pgn() : undefined;
|
|
19
|
+
return {
|
|
20
|
+
data: {
|
|
21
|
+
object: create(ChessType, { name, fen, pgn }),
|
|
22
|
+
},
|
|
23
|
+
};
|
|
16
24
|
},
|
|
17
|
-
})
|
|
25
|
+
}),
|
|
18
26
|
);
|
|
@@ -5,18 +5,25 @@
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
7
|
import { Capabilities, contributes, createSurface } from '@dxos/app-framework';
|
|
8
|
+
import { isInstanceOf } from '@dxos/echo-schema';
|
|
8
9
|
|
|
9
10
|
import { ChessContainer } from '../components';
|
|
11
|
+
import { ChessComponent } from '../components/ChessComponent';
|
|
10
12
|
import { CHESS_PLUGIN } from '../meta';
|
|
11
|
-
import {
|
|
13
|
+
import { ChessType, isObject } from '../types';
|
|
12
14
|
|
|
13
15
|
export default () =>
|
|
14
|
-
contributes(
|
|
15
|
-
Capabilities.ReactSurface,
|
|
16
|
+
contributes(Capabilities.ReactSurface, [
|
|
16
17
|
createSurface({
|
|
17
18
|
id: CHESS_PLUGIN,
|
|
18
19
|
role: ['article', 'section'],
|
|
19
|
-
filter: (data): data is { subject:
|
|
20
|
+
filter: (data): data is { subject: ChessType } => isObject(data.subject),
|
|
20
21
|
component: ({ data, role }) => <ChessContainer game={data.subject} role={role} />,
|
|
21
22
|
}),
|
|
22
|
-
|
|
23
|
+
createSurface({
|
|
24
|
+
id: 'plugin-chess',
|
|
25
|
+
role: 'canvas-node',
|
|
26
|
+
filter: (data): data is any => isInstanceOf(ChessType, data),
|
|
27
|
+
component: ({ data }) => <ChessComponent game={data} />,
|
|
28
|
+
}),
|
|
29
|
+
]);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Chess } from 'chess.js';
|
|
6
|
+
import React, { useCallback, useEffect, useMemo } from 'react';
|
|
7
|
+
|
|
8
|
+
import { getSpace } from '@dxos/react-client/echo';
|
|
9
|
+
import { ChessModel, Board, Chessboard, type BoardRootProps } from '@dxos/react-ui-gameboard';
|
|
10
|
+
|
|
11
|
+
import { type ChessType } from '../types';
|
|
12
|
+
|
|
13
|
+
export const ChessComponent = ({ game }: { game: ChessType }) => {
|
|
14
|
+
const model = useMemo(() => new ChessModel(), []);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (!model || game.pgn !== model?.game.pgn()) {
|
|
17
|
+
const chess = new Chess();
|
|
18
|
+
if (game.pgn) {
|
|
19
|
+
chess.loadPgn(game.pgn);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
model.initialize(chess.fen());
|
|
23
|
+
}
|
|
24
|
+
}, [game.pgn]);
|
|
25
|
+
|
|
26
|
+
const space = getSpace(game);
|
|
27
|
+
if (!space) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const handleDrop = useCallback<NonNullable<BoardRootProps['onDrop']>>(
|
|
32
|
+
(move) => {
|
|
33
|
+
if (model.makeMove(move)) {
|
|
34
|
+
game.pgn = model.game.pgn();
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return false;
|
|
39
|
+
},
|
|
40
|
+
[model],
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<Board.Root model={model} onDrop={handleDrop}>
|
|
45
|
+
<Chessboard />
|
|
46
|
+
</Board.Root>
|
|
47
|
+
);
|
|
48
|
+
};
|
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React
|
|
5
|
+
import React from 'react';
|
|
6
6
|
|
|
7
7
|
import { getSpace } from '@dxos/react-client/echo';
|
|
8
8
|
import { StackItem } from '@dxos/react-ui-stack';
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { ChessComponent } from './ChessComponent';
|
|
11
|
+
import { PlayerSelector } from './PlayerSelector';
|
|
12
|
+
import { type ChessType } from '../types';
|
|
11
13
|
|
|
12
|
-
const ChessContainer = ({ game
|
|
14
|
+
const ChessContainer = ({ game }: { game: ChessType; role?: string }) => {
|
|
13
15
|
const space = getSpace(game);
|
|
14
16
|
if (!space) {
|
|
15
17
|
return null;
|
|
@@ -17,7 +19,15 @@ const ChessContainer = ({ game, role }: Pick<ComponentProps<typeof Chess>, 'game
|
|
|
17
19
|
|
|
18
20
|
return (
|
|
19
21
|
<StackItem.Content toolbar={false}>
|
|
20
|
-
<
|
|
22
|
+
<div role='none' className='grid grid-rows-[60px_1fr_60px] grow overflow-hidden'>
|
|
23
|
+
<div />
|
|
24
|
+
|
|
25
|
+
<div className='flex m-4 overflow-hidden'>
|
|
26
|
+
<ChessComponent game={game} />
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
<PlayerSelector space={space} game={game} />
|
|
30
|
+
</div>
|
|
21
31
|
</StackItem.Content>
|
|
22
32
|
);
|
|
23
33
|
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { ArrowURightDown, Circle } from '@phosphor-icons/react';
|
|
6
|
+
import { type Color } from 'chess.js';
|
|
7
|
+
import React, { type FC } from 'react';
|
|
8
|
+
|
|
9
|
+
import { type ThemedClassName } from '@dxos/react-ui';
|
|
10
|
+
import { type ChessModel } from '@dxos/react-ui-gameboard';
|
|
11
|
+
import { getSize, mx } from '@dxos/react-ui-theme';
|
|
12
|
+
|
|
13
|
+
export type ChessPanelProps = ThemedClassName<{
|
|
14
|
+
model: ChessModel;
|
|
15
|
+
orientation?: Color;
|
|
16
|
+
onFlip?: () => void;
|
|
17
|
+
}>;
|
|
18
|
+
|
|
19
|
+
export const ChessPanel: FC<ChessPanelProps> = ({ classNames, model, orientation = 'w', onFlip }) => {
|
|
20
|
+
const game = model.game;
|
|
21
|
+
const history = game.history();
|
|
22
|
+
const label = game.isGameOver()
|
|
23
|
+
? game.isCheckmate()
|
|
24
|
+
? 'CHECKMATE'
|
|
25
|
+
: game.isStalemate()
|
|
26
|
+
? 'STALEMATE'
|
|
27
|
+
: 'DRAW'
|
|
28
|
+
: game.isCheck()
|
|
29
|
+
? 'CHECK'
|
|
30
|
+
: history.length
|
|
31
|
+
? `Move ${history.length}`
|
|
32
|
+
: '';
|
|
33
|
+
|
|
34
|
+
const Player = ({ color }: { color: Color }) => {
|
|
35
|
+
const turn = color === game.turn();
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<div className='flex items-center'>
|
|
39
|
+
<Circle
|
|
40
|
+
className={mx(getSize(4), turn && (game.isCheckmate() ? 'text-red-500' : 'text-green-500'))}
|
|
41
|
+
weight={turn ? 'fill' : 'thin'}
|
|
42
|
+
/>
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<div className={mx('flex flex-col', classNames)}>
|
|
49
|
+
<div className='flex items-center justify-between pl-2 pr-2 border-b' style={{ height: 32 }}>
|
|
50
|
+
<Player color={orientation === 'w' ? 'b' : 'w'} />
|
|
51
|
+
{onFlip && (
|
|
52
|
+
<button onClick={onFlip}>
|
|
53
|
+
<ArrowURightDown weight='thin' className={getSize(6)} />
|
|
54
|
+
</button>
|
|
55
|
+
)}
|
|
56
|
+
</div>
|
|
57
|
+
|
|
58
|
+
<div className='flex flex-col justify-center pl-2 font-thin' style={{ height: 40 }}>
|
|
59
|
+
{label}
|
|
60
|
+
</div>
|
|
61
|
+
|
|
62
|
+
<div className='flex items-center justify-between pl-2 pr-2 border-t' style={{ height: 32 }}>
|
|
63
|
+
<Player color={orientation} />
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
66
|
+
);
|
|
67
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import '@dxos-theme';
|
|
6
|
+
|
|
7
|
+
import { type Meta, type StoryObj } from '@storybook/react';
|
|
8
|
+
import React, { useMemo } from 'react';
|
|
9
|
+
|
|
10
|
+
import { Board, Chessboard, ChessModel } from '@dxos/react-ui-gameboard';
|
|
11
|
+
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
12
|
+
|
|
13
|
+
import { ChessPanel } from './ChessPanel';
|
|
14
|
+
|
|
15
|
+
const Render = () => {
|
|
16
|
+
const model = useMemo(() => new ChessModel(), []);
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<div className='flex grow mx-8 gap-8 items-center overflow-hidden'>
|
|
20
|
+
<Board.Root model={model} onDrop={(move) => model.makeMove(move)}>
|
|
21
|
+
<Chessboard />
|
|
22
|
+
</Board.Root>
|
|
23
|
+
<ChessPanel model={model} classNames='w-[200px]' />
|
|
24
|
+
</div>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const meta: Meta<typeof Chessboard> = {
|
|
29
|
+
title: 'plugins/plugin-chess/Chessboard',
|
|
30
|
+
component: Chessboard,
|
|
31
|
+
render: Render,
|
|
32
|
+
decorators: [withTheme, withLayout({ fullscreen: true })],
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type Story = StoryObj<typeof Chessboard>;
|
|
36
|
+
|
|
37
|
+
export default meta;
|
|
38
|
+
|
|
39
|
+
export const Default: Story = {};
|
|
@@ -3,63 +3,16 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { CrownCross } from '@phosphor-icons/react';
|
|
6
|
-
import
|
|
7
|
-
import React, { useEffect, useState } from 'react';
|
|
6
|
+
import React from 'react';
|
|
8
7
|
|
|
9
8
|
import { generateName } from '@dxos/display-name';
|
|
10
|
-
import { invariant } from '@dxos/invariant';
|
|
11
9
|
import { useMembers, type Space, type SpaceMember } from '@dxos/react-client/echo';
|
|
12
10
|
import { Input, Select, useThemeContext } from '@dxos/react-ui';
|
|
13
11
|
import { getSize, mx } from '@dxos/react-ui-theme';
|
|
14
12
|
|
|
15
|
-
import {
|
|
16
|
-
import { type GameType } from '../types';
|
|
13
|
+
import { type ChessType } from '../types';
|
|
17
14
|
|
|
18
|
-
const
|
|
19
|
-
const [model, setModel] = useState<ChessModel>();
|
|
20
|
-
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
if (!model || game.pgn !== model?.chess.pgn()) {
|
|
23
|
-
const chess = new ChessJs();
|
|
24
|
-
if (game.pgn) {
|
|
25
|
-
chess.loadPgn(game.pgn);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
setModel({ chess });
|
|
29
|
-
}
|
|
30
|
-
}, [game.pgn]);
|
|
31
|
-
|
|
32
|
-
const handleUpdate = (move: ChessMove) => {
|
|
33
|
-
invariant(model);
|
|
34
|
-
if (model.chess.move(move)) {
|
|
35
|
-
game!.pgn = model.chess.pgn();
|
|
36
|
-
setModel({ ...model });
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
return { model, handleUpdate };
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export const Chess = ({ space, game, playerSelector }: { space: Space; game: GameType; playerSelector?: boolean }) => {
|
|
44
|
-
const { model, handleUpdate } = useChessModel(game);
|
|
45
|
-
if (!model) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<div role='none' className='grid grid-rows-[60px_1fr_60px] grow overflow-hidden'>
|
|
51
|
-
<div />
|
|
52
|
-
<div className='flex grow justify-center overflow-hidden'>
|
|
53
|
-
<div className='flex grow max-w-[600px] items-center overflow-hidden'>
|
|
54
|
-
<Chessboard model={model} onUpdate={handleUpdate} />
|
|
55
|
-
</div>
|
|
56
|
-
</div>
|
|
57
|
-
{playerSelector && <PlayerSelector game={game} space={space} />}
|
|
58
|
-
</div>
|
|
59
|
-
);
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const PlayerSelector = ({ game, space }: { game: GameType; space: Space }) => {
|
|
15
|
+
export const PlayerSelector = ({ space, game }: { space: Space; game: ChessType }) => {
|
|
63
16
|
const members = useMembers(space.key);
|
|
64
17
|
|
|
65
18
|
return (
|
package/src/components/index.ts
CHANGED
package/src/index.ts
CHANGED
package/src/meta.ts
CHANGED
|
@@ -9,7 +9,9 @@ export const CHESS_PLUGIN = 'dxos.org/plugin/chess';
|
|
|
9
9
|
export const meta = {
|
|
10
10
|
id: CHESS_PLUGIN,
|
|
11
11
|
name: 'Chess',
|
|
12
|
-
description:
|
|
12
|
+
description:
|
|
13
|
+
'Chess is a simple plugin which allows you to render an interactive chessboard inside of a plank. This chessboard can be used for collaborative chess games, or for practice experiments with the LLM. ',
|
|
13
14
|
icon: 'ph--shield-chevron--regular',
|
|
14
15
|
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-chess',
|
|
16
|
+
screenshots: ['https://dxos.network/plugin-details-chess-dark.png'],
|
|
15
17
|
} satisfies PluginMeta;
|
package/src/translations.ts
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { CHESS_PLUGIN } from './meta';
|
|
6
|
-
import {
|
|
6
|
+
import { ChessType } from './types';
|
|
7
7
|
|
|
8
8
|
export default [
|
|
9
9
|
{
|
|
10
10
|
'en-US': {
|
|
11
|
-
[
|
|
11
|
+
[ChessType.typename]: {
|
|
12
12
|
'typename label': 'Game',
|
|
13
13
|
},
|
|
14
14
|
[CHESS_PLUGIN]: {
|
package/src/types/schema.ts
CHANGED
|
@@ -14,13 +14,15 @@ export const MoveSchema = S.mutable(
|
|
|
14
14
|
),
|
|
15
15
|
);
|
|
16
16
|
|
|
17
|
-
export class
|
|
17
|
+
export class ChessType extends TypedObject({ typename: 'dxos.org/type/Chess', version: '0.1.0' })(
|
|
18
18
|
{
|
|
19
19
|
name: S.optional(S.String),
|
|
20
20
|
playerWhite: S.String,
|
|
21
21
|
playerBlack: S.String,
|
|
22
22
|
moves: S.mutable(S.Array(S.String)),
|
|
23
|
+
// TODO(wittjosiah): Remove. Redundant with moves.
|
|
23
24
|
pgn: S.String,
|
|
25
|
+
fen: S.String,
|
|
24
26
|
},
|
|
25
27
|
{ partial: true },
|
|
26
28
|
) {}
|
package/src/types/types.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { S } from '@dxos/echo-schema';
|
|
5
|
+
import { isInstanceOf, S } from '@dxos/echo-schema';
|
|
6
6
|
import { isReactiveObject } from '@dxos/live-object';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { ChessType } from './schema';
|
|
9
9
|
import { CHESS_PLUGIN } from '../meta';
|
|
10
10
|
|
|
11
11
|
export namespace ChessAction {
|
|
@@ -14,13 +14,14 @@ export namespace ChessAction {
|
|
|
14
14
|
export class Create extends S.TaggedClass<Create>()(`${CHESS_ACTION}/create`, {
|
|
15
15
|
input: S.Struct({
|
|
16
16
|
name: S.optional(S.String),
|
|
17
|
+
fen: S.optional(S.String),
|
|
17
18
|
}),
|
|
18
19
|
output: S.Struct({
|
|
19
|
-
object:
|
|
20
|
+
object: ChessType,
|
|
20
21
|
}),
|
|
21
22
|
}) {}
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
export const isObject = (object: unknown): object is
|
|
25
|
-
return isReactiveObject(object) && object
|
|
25
|
+
export const isObject = (object: unknown): object is typeof ChessType => {
|
|
26
|
+
return isReactiveObject(object) && isInstanceOf(ChessType, object);
|
|
26
27
|
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Chess
|
|
3
|
-
} from "./chunk-6NAJOKLY.mjs";
|
|
4
|
-
|
|
5
|
-
// packages/plugins/plugin-chess/src/components/ChessContainer.tsx
|
|
6
|
-
import React from "react";
|
|
7
|
-
import { getSpace } from "@dxos/react-client/echo";
|
|
8
|
-
import { StackItem } from "@dxos/react-ui-stack";
|
|
9
|
-
var ChessContainer = ({ game, role }) => {
|
|
10
|
-
const space = getSpace(game);
|
|
11
|
-
if (!space) {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
return /* @__PURE__ */ React.createElement(StackItem.Content, {
|
|
15
|
-
toolbar: false
|
|
16
|
-
}, /* @__PURE__ */ React.createElement(Chess, {
|
|
17
|
-
game,
|
|
18
|
-
space,
|
|
19
|
-
playerSelector: role === "article"
|
|
20
|
-
}));
|
|
21
|
-
};
|
|
22
|
-
var ChessContainer_default = ChessContainer;
|
|
23
|
-
export {
|
|
24
|
-
ChessContainer_default as default
|
|
25
|
-
};
|
|
26
|
-
//# sourceMappingURL=ChessContainer-EG4RG2MG.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/ChessContainer.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { type ComponentProps } from 'react';\n\nimport { getSpace } from '@dxos/react-client/echo';\nimport { StackItem } from '@dxos/react-ui-stack';\n\nimport { Chess } from './Chess';\n\nconst ChessContainer = ({ game, role }: Pick<ComponentProps<typeof Chess>, 'game'> & { role?: string }) => {\n const space = getSpace(game);\n if (!space) {\n return null;\n }\n\n return (\n <StackItem.Content toolbar={false}>\n <Chess game={game} space={space} playerSelector={role === 'article'} />\n </StackItem.Content>\n );\n};\n\nexport default ChessContainer;\n"],
|
|
5
|
-
"mappings": ";;;;;AAIA,OAAOA,WAAoC;AAE3C,SAASC,gBAAgB;AACzB,SAASC,iBAAiB;AAI1B,IAAMC,iBAAiB,CAAC,EAAEC,MAAMC,KAAI,MAAkE;AACpG,QAAMC,QAAQC,SAASH,IAAAA;AACvB,MAAI,CAACE,OAAO;AACV,WAAO;EACT;AAEA,SACE,sBAAA,cAACE,UAAUC,SAAO;IAACC,SAAS;KAC1B,sBAAA,cAACC,OAAAA;IAAMP;IAAYE;IAAcM,gBAAgBP,SAAS;;AAGhE;AAEA,IAAA,yBAAeF;",
|
|
6
|
-
"names": ["React", "getSpace", "StackItem", "ChessContainer", "game", "role", "space", "getSpace", "StackItem", "Content", "toolbar", "Chess", "playerSelector"]
|
|
7
|
-
}
|