@dxos/plugin-chess 0.8.4-main.c1de068 → 0.8.4-main.e098934
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-LIZDOGHI.mjs +97 -0
- package/dist/lib/browser/ChessboardContainer-LIZDOGHI.mjs.map +7 -0
- package/dist/lib/browser/blueprint-definition-RVS32T67.mjs +11 -0
- package/dist/lib/browser/blueprint-definition-RVS32T67.mjs.map +7 -0
- package/dist/lib/browser/chunk-EKNL3H3U.mjs +306 -0
- package/dist/lib/browser/chunk-EKNL3H3U.mjs.map +7 -0
- package/dist/lib/browser/chunk-KD4I5VTZ.mjs +8 -0
- package/dist/lib/browser/chunk-KD4I5VTZ.mjs.map +7 -0
- package/dist/lib/browser/chunk-KYO4ODJJ.mjs +163 -0
- package/dist/lib/browser/chunk-KYO4ODJJ.mjs.map +7 -0
- package/dist/lib/browser/chunk-PE3IWOFR.mjs +28 -0
- package/dist/lib/browser/chunk-PE3IWOFR.mjs.map +7 -0
- package/dist/lib/browser/chunk-T275KG4U.mjs +84 -0
- package/dist/lib/browser/chunk-T275KG4U.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +52 -25
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{intent-resolver-KQYYX44R.mjs → intent-resolver-DA5H5633.mjs} +8 -11
- package/dist/lib/browser/intent-resolver-DA5H5633.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-PLUCWIYP.mjs → react-surface-MIMI6LPO.mjs} +11 -9
- package/dist/lib/browser/react-surface-MIMI6LPO.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +6 -7
- package/dist/lib/node-esm/ChessboardContainer-XWVQ5K7N.mjs +98 -0
- package/dist/lib/node-esm/ChessboardContainer-XWVQ5K7N.mjs.map +7 -0
- package/dist/lib/node-esm/blueprint-definition-F57ZSRAG.mjs +12 -0
- package/dist/lib/node-esm/blueprint-definition-F57ZSRAG.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-5DYLCQBR.mjs +85 -0
- package/dist/lib/node-esm/chunk-5DYLCQBR.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-6OWCPDUA.mjs +29 -0
- package/dist/lib/node-esm/chunk-6OWCPDUA.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-A34JOK3K.mjs +164 -0
- package/dist/lib/node-esm/chunk-A34JOK3K.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-EGBWRJWH.mjs +307 -0
- package/dist/lib/node-esm/chunk-EGBWRJWH.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-QFINI7CC.mjs → chunk-Q5LJYIMO.mjs} +3 -3
- package/dist/lib/node-esm/chunk-Q5LJYIMO.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +52 -25
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/{intent-resolver-GXK2JROQ.mjs → intent-resolver-PODONUD3.mjs} +8 -11
- package/dist/lib/node-esm/intent-resolver-PODONUD3.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{react-surface-NGLNIWN3.mjs → react-surface-XMKFR5BC.mjs} +11 -9
- package/dist/lib/node-esm/react-surface-XMKFR5BC.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +6 -7
- package/dist/types/src/ChessPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/artifact-definition.d.ts +1 -1
- package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -1
- package/dist/types/src/capabilities/blueprint-definition.d.ts +6 -0
- package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +4 -3
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts +1 -1
- package/dist/types/src/components/Card.stories.d.ts +14 -0
- package/dist/types/src/components/Card.stories.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard.d.ts +38 -0
- package/dist/types/src/components/Chessboard.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard.stories.d.ts +40 -4
- package/dist/types/src/components/Chessboard.stories.d.ts.map +1 -1
- package/dist/types/src/components/ChessboardArticle.d.ts +7 -0
- package/dist/types/src/components/ChessboardArticle.d.ts.map +1 -0
- package/dist/types/src/components/ChessboardContainer.d.ts +9 -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/functions/create.d.ts +14 -0
- package/dist/types/src/functions/create.d.ts.map +1 -0
- package/dist/types/src/functions/index.d.ts +4 -0
- package/dist/types/src/functions/index.d.ts.map +1 -0
- package/dist/types/src/functions/move.d.ts +8 -0
- package/dist/types/src/functions/move.d.ts.map +1 -0
- package/dist/types/src/functions/play.d.ts +9 -0
- package/dist/types/src/functions/play.d.ts.map +1 -0
- 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.map +1 -1
- package/dist/types/src/translations.d.ts +10 -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/ChessAction.d.ts +24 -0
- package/dist/types/src/types/ChessAction.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +2 -2
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +38 -26
- package/src/ChessPlugin.tsx +8 -7
- package/src/capabilities/artifact-definition.ts +24 -20
- package/src/capabilities/blueprint-definition.ts +36 -0
- package/src/capabilities/index.ts +3 -1
- package/src/capabilities/intent-resolver.ts +3 -7
- package/src/capabilities/react-surface.tsx +5 -5
- package/src/components/Card.stories.tsx +68 -0
- package/src/components/Chessboard.stories.tsx +35 -26
- package/src/components/Chessboard.tsx +177 -0
- package/src/components/ChessboardArticle.tsx +69 -0
- package/src/components/ChessboardContainer.tsx +44 -0
- package/src/components/Info.tsx +236 -0
- package/src/components/index.ts +2 -2
- package/src/functions/create.ts +30 -0
- package/src/functions/index.ts +7 -0
- package/src/functions/move.ts +43 -0
- package/src/functions/play.ts +53 -0
- package/src/index.ts +2 -0
- package/src/meta.ts +4 -2
- package/src/translations.ts +10 -2
- package/src/types/Chess.ts +66 -0
- package/src/types/ChessAction.ts +19 -0
- package/src/types/index.ts +2 -2
- package/dist/lib/browser/ChessContainer-SC4ZV6XZ.mjs +0 -129
- package/dist/lib/browser/ChessContainer-SC4ZV6XZ.mjs.map +0 -7
- package/dist/lib/browser/artifact-definition-A2FSM255.mjs +0 -182
- package/dist/lib/browser/artifact-definition-A2FSM255.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-KDADGLPC.mjs +0 -8
- package/dist/lib/browser/chunk-KDADGLPC.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZXH3N4NA.mjs +0 -66
- package/dist/lib/browser/chunk-ZXH3N4NA.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-KQYYX44R.mjs.map +0 -7
- package/dist/lib/browser/react-surface-PLUCWIYP.mjs.map +0 -7
- package/dist/lib/node-esm/ChessContainer-7GLY5KLY.mjs +0 -130
- package/dist/lib/node-esm/ChessContainer-7GLY5KLY.mjs.map +0 -7
- package/dist/lib/node-esm/artifact-definition-2H7OUBZO.mjs +0 -183
- package/dist/lib/node-esm/artifact-definition-2H7OUBZO.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-27D3JA3K.mjs +0 -68
- package/dist/lib/node-esm/chunk-27D3JA3K.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-QFINI7CC.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-GXK2JROQ.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-NGLNIWN3.mjs.map +0 -7
- package/dist/types/src/components/Chess.d.ts +0 -14
- package/dist/types/src/components/Chess.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/ChessContainer.stories.d.ts +0 -23
- package/dist/types/src/components/ChessContainer.stories.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/components/Chess.tsx +0 -60
- package/src/components/ChessContainer.stories.tsx +0 -110
- package/src/components/ChessContainer.tsx +0 -71
- package/src/components/ChessPanel.tsx +0 -67
- package/src/components/PlayerSelector.tsx +0 -82
- package/src/types/schema.ts +0 -34
- package/src/types/types.ts +0 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/plugin-chess",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.e098934",
|
|
4
4
|
"description": "Chess for new plugin",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -10,14 +10,22 @@
|
|
|
10
10
|
"type": "module",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
+
"source": "./src/index.ts",
|
|
13
14
|
"types": "./dist/types/src/index.d.ts",
|
|
14
15
|
"browser": "./dist/lib/browser/index.mjs",
|
|
15
16
|
"node": "./dist/lib/node-esm/index.mjs"
|
|
16
17
|
},
|
|
17
18
|
"./types": {
|
|
19
|
+
"source": "./src/types/index.ts",
|
|
18
20
|
"types": "./dist/types/src/types/index.d.ts",
|
|
19
21
|
"browser": "./dist/lib/browser/types/index.mjs",
|
|
20
22
|
"node": "./dist/lib/node-esm/types/index.mjs"
|
|
23
|
+
},
|
|
24
|
+
"./functions": {
|
|
25
|
+
"source": "./src/functions/index.ts",
|
|
26
|
+
"types": "./dist/types/src/functions/index.d.ts",
|
|
27
|
+
"browser": "./dist/lib/browser/functions/index.mjs",
|
|
28
|
+
"node": "./dist/lib/node-esm/functions/index.mjs"
|
|
21
29
|
}
|
|
22
30
|
},
|
|
23
31
|
"types": "dist/types/src/index.d.ts",
|
|
@@ -36,41 +44,45 @@
|
|
|
36
44
|
"@preact-signals/safe-react": "^0.9.0",
|
|
37
45
|
"@preact/signals-core": "^1.9.0",
|
|
38
46
|
"chess.js": "^1.0.0",
|
|
39
|
-
"effect": "3.17.
|
|
40
|
-
"@dxos/ai": "0.8.4-main.
|
|
41
|
-
"@dxos/app-framework": "0.8.4-main.
|
|
42
|
-
"@dxos/assistant": "0.8.4-main.
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/
|
|
49
|
-
"@dxos/live-object": "0.8.4-main.
|
|
50
|
-
"@dxos/log": "0.8.4-main.
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/plugin-
|
|
53
|
-
"@dxos/plugin-graph": "0.8.4-main.
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/react-client": "0.8.4-main.
|
|
56
|
-
"@dxos/react-ui-
|
|
47
|
+
"effect": "3.17.7",
|
|
48
|
+
"@dxos/ai": "0.8.4-main.e098934",
|
|
49
|
+
"@dxos/app-framework": "0.8.4-main.e098934",
|
|
50
|
+
"@dxos/assistant": "0.8.4-main.e098934",
|
|
51
|
+
"@dxos/blueprints": "0.8.4-main.e098934",
|
|
52
|
+
"@dxos/async": "0.8.4-main.e098934",
|
|
53
|
+
"@dxos/display-name": "0.8.4-main.e098934",
|
|
54
|
+
"@dxos/functions": "0.8.4-main.e098934",
|
|
55
|
+
"@dxos/echo-schema": "0.8.4-main.e098934",
|
|
56
|
+
"@dxos/echo": "0.8.4-main.e098934",
|
|
57
|
+
"@dxos/live-object": "0.8.4-main.e098934",
|
|
58
|
+
"@dxos/log": "0.8.4-main.e098934",
|
|
59
|
+
"@dxos/invariant": "0.8.4-main.e098934",
|
|
60
|
+
"@dxos/plugin-client": "0.8.4-main.e098934",
|
|
61
|
+
"@dxos/plugin-graph": "0.8.4-main.e098934",
|
|
62
|
+
"@dxos/plugin-space": "0.8.4-main.e098934",
|
|
63
|
+
"@dxos/react-client": "0.8.4-main.e098934",
|
|
64
|
+
"@dxos/react-ui-gameboard": "0.8.4-main.e098934",
|
|
65
|
+
"@dxos/react-ui-stack": "0.8.4-main.e098934",
|
|
66
|
+
"@dxos/react-ui-sfx": "0.8.4-main.e098934",
|
|
67
|
+
"@dxos/schema": "0.8.4-main.e098934",
|
|
68
|
+
"@dxos/util": "0.8.4-main.e098934"
|
|
57
69
|
},
|
|
58
70
|
"devDependencies": {
|
|
59
71
|
"@types/react": "~18.2.0",
|
|
60
72
|
"@types/react-dom": "~18.2.0",
|
|
61
73
|
"react": "~18.2.0",
|
|
62
74
|
"react-dom": "~18.2.0",
|
|
63
|
-
"vite": "
|
|
64
|
-
"@dxos/
|
|
65
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
66
|
-
"@dxos/
|
|
67
|
-
"@dxos/storybook-utils": "0.8.4-main.
|
|
75
|
+
"vite": "7.1.1",
|
|
76
|
+
"@dxos/react-ui": "0.8.4-main.e098934",
|
|
77
|
+
"@dxos/react-ui-theme": "0.8.4-main.e098934",
|
|
78
|
+
"@dxos/plugin-theme": "0.8.4-main.e098934",
|
|
79
|
+
"@dxos/storybook-utils": "0.8.4-main.e098934"
|
|
68
80
|
},
|
|
69
81
|
"peerDependencies": {
|
|
70
82
|
"react": "~18.2.0",
|
|
71
83
|
"react-dom": "~18.2.0",
|
|
72
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
73
|
-
"@dxos/react-ui-theme": "0.8.4-main.
|
|
84
|
+
"@dxos/react-ui": "0.8.4-main.e098934",
|
|
85
|
+
"@dxos/react-ui-theme": "0.8.4-main.e098934"
|
|
74
86
|
},
|
|
75
87
|
"publishConfig": {
|
|
76
88
|
"access": "public"
|
package/src/ChessPlugin.tsx
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Capabilities, contributes, createIntent, defineModule, definePlugin
|
|
5
|
+
import { Capabilities, Events, contributes, createIntent, defineModule, definePlugin } from '@dxos/app-framework';
|
|
6
6
|
import { ClientEvents } from '@dxos/plugin-client';
|
|
7
7
|
import { SpaceCapabilities } from '@dxos/plugin-space';
|
|
8
8
|
import { defineObjectForm } from '@dxos/plugin-space/types';
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { BLUEPRINT_KEY, BlueprintDefinition, IntentResolver, ReactSurface } from './capabilities';
|
|
11
11
|
import { meta } from './meta';
|
|
12
12
|
import { translations } from './translations';
|
|
13
|
-
import {
|
|
13
|
+
import { Chess, ChessAction } from './types';
|
|
14
14
|
|
|
15
15
|
export const ChessPlugin = () =>
|
|
16
16
|
definePlugin(meta, [
|
|
@@ -24,9 +24,10 @@ export const ChessPlugin = () =>
|
|
|
24
24
|
activatesOn: Events.SetupMetadata,
|
|
25
25
|
activate: () =>
|
|
26
26
|
contributes(Capabilities.Metadata, {
|
|
27
|
-
id:
|
|
27
|
+
id: Chess.Game.typename,
|
|
28
28
|
metadata: {
|
|
29
29
|
icon: 'ph--shield-chevron--regular',
|
|
30
|
+
blueprints: [BLUEPRINT_KEY],
|
|
30
31
|
},
|
|
31
32
|
}),
|
|
32
33
|
}),
|
|
@@ -37,7 +38,7 @@ export const ChessPlugin = () =>
|
|
|
37
38
|
contributes(
|
|
38
39
|
SpaceCapabilities.ObjectForm,
|
|
39
40
|
defineObjectForm({
|
|
40
|
-
objectSchema:
|
|
41
|
+
objectSchema: Chess.Game,
|
|
41
42
|
getIntent: () => createIntent(ChessAction.Create),
|
|
42
43
|
}),
|
|
43
44
|
),
|
|
@@ -53,8 +54,8 @@ export const ChessPlugin = () =>
|
|
|
53
54
|
activate: IntentResolver,
|
|
54
55
|
}),
|
|
55
56
|
defineModule({
|
|
56
|
-
id: `${meta.id}/module/
|
|
57
|
+
id: `${meta.id}/module/blueprint`,
|
|
57
58
|
activatesOn: Events.SetupArtifactDefinition,
|
|
58
|
-
activate:
|
|
59
|
+
activate: BlueprintDefinition,
|
|
59
60
|
}),
|
|
60
61
|
]);
|
|
@@ -2,20 +2,24 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
// ISSUE(burdon): defineArtifact
|
|
6
|
+
// @ts-nocheck
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
8
|
+
import { Chess as ChessJS } from 'chess.js';
|
|
9
|
+
import { Schema, pipe } from 'effect';
|
|
10
|
+
|
|
11
|
+
import { ToolResult, createTool } from '@dxos/ai';
|
|
12
|
+
import { Capabilities, type PromiseIntentDispatcher, chain, contributes, createIntent } from '@dxos/app-framework';
|
|
13
|
+
import { ArtifactId, VersionPin, createArtifactElement } from '@dxos/assistant';
|
|
11
14
|
import { defineArtifact } from '@dxos/blueprints';
|
|
12
15
|
import { Obj } from '@dxos/echo';
|
|
13
16
|
import { invariant } from '@dxos/invariant';
|
|
14
17
|
import { SpaceAction } from '@dxos/plugin-space/types';
|
|
15
18
|
import { Filter, type Space } from '@dxos/react-client/echo';
|
|
19
|
+
import { trim } from '@dxos/util';
|
|
16
20
|
|
|
17
21
|
import { meta } from '../meta';
|
|
18
|
-
import {
|
|
22
|
+
import { Chess, ChessAction } from '../types';
|
|
19
23
|
|
|
20
24
|
// TODO(burdon): Factor out.
|
|
21
25
|
declare global {
|
|
@@ -30,24 +34,24 @@ export default () => {
|
|
|
30
34
|
id: `artifact:${meta.id}`,
|
|
31
35
|
name: meta.name,
|
|
32
36
|
description: 'Provides a simple chess engine.',
|
|
33
|
-
instructions: `
|
|
37
|
+
instructions: trim`
|
|
34
38
|
- 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
39
|
- 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
40
|
`,
|
|
37
|
-
schema:
|
|
41
|
+
schema: Chess.Game,
|
|
38
42
|
tools: [
|
|
39
43
|
createTool(meta.id, {
|
|
40
44
|
name: 'create',
|
|
41
45
|
description: 'Create a new chess game. Returns the artifact definition for the game.',
|
|
42
46
|
caption: 'Creating chess game...',
|
|
43
47
|
schema: Schema.Struct({
|
|
44
|
-
|
|
48
|
+
pgn: Schema.String.annotations({ description: 'The state of the chess game in the PGN format.' }),
|
|
45
49
|
}),
|
|
46
|
-
execute: async ({
|
|
50
|
+
execute: async ({ pgn }, { extensions }) => {
|
|
47
51
|
invariant(extensions?.space, 'No space');
|
|
48
52
|
invariant(extensions?.dispatch, 'No intent dispatcher');
|
|
49
53
|
const intent = pipe(
|
|
50
|
-
createIntent(ChessAction.Create, {
|
|
54
|
+
createIntent(ChessAction.Create, { pgn }),
|
|
51
55
|
chain(SpaceAction.AddObject, { target: extensions.space }),
|
|
52
56
|
);
|
|
53
57
|
const { data, error } = await extensions.dispatch(intent);
|
|
@@ -67,7 +71,7 @@ export default () => {
|
|
|
67
71
|
schema: Schema.Struct({}),
|
|
68
72
|
execute: async (_, { extensions }) => {
|
|
69
73
|
invariant(extensions?.space, 'No space');
|
|
70
|
-
const { objects: games } = await extensions.space.db.query(Filter.type(
|
|
74
|
+
const { objects: games } = await extensions.space.db.query(Filter.type(Chess.Game)).run();
|
|
71
75
|
invariant(games.length > 0, 'No chess games found');
|
|
72
76
|
|
|
73
77
|
return ToolResult.Success(games);
|
|
@@ -83,9 +87,9 @@ export default () => {
|
|
|
83
87
|
const game = await extensions.space.db
|
|
84
88
|
.query(Filter.ids(ArtifactId.toDXN(id, extensions.space.id).toString()))
|
|
85
89
|
.first();
|
|
86
|
-
invariant(Obj.instanceOf(
|
|
90
|
+
invariant(Obj.instanceOf(Chess.Game, game));
|
|
87
91
|
|
|
88
|
-
return ToolResult.Success(game.
|
|
92
|
+
return ToolResult.Success(game.pgn);
|
|
89
93
|
},
|
|
90
94
|
}),
|
|
91
95
|
createTool(meta.id, {
|
|
@@ -104,17 +108,17 @@ export default () => {
|
|
|
104
108
|
const game = await extensions.space.db
|
|
105
109
|
.query(Filter.ids(ArtifactId.toDXN(id, extensions.space.id).toString()))
|
|
106
110
|
.first();
|
|
107
|
-
invariant(Obj.instanceOf(
|
|
111
|
+
invariant(Obj.instanceOf(Chess.Game, game));
|
|
108
112
|
|
|
109
|
-
const
|
|
113
|
+
const chess = new ChessJS(game.pgn);
|
|
110
114
|
try {
|
|
111
|
-
|
|
115
|
+
chess.move(move);
|
|
112
116
|
} catch (error: any) {
|
|
113
117
|
return ToolResult.Error(error.message);
|
|
114
118
|
}
|
|
115
|
-
|
|
116
|
-
game.
|
|
117
|
-
return ToolResult.Success(game.
|
|
119
|
+
|
|
120
|
+
game.pgn = chess.pgn();
|
|
121
|
+
return ToolResult.Success(game.pgn);
|
|
118
122
|
},
|
|
119
123
|
}),
|
|
120
124
|
],
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Capabilities, contributes } from '@dxos/app-framework';
|
|
6
|
+
import { Blueprint, Template } from '@dxos/blueprints';
|
|
7
|
+
import { type FunctionDefinition } from '@dxos/functions';
|
|
8
|
+
import { trim } from '@dxos/util';
|
|
9
|
+
|
|
10
|
+
import { create, move, play } from '../functions';
|
|
11
|
+
|
|
12
|
+
export const BLUEPRINT_KEY = 'dxos.org/blueprint/chess';
|
|
13
|
+
|
|
14
|
+
const functions: FunctionDefinition[] = [create, move, play];
|
|
15
|
+
|
|
16
|
+
export default () => {
|
|
17
|
+
return [
|
|
18
|
+
contributes(Capabilities.Functions, functions),
|
|
19
|
+
contributes(
|
|
20
|
+
Capabilities.BlueprintDefinition,
|
|
21
|
+
Blueprint.make({
|
|
22
|
+
key: BLUEPRINT_KEY,
|
|
23
|
+
name: 'Chess',
|
|
24
|
+
tools: Blueprint.toolDefinitions({ functions }),
|
|
25
|
+
instructions: Template.make({
|
|
26
|
+
source: trim`
|
|
27
|
+
You are an expert chess player.
|
|
28
|
+
To analyze a game you can access the "pgn" property by loading the context object that represents the current game.
|
|
29
|
+
You could suggest a good next move or offer to play a move.
|
|
30
|
+
Don't actually make a move unless you are asked to.
|
|
31
|
+
`,
|
|
32
|
+
}),
|
|
33
|
+
}),
|
|
34
|
+
),
|
|
35
|
+
];
|
|
36
|
+
};
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import { lazy } from '@dxos/app-framework';
|
|
6
6
|
|
|
7
|
-
export const
|
|
7
|
+
export const BlueprintDefinition = lazy(() => import('./blueprint-definition'));
|
|
8
8
|
export const IntentResolver = lazy(() => import('./intent-resolver'));
|
|
9
9
|
export const ReactSurface = lazy(() => import('./react-surface'));
|
|
10
|
+
|
|
11
|
+
export * from './blueprint-definition';
|
|
@@ -2,23 +2,19 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Chess } from 'chess.js';
|
|
6
|
-
|
|
7
5
|
import { Capabilities, contributes, createResolver } from '@dxos/app-framework';
|
|
8
|
-
import { Obj } from '@dxos/echo';
|
|
9
6
|
|
|
10
|
-
import {
|
|
7
|
+
import { Chess, ChessAction } from '../types';
|
|
11
8
|
|
|
12
9
|
export default () =>
|
|
13
10
|
contributes(
|
|
14
11
|
Capabilities.IntentResolver,
|
|
15
12
|
createResolver({
|
|
16
13
|
intent: ChessAction.Create,
|
|
17
|
-
resolve: ({ name,
|
|
18
|
-
const pgn = fen ? new Chess(fen).pgn() : undefined;
|
|
14
|
+
resolve: ({ name, pgn }) => {
|
|
19
15
|
return {
|
|
20
16
|
data: {
|
|
21
|
-
object:
|
|
17
|
+
object: Chess.makeGame({ name, pgn }),
|
|
22
18
|
},
|
|
23
19
|
};
|
|
24
20
|
},
|
|
@@ -7,17 +7,17 @@ import React from 'react';
|
|
|
7
7
|
import { Capabilities, contributes, createSurface } from '@dxos/app-framework';
|
|
8
8
|
import { Obj } from '@dxos/echo';
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { ChessboardContainer } from '../components';
|
|
11
11
|
import { meta } from '../meta';
|
|
12
|
-
import {
|
|
12
|
+
import { Chess } from '../types';
|
|
13
13
|
|
|
14
14
|
export default () =>
|
|
15
15
|
contributes(Capabilities.ReactSurface, [
|
|
16
16
|
createSurface({
|
|
17
17
|
id: meta.id,
|
|
18
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:
|
|
21
|
-
component: ({ data, role }) => <
|
|
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
22
|
}),
|
|
23
23
|
]);
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import '@dxos-theme';
|
|
6
|
+
|
|
7
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
|
+
import React from 'react';
|
|
9
|
+
|
|
10
|
+
import { CardContainer } from '@dxos/react-ui-stack/testing';
|
|
11
|
+
import { withTheme } from '@dxos/storybook-utils';
|
|
12
|
+
|
|
13
|
+
import { meta as pluginMeta } from '../meta';
|
|
14
|
+
import { Chess } from '../types';
|
|
15
|
+
|
|
16
|
+
import { Chessboard } from './Chessboard';
|
|
17
|
+
|
|
18
|
+
type DefaultStoryProps = {
|
|
19
|
+
role: 'card--popover' | 'card--intrinsic' | 'card--extrinsic';
|
|
20
|
+
game: Chess.Game;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const meta: Meta<DefaultStoryProps> = {
|
|
24
|
+
title: 'plugins/plugin-chess/Card',
|
|
25
|
+
render: ({ role, game }) => (
|
|
26
|
+
<CardContainer icon={pluginMeta.icon} role={role}>
|
|
27
|
+
<Chessboard.Root game={game}>
|
|
28
|
+
<Chessboard.Content role={role}>
|
|
29
|
+
<Chessboard.Board />
|
|
30
|
+
</Chessboard.Content>
|
|
31
|
+
</Chessboard.Root>
|
|
32
|
+
</CardContainer>
|
|
33
|
+
),
|
|
34
|
+
decorators: [withTheme],
|
|
35
|
+
parameters: {
|
|
36
|
+
layout: 'centered',
|
|
37
|
+
},
|
|
38
|
+
tags: ['cards'],
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export default meta;
|
|
42
|
+
|
|
43
|
+
const game = Chess.makeGame({
|
|
44
|
+
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 *',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
type Story = StoryObj<typeof meta>;
|
|
48
|
+
|
|
49
|
+
export const Popover: Story = {
|
|
50
|
+
args: {
|
|
51
|
+
role: 'card--popover',
|
|
52
|
+
game: game,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const Intrinsic: Story = {
|
|
57
|
+
args: {
|
|
58
|
+
role: 'card--intrinsic',
|
|
59
|
+
game: game,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const Extrinsic: Story = {
|
|
64
|
+
args: {
|
|
65
|
+
role: 'card--extrinsic',
|
|
66
|
+
game: game,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
@@ -5,37 +5,46 @@
|
|
|
5
5
|
import '@dxos-theme';
|
|
6
6
|
|
|
7
7
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
|
-
import React, { useMemo } from 'react';
|
|
9
8
|
|
|
10
|
-
import {
|
|
9
|
+
import { withClientProvider } from '@dxos/react-client/testing';
|
|
11
10
|
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
12
11
|
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
const DefaultStory = () => {
|
|
16
|
-
const model = useMemo(() => new ChessModel(), []);
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<div className='flex grow mx-8 gap-8 items-center overflow-hidden'>
|
|
20
|
-
<Gameboard.Root model={model} onDrop={(move) => model.makeMove(move)}>
|
|
21
|
-
<Gameboard.Content>
|
|
22
|
-
<Chessboard />
|
|
23
|
-
</Gameboard.Content>
|
|
24
|
-
</Gameboard.Root>
|
|
25
|
-
<ChessPanel model={model} classNames='w-[200px]' />
|
|
26
|
-
</div>
|
|
27
|
-
);
|
|
28
|
-
};
|
|
12
|
+
import { translations } from '../translations';
|
|
13
|
+
import { Chess } from '../types';
|
|
29
14
|
|
|
30
|
-
|
|
31
|
-
title: 'plugins/plugin-chess/Chessboard',
|
|
32
|
-
component: Chessboard,
|
|
33
|
-
render: DefaultStory,
|
|
34
|
-
decorators: [withTheme, withLayout({ fullscreen: true })],
|
|
35
|
-
};
|
|
15
|
+
import { ChessboardArticle } from './ChessboardArticle';
|
|
36
16
|
|
|
37
|
-
|
|
17
|
+
const meta = {
|
|
18
|
+
title: 'plugins/plugin-chess/Chessboard',
|
|
19
|
+
component: ChessboardArticle,
|
|
20
|
+
decorators: [withClientProvider({ createIdentity: true }), withTheme, withLayout({ fullscreen: true })],
|
|
21
|
+
parameters: {
|
|
22
|
+
translations,
|
|
23
|
+
},
|
|
24
|
+
} satisfies Meta<typeof ChessboardArticle>;
|
|
38
25
|
|
|
39
26
|
export default meta;
|
|
40
27
|
|
|
41
|
-
|
|
28
|
+
type Story = StoryObj<typeof meta>;
|
|
29
|
+
|
|
30
|
+
export const Default: Story = {
|
|
31
|
+
args: {
|
|
32
|
+
game: Chess.makeGame(),
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const EndGame: Story = {
|
|
37
|
+
args: {
|
|
38
|
+
game: Chess.makeGame({
|
|
39
|
+
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 *',
|
|
40
|
+
}),
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const Promption: Story = {
|
|
45
|
+
args: {
|
|
46
|
+
game: Chess.makeGame({
|
|
47
|
+
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 *',
|
|
48
|
+
}),
|
|
49
|
+
},
|
|
50
|
+
};
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, {
|
|
6
|
+
type PropsWithChildren,
|
|
7
|
+
forwardRef,
|
|
8
|
+
useCallback,
|
|
9
|
+
useEffect,
|
|
10
|
+
useImperativeHandle,
|
|
11
|
+
useMemo,
|
|
12
|
+
useRef,
|
|
13
|
+
} from 'react';
|
|
14
|
+
|
|
15
|
+
import { addEventListener } from '@dxos/async';
|
|
16
|
+
import { type ThemedClassName } from '@dxos/react-ui';
|
|
17
|
+
import {
|
|
18
|
+
ChessModel,
|
|
19
|
+
Gameboard,
|
|
20
|
+
type GameboardRootProps,
|
|
21
|
+
Chessboard as NaturalChessboard,
|
|
22
|
+
type ChessboardProps as NaturalChessboardProps,
|
|
23
|
+
getRawPgn,
|
|
24
|
+
useGameboardContext,
|
|
25
|
+
} from '@dxos/react-ui-gameboard';
|
|
26
|
+
import { useSoundEffect } from '@dxos/react-ui-sfx';
|
|
27
|
+
import { mx } from '@dxos/react-ui-theme';
|
|
28
|
+
|
|
29
|
+
import { type Chess } from '../types';
|
|
30
|
+
|
|
31
|
+
import { Info, type InfoProps } from './Info';
|
|
32
|
+
|
|
33
|
+
export interface ChessboardController {
|
|
34
|
+
setMoveNumber(index: number): void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class ExtendedChessModel extends ChessModel {
|
|
38
|
+
constructor(readonly object: Chess.Game) {
|
|
39
|
+
super();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//
|
|
44
|
+
// Root
|
|
45
|
+
//
|
|
46
|
+
|
|
47
|
+
type RootProps = PropsWithChildren<{
|
|
48
|
+
game: Chess.Game;
|
|
49
|
+
}>;
|
|
50
|
+
|
|
51
|
+
const Root = forwardRef<ChessboardController, RootProps>(({ game, children }, forwardedRef) => {
|
|
52
|
+
const model = useMemo(() => new ExtendedChessModel(game), []);
|
|
53
|
+
const click = useSoundEffect('Click');
|
|
54
|
+
|
|
55
|
+
// Controller.
|
|
56
|
+
useImperativeHandle(forwardedRef, () => {
|
|
57
|
+
return {
|
|
58
|
+
setMoveNumber: (index) => model.setMoveIndex(index),
|
|
59
|
+
};
|
|
60
|
+
}, [model]);
|
|
61
|
+
|
|
62
|
+
// External change.
|
|
63
|
+
// NOTE: Warning if user has not interacted with the board.
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (model.pgn !== getRawPgn(game.pgn ?? '')) {
|
|
66
|
+
const silent = model.pgn === '*';
|
|
67
|
+
model.update(game.pgn);
|
|
68
|
+
if (!silent) {
|
|
69
|
+
void click.play();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}, [game.pgn]);
|
|
73
|
+
|
|
74
|
+
// Move.
|
|
75
|
+
const handleDrop = useCallback<NonNullable<GameboardRootProps<ChessModel>['onDrop']>>(
|
|
76
|
+
(move) => {
|
|
77
|
+
if (!model.makeMove(move)) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
void click.play();
|
|
82
|
+
game.pgn = model.pgn;
|
|
83
|
+
return true;
|
|
84
|
+
},
|
|
85
|
+
[model],
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<Gameboard.Root model={model} onDrop={handleDrop}>
|
|
90
|
+
{children}
|
|
91
|
+
</Gameboard.Root>
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
//
|
|
96
|
+
// Content
|
|
97
|
+
//
|
|
98
|
+
|
|
99
|
+
type Role = 'card--popover' | 'card--intrinsic' | 'card--extrinsic';
|
|
100
|
+
|
|
101
|
+
type ContentProps = ThemedClassName<PropsWithChildren<{ role?: Role }>>;
|
|
102
|
+
|
|
103
|
+
const Content = ({ classNames, children, role }: ContentProps) => {
|
|
104
|
+
return (
|
|
105
|
+
<Gameboard.Content
|
|
106
|
+
classNames={mx(classNames, role === 'card--popover' && 'size-container popover-square')}
|
|
107
|
+
grow={!role || role === 'card--extrinsic'}
|
|
108
|
+
contain={!role || role === 'card--extrinsic' || role === 'card--popover'}
|
|
109
|
+
>
|
|
110
|
+
{children}
|
|
111
|
+
</Gameboard.Content>
|
|
112
|
+
);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
//
|
|
116
|
+
// Board
|
|
117
|
+
//
|
|
118
|
+
|
|
119
|
+
type BoardProps = NaturalChessboardProps;
|
|
120
|
+
|
|
121
|
+
const Board = (props: BoardProps) => {
|
|
122
|
+
const { model } = useGameboardContext<ChessModel>(Board.displayName);
|
|
123
|
+
|
|
124
|
+
// Keyboard navigation.
|
|
125
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
if (!ref.current) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Participate in keyboard navigation (set tabIndex={0})
|
|
132
|
+
ref.current.setAttribute('data-arrow-keys', 'all');
|
|
133
|
+
|
|
134
|
+
return addEventListener(ref.current, 'keydown', (ev) => {
|
|
135
|
+
switch (ev.key) {
|
|
136
|
+
case 'ArrowUp':
|
|
137
|
+
model.setMoveIndex(0);
|
|
138
|
+
break;
|
|
139
|
+
case 'ArrowDown':
|
|
140
|
+
model.setMoveIndex(model.game.history().length);
|
|
141
|
+
break;
|
|
142
|
+
case 'ArrowLeft':
|
|
143
|
+
if (model.moveIndex.value > 0) {
|
|
144
|
+
model.setMoveIndex(model.moveIndex.value - 1);
|
|
145
|
+
}
|
|
146
|
+
break;
|
|
147
|
+
case 'ArrowRight':
|
|
148
|
+
if (model.moveIndex.value < model.game.history().length) {
|
|
149
|
+
model.setMoveIndex(model.moveIndex.value + 1);
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}, [model]);
|
|
155
|
+
|
|
156
|
+
return <NaturalChessboard ref={ref} {...props} />;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
Board.displayName = 'Chessboard.Board';
|
|
160
|
+
|
|
161
|
+
//
|
|
162
|
+
// Chessboard
|
|
163
|
+
//
|
|
164
|
+
|
|
165
|
+
export const Chessboard = {
|
|
166
|
+
Root: Root,
|
|
167
|
+
Content: Content,
|
|
168
|
+
Board: Board,
|
|
169
|
+
Info: Info,
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export type {
|
|
173
|
+
RootProps as ChessboardRootProps,
|
|
174
|
+
ContentProps as ChessboardContentProps,
|
|
175
|
+
BoardProps as ChessboardBoardProps,
|
|
176
|
+
InfoProps as ChessboardInfoProps,
|
|
177
|
+
};
|