@dxos/plugin-chess 0.7.5-main.9d2a38b → 0.7.5-main.b19bfc8
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-XERPODLK.mjs +86 -0
- package/dist/lib/browser/ChessContainer-XERPODLK.mjs.map +7 -0
- package/dist/lib/browser/artifact-definition-AEIQ7Z36.mjs +174 -0
- package/dist/lib/browser/artifact-definition-AEIQ7Z36.mjs.map +7 -0
- package/dist/lib/browser/{chunk-VHSLLEH3.mjs → chunk-GKM6RRDX.mjs} +16 -10
- package/dist/lib/browser/chunk-GKM6RRDX.mjs.map +7 -0
- package/dist/lib/browser/chunk-R26FYVUS.mjs +8 -0
- package/dist/lib/browser/chunk-R26FYVUS.mjs.map +7 -0
- package/dist/lib/browser/chunk-VRWXC5L2.mjs +42 -0
- package/dist/lib/browser/chunk-VRWXC5L2.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +38 -19
- 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-ITP4OMBZ.mjs +42 -0
- package/dist/lib/browser/react-surface-ITP4OMBZ.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +3 -3
- package/dist/lib/node/ChessContainer-LEPLNICP.cjs +108 -0
- package/dist/lib/node/ChessContainer-LEPLNICP.cjs.map +7 -0
- package/dist/lib/node/artifact-definition-ZM5VDOVN.cjs +189 -0
- package/dist/lib/node/artifact-definition-ZM5VDOVN.cjs.map +7 -0
- package/dist/lib/node/{chunk-3BLH7NRV.cjs → chunk-3TTH3HKL.cjs} +19 -13
- package/dist/lib/node/chunk-3TTH3HKL.cjs.map +7 -0
- package/dist/lib/node/chunk-CSRNUKOH.cjs +74 -0
- package/dist/lib/node/chunk-CSRNUKOH.cjs.map +7 -0
- package/dist/lib/node/{react-surface-PO42G64E.cjs → chunk-ITDMCBQQ.cjs} +11 -22
- package/dist/lib/node/chunk-ITDMCBQQ.cjs.map +7 -0
- package/dist/lib/node/index.cjs +52 -32
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/{intent-resolver-VTB6P3IL.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-4G4PW5RU.cjs +62 -0
- package/dist/lib/node/react-surface-4G4PW5RU.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-S76WNBWN.mjs +87 -0
- package/dist/lib/node-esm/ChessContainer-S76WNBWN.mjs.map +7 -0
- package/dist/lib/node-esm/artifact-definition-NGQEQHJT.mjs +175 -0
- package/dist/lib/node-esm/artifact-definition-NGQEQHJT.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-6SEDGO5G.mjs +44 -0
- package/dist/lib/node-esm/chunk-6SEDGO5G.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-B72CIN6T.mjs +10 -0
- package/dist/lib/node-esm/chunk-B72CIN6T.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-M2CRYWX5.mjs → chunk-GQA2DRUZ.mjs} +16 -10
- package/dist/lib/node-esm/chunk-GQA2DRUZ.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +38 -19
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/{intent-resolver-MKEQFVZO.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-AEMVDP4R.mjs +43 -0
- package/dist/lib/node-esm/react-surface-AEMVDP4R.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-definition.d.ts +11 -0
- package/dist/types/src/capabilities/artifact-definition.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 +5 -0
- package/dist/types/src/components/ChessComponent.d.ts.map +1 -0
- package/dist/types/src/components/ChessContainer.d.ts +4 -4
- 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 +7 -0
- package/dist/types/src/components/PlayerSelector.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +4 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +3 -1
- 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/package.json +23 -20
- package/src/ChessPlugin.tsx +25 -20
- package/src/capabilities/artifact-definition.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 +49 -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 +2 -0
- package/src/index.ts +4 -1
- 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-JYXOZIDK.mjs +0 -505
- package/dist/lib/browser/ChessContainer-JYXOZIDK.mjs.map +0 -7
- package/dist/lib/browser/chunk-VHSLLEH3.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-FUAOSHHX.mjs +0 -19
- package/dist/lib/browser/intent-resolver-FUAOSHHX.mjs.map +0 -7
- package/dist/lib/browser/react-surface-63EO2PZO.mjs +0 -30
- package/dist/lib/browser/react-surface-63EO2PZO.mjs.map +0 -7
- package/dist/lib/node/ChessContainer-XRP7D63X.cjs +0 -518
- package/dist/lib/node/ChessContainer-XRP7D63X.cjs.map +0 -7
- package/dist/lib/node/chunk-3BLH7NRV.cjs.map +0 -7
- package/dist/lib/node/intent-resolver-VTB6P3IL.cjs.map +0 -7
- package/dist/lib/node/react-surface-PO42G64E.cjs.map +0 -7
- package/dist/lib/node-esm/ChessContainer-37QUCUTD.mjs +0 -507
- package/dist/lib/node-esm/ChessContainer-37QUCUTD.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-M2CRYWX5.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-MKEQFVZO.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-CXEBEDLT.mjs +0 -31
- package/dist/lib/node-esm/react-surface-CXEBEDLT.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 -13
- 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 -43
- package/src/components/Chessboard/Chessboard.tsx +0 -170
- 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
package/src/ChessPlugin.tsx
CHANGED
|
@@ -2,21 +2,15 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
defineModule,
|
|
10
|
-
definePlugin,
|
|
11
|
-
Events,
|
|
12
|
-
oneOf,
|
|
13
|
-
} from '@dxos/app-framework';
|
|
14
|
-
import { ClientCapabilities, ClientEvents } from '@dxos/plugin-client';
|
|
5
|
+
import { Capabilities, contributes, createIntent, defineModule, definePlugin, Events } from '@dxos/app-framework';
|
|
6
|
+
import { ClientEvents } from '@dxos/plugin-client';
|
|
7
|
+
import { SpaceCapabilities } from '@dxos/plugin-space';
|
|
8
|
+
import { defineObjectForm } from '@dxos/plugin-space/types';
|
|
15
9
|
|
|
16
|
-
import { IntentResolver, ReactSurface } from './capabilities';
|
|
10
|
+
import { ArtifactDefinition, IntentResolver, ReactSurface } from './capabilities';
|
|
17
11
|
import { CHESS_PLUGIN, meta } from './meta';
|
|
18
12
|
import translations from './translations';
|
|
19
|
-
import { ChessAction,
|
|
13
|
+
import { ChessAction, ChessType } from './types';
|
|
20
14
|
|
|
21
15
|
export const ChessPlugin = () =>
|
|
22
16
|
definePlugin(meta, [
|
|
@@ -27,30 +21,41 @@ export const ChessPlugin = () =>
|
|
|
27
21
|
}),
|
|
28
22
|
defineModule({
|
|
29
23
|
id: `${meta.id}/module/metadata`,
|
|
30
|
-
activatesOn:
|
|
24
|
+
activatesOn: Events.SetupMetadata,
|
|
31
25
|
activate: () =>
|
|
32
26
|
contributes(Capabilities.Metadata, {
|
|
33
|
-
id:
|
|
27
|
+
id: ChessType.typename,
|
|
34
28
|
metadata: {
|
|
35
|
-
createObject: (props: { name?: string }) => createIntent(ChessAction.Create, props),
|
|
36
29
|
placeholder: ['game title placeholder', { ns: CHESS_PLUGIN }],
|
|
37
30
|
icon: 'ph--shield-chevron--regular',
|
|
38
31
|
},
|
|
39
32
|
}),
|
|
40
33
|
}),
|
|
41
34
|
defineModule({
|
|
42
|
-
id: `${meta.id}/module/
|
|
43
|
-
activatesOn: ClientEvents.
|
|
44
|
-
activate: () =>
|
|
35
|
+
id: `${meta.id}/module/object-form`,
|
|
36
|
+
activatesOn: ClientEvents.SetupSchema,
|
|
37
|
+
activate: () =>
|
|
38
|
+
contributes(
|
|
39
|
+
SpaceCapabilities.ObjectForm,
|
|
40
|
+
defineObjectForm({
|
|
41
|
+
objectSchema: ChessType,
|
|
42
|
+
getIntent: () => createIntent(ChessAction.Create),
|
|
43
|
+
}),
|
|
44
|
+
),
|
|
45
45
|
}),
|
|
46
46
|
defineModule({
|
|
47
47
|
id: `${meta.id}/module/react-surface`,
|
|
48
|
-
activatesOn: Events.
|
|
48
|
+
activatesOn: Events.SetupReactSurface,
|
|
49
49
|
activate: ReactSurface,
|
|
50
50
|
}),
|
|
51
51
|
defineModule({
|
|
52
52
|
id: `${meta.id}/module/intent-resolver`,
|
|
53
|
-
activatesOn: Events.
|
|
53
|
+
activatesOn: Events.SetupIntentResolver,
|
|
54
54
|
activate: IntentResolver,
|
|
55
55
|
}),
|
|
56
|
+
defineModule({
|
|
57
|
+
id: `${meta.id}/module/artifact-definition`,
|
|
58
|
+
activatesOn: Events.SetupArtifactDefinition,
|
|
59
|
+
activate: ArtifactDefinition,
|
|
60
|
+
}),
|
|
56
61
|
]);
|
|
@@ -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
|
+
};
|
|
@@ -4,5 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
import { lazy } from '@dxos/app-framework';
|
|
6
6
|
|
|
7
|
+
export const ArtifactDefinition = lazy(() => import('./artifact-definition'));
|
|
7
8
|
export const IntentResolver = lazy(() => import('./intent-resolver'));
|
|
8
9
|
export const ReactSurface = lazy(() => import('./react-surface'));
|
|
@@ -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,49 @@
|
|
|
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
|
+
game.fen = model.game.fen();
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return false;
|
|
40
|
+
},
|
|
41
|
+
[model],
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<Board.Root model={model} onDrop={handleDrop}>
|
|
46
|
+
<Chessboard />
|
|
47
|
+
</Board.Root>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
@@ -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
|
};
|