@dxos/plugin-chess 0.8.4-main.e8ec1fe → 0.8.4-main.effb148878
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-2MAUPQEP.mjs +148 -0
- package/dist/lib/neutral/chunk-2MAUPQEP.mjs.map +7 -0
- package/dist/lib/neutral/chunk-47NTXLZ4.mjs +8 -0
- package/dist/lib/neutral/chunk-47NTXLZ4.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/{browser/chunk-DUO4WTAM.mjs → neutral/chunk-V4UMIQ6K.mjs} +12 -9
- 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-UMYAK7LT.mjs +41 -0
- package/dist/lib/neutral/game-variant-UMYAK7LT.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +18 -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-CSQAYS6C.mjs +37 -0
- package/dist/lib/neutral/move-CSQAYS6C.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-MAQS65O7.mjs +46 -0
- package/dist/lib/neutral/play-MAQS65O7.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-EAPXOLGE.mjs +29 -0
- package/dist/lib/neutral/print-EAPXOLGE.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 +35 -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 +5 -5
- package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -1
- 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 -4
- 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.d.ts → Chessboard/Chessboard.d.ts} +10 -10
- 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/{Info.d.ts → Chessboard/Info.d.ts} +5 -6
- 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 +0 -1
- 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/{components/Card.stories.d.ts → containers/ChessCard/ChessCard.stories.d.ts} +2 -9
- 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 +1 -4
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -2
- 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 -22
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Chess.d.ts +12 -22
- package/dist/types/src/types/Chess.d.ts.map +1 -1
- package/dist/types/src/types/ChessOperation.d.ts +29 -0
- package/dist/types/src/types/ChessOperation.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +1 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +117 -58
- package/src/ChessPlugin.node.ts +23 -0
- package/src/ChessPlugin.test.ts +50 -0
- package/src/ChessPlugin.tsx +19 -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 +11 -28
- package/src/capabilities/game-variant.ts +43 -0
- package/src/capabilities/index.ts +9 -6
- package/src/capabilities/operation-handler.ts +14 -0
- package/src/components/Chessboard/Chessboard.stories.tsx +94 -0
- package/src/components/{Chessboard.tsx → Chessboard/Chessboard.tsx} +34 -31
- package/src/components/{Info.tsx → Chessboard/Info.tsx} +33 -76
- package/src/components/Chessboard/index.ts +5 -0
- package/src/components/Chessboard/types.ts +18 -0
- package/src/components/index.ts +1 -5
- 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 +1 -5
- package/src/meta.ts +9 -3
- 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 +19 -20
- package/src/types/Chess.ts +25 -29
- package/src/types/ChessOperation.ts +88 -0
- package/src/types/index.ts +1 -1
- package/dist/lib/browser/ChessboardContainer-5YXEM4VR.mjs +0 -96
- package/dist/lib/browser/ChessboardContainer-5YXEM4VR.mjs.map +0 -7
- package/dist/lib/browser/blueprint-definition-FD4TL5EE.mjs +0 -11
- package/dist/lib/browser/chunk-5DOZV3PW.mjs +0 -294
- package/dist/lib/browser/chunk-5DOZV3PW.mjs.map +0 -7
- package/dist/lib/browser/chunk-DUO4WTAM.mjs.map +0 -7
- package/dist/lib/browser/chunk-FBLAVAMY.mjs +0 -84
- package/dist/lib/browser/chunk-FBLAVAMY.mjs.map +0 -7
- package/dist/lib/browser/chunk-Q5TZCIH7.mjs +0 -8
- package/dist/lib/browser/chunk-Q5TZCIH7.mjs.map +0 -7
- package/dist/lib/browser/chunk-TIIGNOGK.mjs +0 -169
- package/dist/lib/browser/chunk-TIIGNOGK.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -124
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-GXZN2EBT.mjs +0 -25
- package/dist/lib/browser/intent-resolver-GXZN2EBT.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/react-surface-KTTAUHAA.mjs +0 -38
- package/dist/lib/browser/react-surface-KTTAUHAA.mjs.map +0 -7
- package/dist/lib/browser/types/index.mjs +0 -10
- package/dist/lib/node-esm/ChessboardContainer-7OQ6TOKB.mjs +0 -97
- package/dist/lib/node-esm/ChessboardContainer-7OQ6TOKB.mjs.map +0 -7
- package/dist/lib/node-esm/blueprint-definition-O7ZM3HUF.mjs +0 -12
- package/dist/lib/node-esm/chunk-F4C2HVZL.mjs +0 -295
- package/dist/lib/node-esm/chunk-F4C2HVZL.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-KNOOJFIR.mjs +0 -29
- package/dist/lib/node-esm/chunk-KNOOJFIR.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-MP3A3AGA.mjs +0 -85
- package/dist/lib/node-esm/chunk-MP3A3AGA.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-RTCAAOLF.mjs +0 -170
- package/dist/lib/node-esm/chunk-RTCAAOLF.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-VVXTAVIS.mjs +0 -10
- package/dist/lib/node-esm/chunk-VVXTAVIS.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -125
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-HK5L6P6Z.mjs +0 -26
- package/dist/lib/node-esm/intent-resolver-HK5L6P6Z.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/react-surface-VO4PSY6O.mjs +0 -39
- package/dist/lib/node-esm/react-surface-VO4PSY6O.mjs.map +0 -7
- package/dist/lib/node-esm/types/index.mjs +0 -11
- 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/Card.stories.d.ts.map +0 -1
- package/dist/types/src/components/Chessboard.d.ts.map +0 -1
- package/dist/types/src/components/Chessboard.stories.d.ts +0 -44
- package/dist/types/src/components/Chessboard.stories.d.ts.map +0 -1
- package/dist/types/src/components/ChessboardArticle.d.ts +0 -7
- package/dist/types/src/components/ChessboardArticle.d.ts.map +0 -1
- package/dist/types/src/components/ChessboardContainer.d.ts +0 -9
- package/dist/types/src/components/ChessboardContainer.d.ts.map +0 -1
- package/dist/types/src/components/Info.d.ts.map +0 -1
- package/dist/types/src/functions/create.d.ts +0 -14
- package/dist/types/src/functions/create.d.ts.map +0 -1
- package/dist/types/src/functions/index.d.ts +0 -4
- package/dist/types/src/functions/index.d.ts.map +0 -1
- package/dist/types/src/functions/move.d.ts +0 -8
- package/dist/types/src/functions/move.d.ts.map +0 -1
- package/dist/types/src/functions/play.d.ts +0 -9
- package/dist/types/src/functions/play.d.ts.map +0 -1
- package/dist/types/src/types/ChessAction.d.ts +0 -24
- package/dist/types/src/types/ChessAction.d.ts.map +0 -1
- package/src/capabilities/artifact-definition.ts +0 -129
- package/src/capabilities/intent-resolver.ts +0 -22
- package/src/capabilities/react-surface.tsx +0 -23
- package/src/components/Card.stories.tsx +0 -66
- package/src/components/Chessboard.stories.tsx +0 -49
- package/src/components/ChessboardArticle.tsx +0 -68
- package/src/components/ChessboardContainer.tsx +0 -44
- package/src/functions/create.ts +0 -32
- package/src/functions/index.ts +0 -7
- package/src/functions/move.ts +0 -45
- package/src/functions/play.ts +0 -55
- package/src/types/ChessAction.ts +0 -19
- /package/dist/lib/{browser/blueprint-definition-FD4TL5EE.mjs.map → neutral/ChessPlugin.mjs.map} +0 -0
- /package/dist/lib/{browser/types → neutral/blueprints}/index.mjs.map +0 -0
- /package/dist/lib/{node-esm/blueprint-definition-O7ZM3HUF.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
- /package/dist/lib/{node-esm/types → neutral}/index.mjs.map +0 -0
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// ISSUE(burdon): defineArtifact
|
|
6
|
-
// @ts-nocheck
|
|
7
|
-
|
|
8
|
-
import { Chess as ChessJS } from 'chess.js';
|
|
9
|
-
import * as Function from 'effect/Function';
|
|
10
|
-
import * as Schema from 'effect/Schema';
|
|
11
|
-
|
|
12
|
-
import { ToolResult, createTool } from '@dxos/ai';
|
|
13
|
-
import { Capabilities, type PromiseIntentDispatcher, chain, contributes, createIntent } from '@dxos/app-framework';
|
|
14
|
-
import { ArtifactId, VersionPin, createArtifactElement } from '@dxos/assistant';
|
|
15
|
-
import { defineArtifact } from '@dxos/blueprints';
|
|
16
|
-
import { Obj } from '@dxos/echo';
|
|
17
|
-
import { invariant } from '@dxos/invariant';
|
|
18
|
-
import { SpaceAction } from '@dxos/plugin-space/types';
|
|
19
|
-
import { Filter, type Space } from '@dxos/react-client/echo';
|
|
20
|
-
import { trim } from '@dxos/util';
|
|
21
|
-
|
|
22
|
-
import { meta } from '../meta';
|
|
23
|
-
import { Chess, ChessAction } from '../types';
|
|
24
|
-
|
|
25
|
-
// TODO(burdon): Factor out.
|
|
26
|
-
declare global {
|
|
27
|
-
interface ToolContextExtensions {
|
|
28
|
-
space?: Space;
|
|
29
|
-
dispatch?: PromiseIntentDispatcher;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export default () => {
|
|
34
|
-
const definition = defineArtifact({
|
|
35
|
-
id: `artifact:${meta.id}`,
|
|
36
|
-
name: meta.name,
|
|
37
|
-
description: 'Provides a simple chess engine.',
|
|
38
|
-
instructions: trim`
|
|
39
|
-
- 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.
|
|
40
|
-
- Always inspect the chess game at the start of every prompt realting to a chess game, as it might have changed since the interaction.
|
|
41
|
-
`,
|
|
42
|
-
schema: Chess.Game,
|
|
43
|
-
tools: [
|
|
44
|
-
createTool(meta.id, {
|
|
45
|
-
name: 'create',
|
|
46
|
-
description: 'Create a new chess game. Returns the artifact definition for the game.',
|
|
47
|
-
caption: 'Creating chess game...',
|
|
48
|
-
schema: Schema.Struct({
|
|
49
|
-
pgn: Schema.String.annotations({ description: 'The state of the chess game in the PGN format.' }),
|
|
50
|
-
}),
|
|
51
|
-
execute: async ({ pgn }, { extensions }) => {
|
|
52
|
-
invariant(extensions?.space, 'No space');
|
|
53
|
-
invariant(extensions?.dispatch, 'No intent dispatcher');
|
|
54
|
-
const intent = Function.pipe(
|
|
55
|
-
createIntent(ChessAction.Create, { pgn }),
|
|
56
|
-
chain(SpaceAction.AddObject, { target: extensions.space }),
|
|
57
|
-
);
|
|
58
|
-
const { data, error } = await extensions.dispatch(intent);
|
|
59
|
-
if (!data || error) {
|
|
60
|
-
return ToolResult.Error(error?.message ?? 'Failed to create chess game');
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return ToolResult.Success(createArtifactElement(data.id), [
|
|
64
|
-
VersionPin.createBlock(VersionPin.fromObject(data.object)),
|
|
65
|
-
]);
|
|
66
|
-
},
|
|
67
|
-
}),
|
|
68
|
-
createTool(meta.id, {
|
|
69
|
-
name: 'list',
|
|
70
|
-
description: 'Query all active chess games.',
|
|
71
|
-
caption: 'Getting games...',
|
|
72
|
-
schema: Schema.Struct({}),
|
|
73
|
-
execute: async (_, { extensions }) => {
|
|
74
|
-
invariant(extensions?.space, 'No space');
|
|
75
|
-
const { objects: games } = await extensions.space.db.query(Filter.type(Chess.Game)).run();
|
|
76
|
-
invariant(games.length > 0, 'No chess games found');
|
|
77
|
-
|
|
78
|
-
return ToolResult.Success(games);
|
|
79
|
-
},
|
|
80
|
-
}),
|
|
81
|
-
createTool(meta.id, {
|
|
82
|
-
name: 'inspect',
|
|
83
|
-
description: 'Get the current state of the chess game.',
|
|
84
|
-
caption: 'Inspecting game...',
|
|
85
|
-
schema: Schema.Struct({ id: ArtifactId }),
|
|
86
|
-
execute: async ({ id }, { extensions }) => {
|
|
87
|
-
invariant(extensions?.space, 'No space');
|
|
88
|
-
const game = await extensions.space.db
|
|
89
|
-
.query(Filter.ids(ArtifactId.toDXN(id, extensions.space.id).toString()))
|
|
90
|
-
.first();
|
|
91
|
-
invariant(Obj.instanceOf(Chess.Game, game));
|
|
92
|
-
|
|
93
|
-
return ToolResult.Success(game.pgn);
|
|
94
|
-
},
|
|
95
|
-
}),
|
|
96
|
-
createTool(meta.id, {
|
|
97
|
-
name: 'move',
|
|
98
|
-
description: 'Make a move in the chess game.',
|
|
99
|
-
caption: 'Making chess move...',
|
|
100
|
-
schema: Schema.Struct({
|
|
101
|
-
id: ArtifactId,
|
|
102
|
-
move: Schema.String.annotations({
|
|
103
|
-
description: 'The move to make in the chess game.',
|
|
104
|
-
examples: ['e4', 'Bf3'],
|
|
105
|
-
}),
|
|
106
|
-
}),
|
|
107
|
-
execute: async ({ id, move }, { extensions }) => {
|
|
108
|
-
invariant(extensions?.space, 'No space');
|
|
109
|
-
const game = await extensions.space.db
|
|
110
|
-
.query(Filter.ids(ArtifactId.toDXN(id, extensions.space.id).toString()))
|
|
111
|
-
.first();
|
|
112
|
-
invariant(Obj.instanceOf(Chess.Game, game));
|
|
113
|
-
|
|
114
|
-
const chess = new ChessJS(game.pgn);
|
|
115
|
-
try {
|
|
116
|
-
chess.move(move);
|
|
117
|
-
} catch (error: any) {
|
|
118
|
-
return ToolResult.Error(error.message);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
game.pgn = chess.pgn();
|
|
122
|
-
return ToolResult.Success(game.pgn);
|
|
123
|
-
},
|
|
124
|
-
}),
|
|
125
|
-
],
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
return contributes(Capabilities.ArtifactDefinition, definition);
|
|
129
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Capabilities, contributes, createResolver } from '@dxos/app-framework';
|
|
6
|
-
|
|
7
|
-
import { Chess, ChessAction } from '../types';
|
|
8
|
-
|
|
9
|
-
export default () =>
|
|
10
|
-
contributes(
|
|
11
|
-
Capabilities.IntentResolver,
|
|
12
|
-
createResolver({
|
|
13
|
-
intent: ChessAction.Create,
|
|
14
|
-
resolve: ({ name, pgn }) => {
|
|
15
|
-
return {
|
|
16
|
-
data: {
|
|
17
|
-
object: Chess.makeGame({ name, pgn }),
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
},
|
|
21
|
-
}),
|
|
22
|
-
);
|
|
@@ -1,23 +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 { ChessboardContainer } from '../components';
|
|
11
|
-
import { meta } from '../meta';
|
|
12
|
-
import { Chess } from '../types';
|
|
13
|
-
|
|
14
|
-
export default () =>
|
|
15
|
-
contributes(Capabilities.ReactSurface, [
|
|
16
|
-
createSurface({
|
|
17
|
-
id: meta.id,
|
|
18
|
-
role: ['article', 'section', 'card--intrinsic', 'card--extrinsic', 'card--popover', 'card--transclusion'],
|
|
19
|
-
// TODO(burdon): Could this be standardized so that we don't require a subject property.
|
|
20
|
-
filter: (data): data is { subject: Chess.Game } => Obj.instanceOf(Chess.Game, data.subject),
|
|
21
|
-
component: ({ data, role }) => <ChessboardContainer game={data.subject} role={role} />,
|
|
22
|
-
}),
|
|
23
|
-
]);
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
-
import React from 'react';
|
|
7
|
-
|
|
8
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
9
|
-
import { CardContainer } from '@dxos/react-ui-stack/testing';
|
|
10
|
-
|
|
11
|
-
import { meta as pluginMeta } from '../meta';
|
|
12
|
-
import { Chess } from '../types';
|
|
13
|
-
|
|
14
|
-
import { Chessboard } from './Chessboard';
|
|
15
|
-
|
|
16
|
-
type DefaultStoryProps = {
|
|
17
|
-
role: 'card--popover' | 'card--intrinsic' | 'card--extrinsic';
|
|
18
|
-
game: Chess.Game;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const meta = {
|
|
22
|
-
title: 'plugins/plugin-chess/Card',
|
|
23
|
-
render: ({ role, game }) => (
|
|
24
|
-
<CardContainer icon={pluginMeta.icon} role={role}>
|
|
25
|
-
<Chessboard.Root game={game}>
|
|
26
|
-
<Chessboard.Content role={role}>
|
|
27
|
-
<Chessboard.Board />
|
|
28
|
-
</Chessboard.Content>
|
|
29
|
-
</Chessboard.Root>
|
|
30
|
-
</CardContainer>
|
|
31
|
-
),
|
|
32
|
-
decorators: [withTheme],
|
|
33
|
-
parameters: {
|
|
34
|
-
layout: 'centered',
|
|
35
|
-
},
|
|
36
|
-
tags: ['cards'],
|
|
37
|
-
} satisfies Meta<DefaultStoryProps>;
|
|
38
|
-
|
|
39
|
-
export default meta;
|
|
40
|
-
|
|
41
|
-
const game = Chess.makeGame({
|
|
42
|
-
pgn: '1. e4 e5 2. Nf3 Nc6 3. Bc4 Bc5 4. c3 Nf6 5. d4 exd4 6. cxd4 Bb4+ 7. Nc3 d5 8. exd5 Nxd5 9. O-O Be6 10. Qb3 Na5 11. Qa4+ c6 12. Bxd5 Bxc3 13. Bxe6 fxe6 14. d5 Qg5 15. dxe6 Qg4 16. e7 Kf7 17. bxc3 Kg6 *',
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
type Story = StoryObj<typeof meta>;
|
|
46
|
-
|
|
47
|
-
export const Popover: Story = {
|
|
48
|
-
args: {
|
|
49
|
-
role: 'card--popover',
|
|
50
|
-
game: game,
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export const Intrinsic: Story = {
|
|
55
|
-
args: {
|
|
56
|
-
role: 'card--intrinsic',
|
|
57
|
-
game: game,
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export const Extrinsic: Story = {
|
|
62
|
-
args: {
|
|
63
|
-
role: 'card--extrinsic',
|
|
64
|
-
game: game,
|
|
65
|
-
},
|
|
66
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
-
|
|
7
|
-
import { withClientProvider } from '@dxos/react-client/testing';
|
|
8
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
9
|
-
|
|
10
|
-
import { translations } from '../translations';
|
|
11
|
-
import { Chess } from '../types';
|
|
12
|
-
|
|
13
|
-
import { ChessboardArticle } from './ChessboardArticle';
|
|
14
|
-
|
|
15
|
-
const meta = {
|
|
16
|
-
title: 'plugins/plugin-chess/Chessboard',
|
|
17
|
-
component: ChessboardArticle,
|
|
18
|
-
decorators: [withTheme, withClientProvider({ createIdentity: true })],
|
|
19
|
-
parameters: {
|
|
20
|
-
layout: 'fullscreen',
|
|
21
|
-
translations,
|
|
22
|
-
},
|
|
23
|
-
} satisfies Meta<typeof ChessboardArticle>;
|
|
24
|
-
|
|
25
|
-
export default meta;
|
|
26
|
-
|
|
27
|
-
type Story = StoryObj<typeof meta>;
|
|
28
|
-
|
|
29
|
-
export const Default: Story = {
|
|
30
|
-
args: {
|
|
31
|
-
game: Chess.makeGame(),
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export const EndGame: Story = {
|
|
36
|
-
args: {
|
|
37
|
-
game: Chess.makeGame({
|
|
38
|
-
pgn: '1. e4 e5 2. Nf3 Nc6 3. Bc4 Bc5 4. c3 Nf6 5. d4 exd4 6. cxd4 Bb4+ 7. Nc3 d5 8. exd5 Nxd5 9. O-O Be6 10. Qb3 Na5 11. Qa4+ c6 12. Bxd5 Bxc3 13. Bxe6 fxe6 *',
|
|
39
|
-
}),
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export const Promption: Story = {
|
|
44
|
-
args: {
|
|
45
|
-
game: Chess.makeGame({
|
|
46
|
-
pgn: '1. e4 e5 2. Nf3 Nc6 3. Bc4 Bc5 4. c3 Nf6 5. d4 exd4 6. cxd4 Bb4+ 7. Nc3 d5 8. exd5 Nxd5 9. O-O Be6 10. Qb3 Na5 11. Qa4+ c6 12. Bxd5 Bxc3 13. Bxe6 fxe6 14. d5 Qg5 15. dxe6 Qg4 16. e7 Kf7 17. bxc3 Kg6 *',
|
|
47
|
-
}),
|
|
48
|
-
},
|
|
49
|
-
};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React, { useCallback, useRef, useState } from 'react';
|
|
6
|
-
|
|
7
|
-
import { Toolbar, useTranslation } from '@dxos/react-ui';
|
|
8
|
-
import { type Player } from '@dxos/react-ui-gameboard';
|
|
9
|
-
import { StackItem } from '@dxos/react-ui-stack';
|
|
10
|
-
import { mx } from '@dxos/react-ui-theme';
|
|
11
|
-
|
|
12
|
-
import { meta } from '../meta';
|
|
13
|
-
import { type Chess } from '../types';
|
|
14
|
-
|
|
15
|
-
import { Chessboard, type ChessboardController, type ChessboardInfoProps } from './Chessboard';
|
|
16
|
-
|
|
17
|
-
export const ChessboardArticle = ({ game, role }: { game: Chess.Game; role?: string }) => {
|
|
18
|
-
const { t } = useTranslation(meta.id);
|
|
19
|
-
const [orientation, setOrientation] = useState<Player>('white');
|
|
20
|
-
const [open, setOpen] = useState(true);
|
|
21
|
-
const controller = useRef<ChessboardController>(null);
|
|
22
|
-
|
|
23
|
-
// TODO(burdon): Keyboard handler.
|
|
24
|
-
const handleSelect = useCallback<NonNullable<ChessboardInfoProps['onSelect']>>((index) => {
|
|
25
|
-
controller.current?.setMoveNumber(index);
|
|
26
|
-
}, []);
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<StackItem.Content toolbar classNames='@container'>
|
|
30
|
-
<Chessboard.Root game={game} ref={controller}>
|
|
31
|
-
<Toolbar.Root>
|
|
32
|
-
<Toolbar.IconButton
|
|
33
|
-
icon='ph--info--regular'
|
|
34
|
-
iconOnly
|
|
35
|
-
label={t('toggle info button')}
|
|
36
|
-
disabled={open}
|
|
37
|
-
classNames={mx('invisible @3xl:visible')}
|
|
38
|
-
onClick={() => setOpen((open) => !open)}
|
|
39
|
-
/>
|
|
40
|
-
</Toolbar.Root>
|
|
41
|
-
<div
|
|
42
|
-
className={mx(
|
|
43
|
-
'grid bs-full is-full gap-2',
|
|
44
|
-
open && '@3xl:grid-cols-[1fr_320px]',
|
|
45
|
-
role === 'section' && 'aspect-square',
|
|
46
|
-
role === 'section' && open && '@3xl:aspect-auto',
|
|
47
|
-
)}
|
|
48
|
-
>
|
|
49
|
-
<Chessboard.Content>
|
|
50
|
-
<Chessboard.Board classNames='m-4 rounded-sm overflow-hidden' orientation={orientation} />
|
|
51
|
-
</Chessboard.Content>
|
|
52
|
-
{open && (
|
|
53
|
-
<div className='hidden @3xl:flex flex-col p-8 justify-center items-center overflow-hidden'>
|
|
54
|
-
<Chessboard.Info
|
|
55
|
-
orientation={orientation}
|
|
56
|
-
min={8}
|
|
57
|
-
max={8}
|
|
58
|
-
onOrientationChange={setOrientation}
|
|
59
|
-
onClose={() => setOpen(false)}
|
|
60
|
-
onSelect={handleSelect}
|
|
61
|
-
/>
|
|
62
|
-
</div>
|
|
63
|
-
)}
|
|
64
|
-
</div>
|
|
65
|
-
</Chessboard.Root>
|
|
66
|
-
</StackItem.Content>
|
|
67
|
-
);
|
|
68
|
-
};
|
|
@@ -1,44 +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
|
-
|
|
9
|
-
import { type Chess } from '../types';
|
|
10
|
-
|
|
11
|
-
import { Chessboard } from './Chessboard';
|
|
12
|
-
import { ChessboardArticle } from './ChessboardArticle';
|
|
13
|
-
|
|
14
|
-
export type ChessboardContainerProps = {
|
|
15
|
-
game: Chess.Game;
|
|
16
|
-
role?: string;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const ChessboardContainer = ({ game, role }: ChessboardContainerProps) => {
|
|
20
|
-
const space = getSpace(game);
|
|
21
|
-
if (!space) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
switch (role) {
|
|
26
|
-
case 'card--popover':
|
|
27
|
-
case 'card--intrinsic':
|
|
28
|
-
case 'card--extrinsic': {
|
|
29
|
-
return (
|
|
30
|
-
<Chessboard.Root game={game}>
|
|
31
|
-
<Chessboard.Content role={role}>
|
|
32
|
-
<Chessboard.Board />
|
|
33
|
-
</Chessboard.Content>
|
|
34
|
-
</Chessboard.Root>
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
default: {
|
|
39
|
-
return <ChessboardArticle game={game} role={role} />;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export default ChessboardContainer;
|
package/src/functions/create.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as Effect from 'effect/Effect';
|
|
6
|
-
import * as Schema from 'effect/Schema';
|
|
7
|
-
|
|
8
|
-
import { DatabaseService, defineFunction } from '@dxos/functions';
|
|
9
|
-
|
|
10
|
-
import { Chess } from '../types';
|
|
11
|
-
|
|
12
|
-
export default defineFunction({
|
|
13
|
-
key: 'dxos.org/function/chess/create',
|
|
14
|
-
name: 'Create Chess',
|
|
15
|
-
description: 'Creates a new chess game.',
|
|
16
|
-
inputSchema: Schema.Struct({
|
|
17
|
-
pgn: Schema.optional(
|
|
18
|
-
Schema.String.annotations({
|
|
19
|
-
description: 'Portable Game Notation.',
|
|
20
|
-
}),
|
|
21
|
-
),
|
|
22
|
-
fen: Schema.optional(
|
|
23
|
-
Schema.String.annotations({
|
|
24
|
-
description: 'Forsyth-Edwards Notation.',
|
|
25
|
-
}),
|
|
26
|
-
),
|
|
27
|
-
}),
|
|
28
|
-
outputSchema: Chess.Game,
|
|
29
|
-
handler: Effect.fn(function* ({ data: { pgn, fen } }) {
|
|
30
|
-
return yield* DatabaseService.add(Chess.makeGame({ pgn, fen }));
|
|
31
|
-
}),
|
|
32
|
-
});
|
package/src/functions/index.ts
DELETED
package/src/functions/move.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Chess as ChessJS } from 'chess.js';
|
|
6
|
-
import * as Effect from 'effect/Effect';
|
|
7
|
-
import * as Schema from 'effect/Schema';
|
|
8
|
-
|
|
9
|
-
import { ArtifactId } from '@dxos/assistant';
|
|
10
|
-
import { DatabaseService, defineFunction } from '@dxos/functions';
|
|
11
|
-
|
|
12
|
-
import { Chess } from '../types';
|
|
13
|
-
|
|
14
|
-
export default defineFunction({
|
|
15
|
-
key: 'dxos.org/function/chess/move',
|
|
16
|
-
name: 'Move',
|
|
17
|
-
description: 'Makes a move in the given chess game.',
|
|
18
|
-
inputSchema: Schema.Struct({
|
|
19
|
-
id: ArtifactId.annotations({
|
|
20
|
-
description: 'The ID of the chess object.',
|
|
21
|
-
}),
|
|
22
|
-
move: Schema.String.annotations({
|
|
23
|
-
description: 'The move to make in the chess game.',
|
|
24
|
-
examples: ['e4', 'Bf3'],
|
|
25
|
-
}),
|
|
26
|
-
}),
|
|
27
|
-
outputSchema: Schema.Struct({
|
|
28
|
-
pgn: Schema.String.annotations({
|
|
29
|
-
description: 'The PGN of the game after the move was played.',
|
|
30
|
-
}),
|
|
31
|
-
}),
|
|
32
|
-
handler: Effect.fn(function* ({ data: { id, move } }) {
|
|
33
|
-
const object = yield* DatabaseService.resolve(ArtifactId.toDXN(id), Chess.Game);
|
|
34
|
-
const chess = new ChessJS();
|
|
35
|
-
if (object.pgn) {
|
|
36
|
-
chess.loadPgn(object.pgn);
|
|
37
|
-
} else if (object.fen) {
|
|
38
|
-
chess.load(object.fen);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
chess.move(move, { strict: false });
|
|
42
|
-
object.pgn = chess.pgn();
|
|
43
|
-
return { pgn: object.pgn };
|
|
44
|
-
}),
|
|
45
|
-
});
|
package/src/functions/play.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Chess as ChessJS } from 'chess.js';
|
|
6
|
-
import * as Effect from 'effect/Effect';
|
|
7
|
-
import * as Schema from 'effect/Schema';
|
|
8
|
-
|
|
9
|
-
import { ArtifactId } from '@dxos/assistant';
|
|
10
|
-
import { DatabaseService, defineFunction } from '@dxos/functions';
|
|
11
|
-
|
|
12
|
-
import { Chess } from '../types';
|
|
13
|
-
|
|
14
|
-
export default defineFunction({
|
|
15
|
-
key: 'dxos.org/function/chess/play',
|
|
16
|
-
name: 'Play',
|
|
17
|
-
description: 'Uses the chess engine to play the next move.',
|
|
18
|
-
inputSchema: Schema.Struct({
|
|
19
|
-
id: ArtifactId.annotations({
|
|
20
|
-
description: 'The ID of the chess object.',
|
|
21
|
-
}),
|
|
22
|
-
side: Schema.optional(Schema.Literal('white', 'black', 'any')).annotations({
|
|
23
|
-
description: 'The side to play.',
|
|
24
|
-
defaultValue: 'any',
|
|
25
|
-
}),
|
|
26
|
-
}),
|
|
27
|
-
outputSchema: Schema.Struct({
|
|
28
|
-
pgn: Schema.String.annotations({
|
|
29
|
-
description: 'The PGN of the game after the move was played.',
|
|
30
|
-
}),
|
|
31
|
-
move: Schema.optional(Schema.String).annotations({
|
|
32
|
-
description: 'The move that was played.',
|
|
33
|
-
}),
|
|
34
|
-
}),
|
|
35
|
-
handler: Effect.fn(function* ({ data: { id, side = 'any' } }) {
|
|
36
|
-
const object = yield* DatabaseService.resolve(ArtifactId.toDXN(id), Chess.Game);
|
|
37
|
-
const chess = new ChessJS();
|
|
38
|
-
if (object.pgn) {
|
|
39
|
-
chess.loadPgn(object.pgn);
|
|
40
|
-
} else if (object.fen) {
|
|
41
|
-
chess.load(object.fen);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (!(side === 'any' || (chess.turn() === 'w' && side === 'white') || (chess.turn() === 'b' && side === 'black'))) {
|
|
45
|
-
return { move: undefined, pgn: object.pgn! };
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const moves = chess.moves();
|
|
49
|
-
const move = moves[Math.floor(Math.random() * moves.length)];
|
|
50
|
-
|
|
51
|
-
chess.move(move, { strict: false });
|
|
52
|
-
object.pgn = chess.pgn();
|
|
53
|
-
return { move, pgn: object.pgn };
|
|
54
|
-
}),
|
|
55
|
-
});
|
package/src/types/ChessAction.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as Schema from 'effect/Schema';
|
|
6
|
-
|
|
7
|
-
import { meta } from '../meta';
|
|
8
|
-
|
|
9
|
-
import { Game } from './Chess';
|
|
10
|
-
|
|
11
|
-
export class Create extends Schema.TaggedClass<Create>()(`${meta.id}/action/create`, {
|
|
12
|
-
input: Schema.Struct({
|
|
13
|
-
name: Schema.optional(Schema.String),
|
|
14
|
-
pgn: Schema.optional(Schema.String),
|
|
15
|
-
}),
|
|
16
|
-
output: Schema.Struct({
|
|
17
|
-
object: Game,
|
|
18
|
-
}),
|
|
19
|
-
}) {}
|
/package/dist/lib/{browser/blueprint-definition-FD4TL5EE.mjs.map → neutral/ChessPlugin.mjs.map}
RENAMED
|
File without changes
|
|
File without changes
|
/package/dist/lib/{node-esm/blueprint-definition-O7ZM3HUF.mjs.map → neutral/chunk-J5LGTIGS.mjs.map}
RENAMED
|
File without changes
|
|
File without changes
|