@dxos/plugin-chess 0.8.4-main.84f28bd → 0.8.4-main.937b3ca
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/ChessboardContainer-IS4PXWJD.mjs +81 -0
- package/dist/lib/browser/ChessboardContainer-IS4PXWJD.mjs.map +7 -0
- package/dist/lib/browser/blueprint-definition-5RUGJ64Z.mjs +18 -0
- package/dist/lib/browser/blueprint-definition-5RUGJ64Z.mjs.map +7 -0
- package/dist/lib/browser/blueprints/index.mjs +11 -0
- package/dist/lib/browser/blueprints/index.mjs.map +7 -0
- package/dist/lib/browser/chunk-7OZ7J7LF.mjs +64 -0
- package/dist/lib/browser/chunk-7OZ7J7LF.mjs.map +7 -0
- package/dist/lib/browser/chunk-DH4WQRZH.mjs +229 -0
- package/dist/lib/browser/chunk-DH4WQRZH.mjs.map +7 -0
- package/dist/lib/browser/chunk-H3NUMCQ6.mjs +21 -0
- package/dist/lib/browser/chunk-H3NUMCQ6.mjs.map +7 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/browser/chunk-MV2GQK7M.mjs +8 -0
- package/dist/lib/browser/chunk-MV2GQK7M.mjs.map +7 -0
- package/dist/lib/browser/chunk-UUMPZ2FM.mjs +271 -0
- package/dist/lib/browser/chunk-UUMPZ2FM.mjs.map +7 -0
- package/dist/lib/browser/cli/index.mjs +28 -0
- package/dist/lib/browser/cli/index.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +69 -66
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react-surface-GQE7XMWH.mjs +37 -0
- package/dist/lib/browser/react-surface-GQE7XMWH.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +4 -7
- package/dist/lib/node-esm/ChessboardContainer-S3T6OE7P.mjs +82 -0
- package/dist/lib/node-esm/ChessboardContainer-S3T6OE7P.mjs.map +7 -0
- package/dist/lib/node-esm/blueprint-definition-RYKASBIJ.mjs +19 -0
- package/dist/lib/node-esm/blueprint-definition-RYKASBIJ.mjs.map +7 -0
- package/dist/lib/node-esm/blueprints/index.mjs +12 -0
- package/dist/lib/node-esm/blueprints/index.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-TD2SWK2H.mjs → chunk-DOBR6ILE.mjs} +3 -3
- package/dist/lib/node-esm/chunk-DOBR6ILE.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-F5OMIM4F.mjs +23 -0
- package/dist/lib/node-esm/chunk-F5OMIM4F.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-LKJ5GDAB.mjs +272 -0
- package/dist/lib/node-esm/chunk-LKJ5GDAB.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-NAYRVJR4.mjs +65 -0
- package/dist/lib/node-esm/chunk-NAYRVJR4.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-NFDJU7XQ.mjs +230 -0
- package/dist/lib/node-esm/chunk-NFDJU7XQ.mjs.map +7 -0
- package/dist/lib/node-esm/cli/index.mjs +29 -0
- package/dist/lib/node-esm/cli/index.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +69 -66
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/react-surface-7UZLIVN6.mjs +38 -0
- package/dist/lib/node-esm/react-surface-7UZLIVN6.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +4 -7
- package/dist/types/src/ChessPlugin.d.ts +2 -1
- package/dist/types/src/ChessPlugin.d.ts.map +1 -1
- package/dist/types/src/blueprints/chess-blueprint.d.ts +21 -0
- package/dist/types/src/blueprints/chess-blueprint.d.ts.map +1 -0
- package/dist/types/src/blueprints/functions/create.d.ts +15 -0
- package/dist/types/src/blueprints/functions/create.d.ts.map +1 -0
- package/dist/types/src/blueprints/functions/index.d.ts +5 -0
- package/dist/types/src/blueprints/functions/index.d.ts.map +1 -0
- package/dist/types/src/blueprints/functions/move.d.ts +8 -0
- package/dist/types/src/blueprints/functions/move.d.ts.map +1 -0
- package/dist/types/src/blueprints/functions/play.d.ts +9 -0
- package/dist/types/src/blueprints/functions/play.d.ts.map +1 -0
- package/dist/types/src/blueprints/functions/print.d.ts +8 -0
- package/dist/types/src/blueprints/functions/print.d.ts.map +1 -0
- package/dist/types/src/blueprints/index.d.ts +3 -0
- package/dist/types/src/blueprints/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/artifact-definition/artifact-definition.d.ts +12 -0
- package/dist/types/src/capabilities/artifact-definition/artifact-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/artifact-definition/index.d.ts +3 -0
- package/dist/types/src/capabilities/artifact-definition/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts +9 -0
- package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/blueprint-definition/index.d.ts +3 -0
- package/dist/types/src/capabilities/blueprint-definition/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +2 -3
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface/index.d.ts +3 -0
- package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts +5 -0
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -0
- package/dist/types/src/cli/index.d.ts +2 -0
- package/dist/types/src/cli/index.d.ts.map +1 -0
- package/dist/types/src/cli/plugin.d.ts +3 -0
- package/dist/types/src/cli/plugin.d.ts.map +1 -0
- package/dist/types/src/components/Card.stories.d.ts +15 -0
- package/dist/types/src/components/Card.stories.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard.d.ts +39 -0
- package/dist/types/src/components/Chessboard.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard.stories.d.ts +43 -5
- package/dist/types/src/components/Chessboard.stories.d.ts.map +1 -1
- package/dist/types/src/components/ChessboardArticle.d.ts +6 -0
- package/dist/types/src/components/ChessboardArticle.d.ts.map +1 -0
- package/dist/types/src/components/ChessboardContainer.d.ts +7 -0
- package/dist/types/src/components/ChessboardContainer.d.ts.map +1 -0
- package/dist/types/src/components/Info.d.ts +21 -0
- package/dist/types/src/components/Info.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +2 -5
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +2 -0
- 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/translations.d.ts +13 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Chess.d.ts +27 -0
- package/dist/types/src/types/Chess.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +1 -2
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +64 -39
- package/src/ChessPlugin.tsx +26 -52
- package/src/blueprints/chess-blueprint.ts +28 -0
- package/src/blueprints/functions/create.ts +38 -0
- package/src/blueprints/functions/index.ts +8 -0
- package/src/blueprints/functions/move.ts +49 -0
- package/src/blueprints/functions/play.ts +59 -0
- package/src/blueprints/functions/print.ts +42 -0
- package/src/blueprints/index.ts +6 -0
- package/src/capabilities/artifact-definition/artifact-definition.ts +135 -0
- package/src/capabilities/artifact-definition/index.ts +7 -0
- package/src/capabilities/blueprint-definition/blueprint-definition.ts +23 -0
- package/src/capabilities/blueprint-definition/index.ts +7 -0
- package/src/capabilities/index.ts +2 -5
- package/src/capabilities/react-surface/index.ts +7 -0
- package/src/capabilities/react-surface/react-surface.tsx +27 -0
- package/src/cli/index.ts +5 -0
- package/src/cli/plugin.ts +26 -0
- package/src/components/Card.stories.tsx +47 -0
- package/src/components/Chessboard.stories.tsx +36 -22
- package/src/components/Chessboard.tsx +188 -0
- package/src/components/ChessboardArticle.tsx +71 -0
- package/src/components/ChessboardContainer.tsx +40 -0
- package/src/components/Info.tsx +240 -0
- package/src/components/index.ts +2 -2
- package/src/index.ts +2 -0
- package/src/meta.ts +9 -7
- package/src/translations.ts +13 -2
- package/src/types/Chess.ts +58 -0
- package/src/types/index.ts +1 -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/intent-resolver-KQYYX44R.mjs +0 -28
- package/dist/lib/browser/intent-resolver-KQYYX44R.mjs.map +0 -7
- package/dist/lib/browser/react-surface-4TBVZUKU.mjs +0 -43
- package/dist/lib/browser/react-surface-4TBVZUKU.mjs.map +0 -7
- 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.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/react-surface-PAUEOIBL.mjs +0 -44
- package/dist/lib/node-esm/react-surface-PAUEOIBL.mjs.map +0 -7
- 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/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/PlayerSelector.tsx +0 -80
- package/src/types/schema.ts +0 -34
- package/src/types/types.ts +0 -20
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Chess } from 'chess.js';
|
|
6
|
-
import { pipe, Schema } from 'effect';
|
|
7
|
-
|
|
8
|
-
import { createTool, ToolResult } from '@dxos/ai';
|
|
9
|
-
import { Capabilities, chain, contributes, createIntent, type PromiseIntentDispatcher } from '@dxos/app-framework';
|
|
10
|
-
import { ArtifactId, defineArtifact } from '@dxos/artifact';
|
|
11
|
-
import { createArtifactElement, VersionPin } from '@dxos/assistant';
|
|
12
|
-
import { Obj } from '@dxos/echo';
|
|
13
|
-
import { invariant } from '@dxos/invariant';
|
|
14
|
-
import { SpaceAction } from '@dxos/plugin-space/types';
|
|
15
|
-
import { Filter, type Space } from '@dxos/react-client/echo';
|
|
16
|
-
|
|
17
|
-
import { meta } from '../meta';
|
|
18
|
-
import { ChessAction, ChessType } from '../types';
|
|
19
|
-
|
|
20
|
-
// TODO(burdon): Factor out.
|
|
21
|
-
declare global {
|
|
22
|
-
interface ToolContextExtensions {
|
|
23
|
-
space?: Space;
|
|
24
|
-
dispatch?: PromiseIntentDispatcher;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default () => {
|
|
29
|
-
const definition = defineArtifact({
|
|
30
|
-
id: `artifact:${meta.id}`,
|
|
31
|
-
name: meta.name,
|
|
32
|
-
description: 'Provides a simple chess engine.',
|
|
33
|
-
instructions: `
|
|
34
|
-
- 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.
|
|
35
|
-
- Always inspect the chess game at the start of every prompt realting to a chess game, as it might have changed since the interaction.
|
|
36
|
-
`,
|
|
37
|
-
schema: ChessType,
|
|
38
|
-
tools: [
|
|
39
|
-
createTool(meta.id, {
|
|
40
|
-
name: 'create',
|
|
41
|
-
description: 'Create a new chess game. Returns the artifact definition for the game.',
|
|
42
|
-
caption: 'Creating chess game...',
|
|
43
|
-
schema: Schema.Struct({
|
|
44
|
-
fen: Schema.String.annotations({ description: 'The state of the chess game in the FEN format.' }),
|
|
45
|
-
}),
|
|
46
|
-
execute: async ({ fen }, { extensions }) => {
|
|
47
|
-
invariant(extensions?.space, 'No space');
|
|
48
|
-
invariant(extensions?.dispatch, 'No intent dispatcher');
|
|
49
|
-
const intent = pipe(
|
|
50
|
-
createIntent(ChessAction.Create, { fen }),
|
|
51
|
-
chain(SpaceAction.AddObject, { target: extensions.space }),
|
|
52
|
-
);
|
|
53
|
-
const { data, error } = await extensions.dispatch(intent);
|
|
54
|
-
if (!data || error) {
|
|
55
|
-
return ToolResult.Error(error?.message ?? 'Failed to create chess game');
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return ToolResult.Success(createArtifactElement(data.id), [
|
|
59
|
-
VersionPin.createBlock(VersionPin.fromObject(data.object)),
|
|
60
|
-
]);
|
|
61
|
-
},
|
|
62
|
-
}),
|
|
63
|
-
createTool(meta.id, {
|
|
64
|
-
name: 'list',
|
|
65
|
-
description: 'Query all active chess games.',
|
|
66
|
-
caption: 'Getting games...',
|
|
67
|
-
schema: Schema.Struct({}),
|
|
68
|
-
execute: async (_, { extensions }) => {
|
|
69
|
-
invariant(extensions?.space, 'No space');
|
|
70
|
-
const { objects: games } = await extensions.space.db.query(Filter.type(ChessType)).run();
|
|
71
|
-
invariant(games.length > 0, 'No chess games found');
|
|
72
|
-
|
|
73
|
-
return ToolResult.Success(games);
|
|
74
|
-
},
|
|
75
|
-
}),
|
|
76
|
-
createTool(meta.id, {
|
|
77
|
-
name: 'inspect',
|
|
78
|
-
description: 'Get the current state of the chess game.',
|
|
79
|
-
caption: 'Inspecting game...',
|
|
80
|
-
schema: Schema.Struct({ id: ArtifactId }),
|
|
81
|
-
execute: async ({ id }, { extensions }) => {
|
|
82
|
-
invariant(extensions?.space, 'No space');
|
|
83
|
-
const game = await extensions.space.db
|
|
84
|
-
.query(Filter.ids(ArtifactId.toDXN(id, extensions.space.id).toString()))
|
|
85
|
-
.first();
|
|
86
|
-
invariant(Obj.instanceOf(ChessType, game));
|
|
87
|
-
|
|
88
|
-
return ToolResult.Success(game.fen);
|
|
89
|
-
},
|
|
90
|
-
}),
|
|
91
|
-
createTool(meta.id, {
|
|
92
|
-
name: 'move',
|
|
93
|
-
description: 'Make a move in the chess game.',
|
|
94
|
-
caption: 'Making chess move...',
|
|
95
|
-
schema: Schema.Struct({
|
|
96
|
-
id: ArtifactId,
|
|
97
|
-
move: Schema.String.annotations({
|
|
98
|
-
description: 'The move to make in the chess game.',
|
|
99
|
-
examples: ['e4', 'Bf3'],
|
|
100
|
-
}),
|
|
101
|
-
}),
|
|
102
|
-
execute: async ({ id, move }, { extensions }) => {
|
|
103
|
-
invariant(extensions?.space, 'No space');
|
|
104
|
-
const game = await extensions.space.db
|
|
105
|
-
.query(Filter.ids(ArtifactId.toDXN(id, extensions.space.id).toString()))
|
|
106
|
-
.first();
|
|
107
|
-
invariant(Obj.instanceOf(ChessType, game));
|
|
108
|
-
|
|
109
|
-
const board = new Chess(game.fen);
|
|
110
|
-
try {
|
|
111
|
-
board.move(move);
|
|
112
|
-
} catch (error: any) {
|
|
113
|
-
return ToolResult.Error(error.message);
|
|
114
|
-
}
|
|
115
|
-
game.pgn = board.pgn();
|
|
116
|
-
game.fen = board.fen();
|
|
117
|
-
return ToolResult.Success(game.fen);
|
|
118
|
-
},
|
|
119
|
-
}),
|
|
120
|
-
],
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
return contributes(Capabilities.ArtifactDefinition, definition);
|
|
124
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Chess } from 'chess.js';
|
|
6
|
-
|
|
7
|
-
import { Capabilities, contributes, createResolver } from '@dxos/app-framework';
|
|
8
|
-
import { Obj } from '@dxos/echo';
|
|
9
|
-
|
|
10
|
-
import { ChessAction, ChessType } from '../types';
|
|
11
|
-
|
|
12
|
-
export default () =>
|
|
13
|
-
contributes(
|
|
14
|
-
Capabilities.IntentResolver,
|
|
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: Obj.make(ChessType, { name, fen, pgn }),
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
},
|
|
25
|
-
}),
|
|
26
|
-
);
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React from 'react';
|
|
6
|
-
|
|
7
|
-
import { Capabilities, contributes, createSurface } from '@dxos/app-framework';
|
|
8
|
-
import { Obj } from '@dxos/echo';
|
|
9
|
-
|
|
10
|
-
import { ChessContainer, ChessComponent } from '../components';
|
|
11
|
-
import { meta } from '../meta';
|
|
12
|
-
import { ChessType } from '../types';
|
|
13
|
-
|
|
14
|
-
export default () =>
|
|
15
|
-
contributes(Capabilities.ReactSurface, [
|
|
16
|
-
createSurface({
|
|
17
|
-
id: meta.id,
|
|
18
|
-
role: ['article', 'section'],
|
|
19
|
-
// TODO(burdon): Could this be standardized so that we don't require a subject property (like below)?
|
|
20
|
-
filter: (data): data is { subject: ChessType } => Obj.instanceOf(ChessType, data.subject),
|
|
21
|
-
component: ({ data, role }) => <ChessContainer game={data.subject} role={role} />,
|
|
22
|
-
}),
|
|
23
|
-
createSurface({
|
|
24
|
-
id: 'plugin-chess',
|
|
25
|
-
// TODO(burdon): Change role to card?
|
|
26
|
-
role: 'canvas-node',
|
|
27
|
-
filter: Obj.instanceOf(ChessType),
|
|
28
|
-
component: ({ data }) => <ChessComponent game={data} />,
|
|
29
|
-
}),
|
|
30
|
-
]);
|
|
@@ -1,54 +0,0 @@
|
|
|
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 { log } from '@dxos/log';
|
|
9
|
-
import { getSpace } from '@dxos/react-client/echo';
|
|
10
|
-
import { ChessModel, Board, Chessboard, type BoardRootProps } from '@dxos/react-ui-gameboard';
|
|
11
|
-
|
|
12
|
-
import { type ChessType } from '../types';
|
|
13
|
-
|
|
14
|
-
export const ChessComponent = ({ game }: { game: ChessType }) => {
|
|
15
|
-
const model = useMemo(() => new ChessModel(), []);
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
if (!model || game.pgn !== model?.game.pgn()) {
|
|
18
|
-
const chess = new Chess();
|
|
19
|
-
if (game.pgn) {
|
|
20
|
-
try {
|
|
21
|
-
chess.loadPgn(game.pgn);
|
|
22
|
-
} catch (err) {
|
|
23
|
-
log.catch(err, { game });
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
model.initialize(chess.fen());
|
|
28
|
-
}
|
|
29
|
-
}, [game.pgn]);
|
|
30
|
-
|
|
31
|
-
const space = getSpace(game);
|
|
32
|
-
if (!space) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const handleDrop = useCallback<NonNullable<BoardRootProps['onDrop']>>(
|
|
37
|
-
(move) => {
|
|
38
|
-
if (model.makeMove(move)) {
|
|
39
|
-
game.pgn = model.game.pgn();
|
|
40
|
-
game.fen = model.game.fen();
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return false;
|
|
45
|
-
},
|
|
46
|
-
[model],
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<Board.Root model={model} onDrop={handleDrop}>
|
|
51
|
-
<Chessboard />
|
|
52
|
-
</Board.Root>
|
|
53
|
-
);
|
|
54
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React from 'react';
|
|
6
|
-
|
|
7
|
-
import { getSpace } from '@dxos/react-client/echo';
|
|
8
|
-
import { StackItem } from '@dxos/react-ui-stack';
|
|
9
|
-
|
|
10
|
-
import { ChessComponent } from './ChessComponent';
|
|
11
|
-
import { PlayerSelector } from './PlayerSelector';
|
|
12
|
-
import { type ChessType } from '../types';
|
|
13
|
-
|
|
14
|
-
const ChessContainer = ({ game }: { game: ChessType; role?: string }) => {
|
|
15
|
-
const space = getSpace(game);
|
|
16
|
-
if (!space) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
<StackItem.Content>
|
|
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>
|
|
31
|
-
</StackItem.Content>
|
|
32
|
-
);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export default ChessContainer;
|
|
@@ -1,67 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { CrownCross } from '@phosphor-icons/react';
|
|
6
|
-
import React from 'react';
|
|
7
|
-
|
|
8
|
-
import { generateName } from '@dxos/display-name';
|
|
9
|
-
import { useMembers, type Space, type SpaceMember } from '@dxos/react-client/echo';
|
|
10
|
-
import { Input, Select, useThemeContext } from '@dxos/react-ui';
|
|
11
|
-
import { getSize, mx } from '@dxos/react-ui-theme';
|
|
12
|
-
|
|
13
|
-
import { type ChessType } from '../types';
|
|
14
|
-
|
|
15
|
-
export const PlayerSelector = ({ space, game }: { space: Space; game: ChessType }) => {
|
|
16
|
-
const members = useMembers(space.key);
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<div role='none' className='grid grid-cols-2 gap-8'>
|
|
20
|
-
<div role='none' className='flex flex-row-reverse items-center gap-2'>
|
|
21
|
-
<PlayerSelect
|
|
22
|
-
side='white'
|
|
23
|
-
value={game.playerWhite}
|
|
24
|
-
onValueChange={(player) => (game.playerWhite = player)}
|
|
25
|
-
members={members}
|
|
26
|
-
/>
|
|
27
|
-
</div>
|
|
28
|
-
<div role='none' className='flex flex-row items-center gap-2'>
|
|
29
|
-
<PlayerSelect
|
|
30
|
-
side='black'
|
|
31
|
-
value={game.playerBlack}
|
|
32
|
-
onValueChange={(player) => (game.playerBlack = player)}
|
|
33
|
-
members={members}
|
|
34
|
-
/>
|
|
35
|
-
</div>
|
|
36
|
-
</div>
|
|
37
|
-
);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const PlayerSelect = ({
|
|
41
|
-
side,
|
|
42
|
-
value,
|
|
43
|
-
onValueChange,
|
|
44
|
-
members,
|
|
45
|
-
}: {
|
|
46
|
-
side: 'white' | 'black';
|
|
47
|
-
value: string | undefined;
|
|
48
|
-
onValueChange: (player: string) => void;
|
|
49
|
-
members: SpaceMember[];
|
|
50
|
-
}) => {
|
|
51
|
-
const { themeMode } = useThemeContext();
|
|
52
|
-
const iconFillMode =
|
|
53
|
-
(side === 'black' && themeMode === 'light') || (side === 'white' && themeMode === 'dark') ? 'fill' : undefined;
|
|
54
|
-
|
|
55
|
-
return (
|
|
56
|
-
<Input.Root>
|
|
57
|
-
<Input.Label>
|
|
58
|
-
<CrownCross className={mx(getSize(6))} weight={iconFillMode} aria-label={`Chess icon for side ${side}`} />
|
|
59
|
-
</Input.Label>
|
|
60
|
-
<Select.Root value={value} onValueChange={onValueChange}>
|
|
61
|
-
<Select.TriggerButton placeholder={'Select player'} />
|
|
62
|
-
<Select.Portal>
|
|
63
|
-
<Select.Content>
|
|
64
|
-
<Select.Viewport>
|
|
65
|
-
{members.map((member) => {
|
|
66
|
-
const memberKey = member.identity.identityKey.toHex();
|
|
67
|
-
const displayName = member.identity?.profile?.displayName || generateName(memberKey);
|
|
68
|
-
return (
|
|
69
|
-
<Select.Option key={memberKey} value={memberKey}>
|
|
70
|
-
{displayName}
|
|
71
|
-
</Select.Option>
|
|
72
|
-
);
|
|
73
|
-
})}
|
|
74
|
-
</Select.Viewport>
|
|
75
|
-
</Select.Content>
|
|
76
|
-
</Select.Portal>
|
|
77
|
-
</Select.Root>
|
|
78
|
-
</Input.Root>
|
|
79
|
-
);
|
|
80
|
-
};
|
package/src/types/schema.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Schema } from 'effect';
|
|
6
|
-
|
|
7
|
-
import { Type } from '@dxos/echo';
|
|
8
|
-
|
|
9
|
-
export const MoveSchema = Schema.mutable(
|
|
10
|
-
Schema.partial(
|
|
11
|
-
Schema.Struct({
|
|
12
|
-
source: Schema.String,
|
|
13
|
-
target: Schema.String,
|
|
14
|
-
piece: Schema.String,
|
|
15
|
-
}),
|
|
16
|
-
),
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
export const ChessType = Schema.Struct({
|
|
20
|
-
name: Schema.optional(Schema.String),
|
|
21
|
-
playerWhite: Schema.String,
|
|
22
|
-
playerBlack: Schema.String,
|
|
23
|
-
moves: Schema.mutable(Schema.Array(Schema.String)),
|
|
24
|
-
// TODO(wittjosiah): Remove. Redundant with moves.
|
|
25
|
-
pgn: Schema.String,
|
|
26
|
-
fen: Schema.String,
|
|
27
|
-
}).pipe(
|
|
28
|
-
Schema.partial,
|
|
29
|
-
Type.Obj({
|
|
30
|
-
typename: 'dxos.org/type/Chess',
|
|
31
|
-
version: '0.1.0',
|
|
32
|
-
}),
|
|
33
|
-
);
|
|
34
|
-
export interface ChessType extends Schema.Schema.Type<typeof ChessType> {}
|
package/src/types/types.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Schema } from 'effect';
|
|
6
|
-
|
|
7
|
-
import { ChessType } from './schema';
|
|
8
|
-
import { meta } from '../meta';
|
|
9
|
-
|
|
10
|
-
export namespace ChessAction {
|
|
11
|
-
export class Create extends Schema.TaggedClass<Create>()(`${meta.id}/action/create`, {
|
|
12
|
-
input: Schema.Struct({
|
|
13
|
-
name: Schema.optional(Schema.String),
|
|
14
|
-
fen: Schema.optional(Schema.String),
|
|
15
|
-
}),
|
|
16
|
-
output: Schema.Struct({
|
|
17
|
-
object: ChessType,
|
|
18
|
-
}),
|
|
19
|
-
}) {}
|
|
20
|
-
}
|