@dxos/plugin-chess 0.8.4-main.c1de068 → 0.8.4-main.fd6878d
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-NNIOQIRP.mjs +90 -0
- package/dist/lib/browser/ChessboardContainer-NNIOQIRP.mjs.map +7 -0
- package/dist/lib/browser/blueprint-definition-OJQYAZGZ.mjs +38 -0
- package/dist/lib/browser/blueprint-definition-OJQYAZGZ.mjs.map +7 -0
- package/dist/lib/browser/chunk-2W3S5N6C.mjs +257 -0
- package/dist/lib/browser/chunk-2W3S5N6C.mjs.map +7 -0
- package/dist/lib/browser/chunk-EJMPHRSR.mjs +94 -0
- package/dist/lib/browser/chunk-EJMPHRSR.mjs.map +7 -0
- package/dist/lib/browser/chunk-OBJAHY6H.mjs +79 -0
- package/dist/lib/browser/chunk-OBJAHY6H.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-PPBBLHAC.mjs +8 -0
- package/dist/lib/browser/chunk-PPBBLHAC.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +42 -24
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{intent-resolver-KQYYX44R.mjs → intent-resolver-JWKKRNGG.mjs} +8 -11
- package/dist/lib/browser/intent-resolver-JWKKRNGG.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-PLUCWIYP.mjs → react-surface-RIXD6RTS.mjs} +11 -9
- package/dist/lib/browser/react-surface-RIXD6RTS.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +6 -7
- package/dist/lib/node-esm/ChessboardContainer-FCPUV2T2.mjs +91 -0
- package/dist/lib/node-esm/ChessboardContainer-FCPUV2T2.mjs.map +7 -0
- package/dist/lib/node-esm/blueprint-definition-F5SGHCDA.mjs +39 -0
- package/dist/lib/node-esm/blueprint-definition-F5SGHCDA.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-QFINI7CC.mjs → chunk-42EKKMOO.mjs} +3 -3
- package/dist/lib/node-esm/chunk-42EKKMOO.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-5APYXPBX.mjs +95 -0
- package/dist/lib/node-esm/chunk-5APYXPBX.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-LCCUF5X5.mjs +80 -0
- package/dist/lib/node-esm/chunk-LCCUF5X5.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-QAGOXJGH.mjs +258 -0
- package/dist/lib/node-esm/chunk-QAGOXJGH.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +42 -24
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/{intent-resolver-GXK2JROQ.mjs → intent-resolver-G6XJAW6C.mjs} +8 -11
- package/dist/lib/node-esm/intent-resolver-G6XJAW6C.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{react-surface-NGLNIWN3.mjs → react-surface-GGRDWZJT.mjs} +11 -9
- package/dist/lib/node-esm/react-surface-GGRDWZJT.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +6 -7
- 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 +3 -0
- package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +1 -1
- 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/components/Card.stories.d.ts +49 -0
- package/dist/types/src/components/Card.stories.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard.d.ts +32 -0
- package/dist/types/src/components/Chessboard.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard.stories.d.ts +39 -5
- package/dist/types/src/components/Chessboard.stories.d.ts.map +1 -1
- package/dist/types/src/components/ChessboardArticle.d.ts +6 -0
- package/dist/types/src/components/ChessboardArticle.d.ts.map +1 -0
- package/dist/types/src/components/ChessboardContainer.d.ts +9 -0
- package/dist/types/src/components/ChessboardContainer.d.ts.map +1 -0
- package/dist/types/src/components/ChessboardInfo.d.ts +20 -0
- package/dist/types/src/components/ChessboardInfo.d.ts.map +1 -0
- package/dist/types/src/components/ChessboardPlayers.d.ts +8 -0
- package/dist/types/src/components/ChessboardPlayers.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/index.d.ts +3 -0
- package/dist/types/src/functions/index.d.ts.map +1 -0
- package/dist/types/src/functions/move.d.ts +6 -0
- package/dist/types/src/functions/move.d.ts.map +1 -0
- package/dist/types/src/functions/play.d.ts +8 -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 +8 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Chess.d.ts +24 -0
- package/dist/types/src/types/Chess.d.ts.map +1 -0
- package/dist/types/src/types/ChessAction.d.ts +23 -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 +29 -25
- package/src/ChessPlugin.tsx +7 -7
- package/src/capabilities/artifact-definition.ts +24 -20
- package/src/capabilities/blueprint-definition.ts +34 -0
- package/src/capabilities/index.ts +1 -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 +33 -24
- package/src/components/Chessboard.tsx +101 -0
- package/src/components/ChessboardArticle.tsx +57 -0
- package/src/components/ChessboardContainer.tsx +44 -0
- package/src/components/ChessboardInfo.tsx +140 -0
- package/src/components/{PlayerSelector.tsx → ChessboardPlayers.tsx} +25 -10
- package/src/components/index.ts +2 -2
- package/src/functions/index.ts +6 -0
- package/src/functions/move.ts +43 -0
- package/src/functions/play.ts +45 -0
- package/src/index.ts +2 -0
- package/src/meta.ts +4 -2
- package/src/translations.ts +8 -2
- package/src/types/Chess.ts +56 -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/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.fd6878d",
|
|
4
4
|
"description": "Chess for new plugin",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -10,11 +10,13 @@
|
|
|
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"
|
|
@@ -36,24 +38,26 @@
|
|
|
36
38
|
"@preact-signals/safe-react": "^0.9.0",
|
|
37
39
|
"@preact/signals-core": "^1.9.0",
|
|
38
40
|
"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/blueprints": "0.8.4-main.
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/echo-schema": "0.8.4-main.
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/invariant": "0.8.4-main.
|
|
49
|
-
"@dxos/
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/plugin-
|
|
53
|
-
"@dxos/plugin-graph": "0.8.4-main.
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/react-
|
|
56
|
-
"@dxos/
|
|
41
|
+
"effect": "3.17.7",
|
|
42
|
+
"@dxos/ai": "0.8.4-main.fd6878d",
|
|
43
|
+
"@dxos/app-framework": "0.8.4-main.fd6878d",
|
|
44
|
+
"@dxos/assistant": "0.8.4-main.fd6878d",
|
|
45
|
+
"@dxos/async": "0.8.4-main.fd6878d",
|
|
46
|
+
"@dxos/blueprints": "0.8.4-main.fd6878d",
|
|
47
|
+
"@dxos/display-name": "0.8.4-main.fd6878d",
|
|
48
|
+
"@dxos/echo-schema": "0.8.4-main.fd6878d",
|
|
49
|
+
"@dxos/functions": "0.8.4-main.fd6878d",
|
|
50
|
+
"@dxos/invariant": "0.8.4-main.fd6878d",
|
|
51
|
+
"@dxos/echo": "0.8.4-main.fd6878d",
|
|
52
|
+
"@dxos/live-object": "0.8.4-main.fd6878d",
|
|
53
|
+
"@dxos/log": "0.8.4-main.fd6878d",
|
|
54
|
+
"@dxos/plugin-client": "0.8.4-main.fd6878d",
|
|
55
|
+
"@dxos/plugin-graph": "0.8.4-main.fd6878d",
|
|
56
|
+
"@dxos/plugin-space": "0.8.4-main.fd6878d",
|
|
57
|
+
"@dxos/react-ui-stack": "0.8.4-main.fd6878d",
|
|
58
|
+
"@dxos/util": "0.8.4-main.fd6878d",
|
|
59
|
+
"@dxos/react-client": "0.8.4-main.fd6878d",
|
|
60
|
+
"@dxos/react-ui-gameboard": "0.8.4-main.fd6878d"
|
|
57
61
|
},
|
|
58
62
|
"devDependencies": {
|
|
59
63
|
"@types/react": "~18.2.0",
|
|
@@ -61,16 +65,16 @@
|
|
|
61
65
|
"react": "~18.2.0",
|
|
62
66
|
"react-dom": "~18.2.0",
|
|
63
67
|
"vite": "5.4.7",
|
|
64
|
-
"@dxos/plugin-theme": "0.8.4-main.
|
|
65
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
66
|
-
"@dxos/react-ui-theme": "0.8.4-main.
|
|
67
|
-
"@dxos/storybook-utils": "0.8.4-main.
|
|
68
|
+
"@dxos/plugin-theme": "0.8.4-main.fd6878d",
|
|
69
|
+
"@dxos/react-ui": "0.8.4-main.fd6878d",
|
|
70
|
+
"@dxos/react-ui-theme": "0.8.4-main.fd6878d",
|
|
71
|
+
"@dxos/storybook-utils": "0.8.4-main.fd6878d"
|
|
68
72
|
},
|
|
69
73
|
"peerDependencies": {
|
|
70
74
|
"react": "~18.2.0",
|
|
71
75
|
"react-dom": "~18.2.0",
|
|
72
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
73
|
-
"@dxos/react-ui-theme": "0.8.4-main.
|
|
76
|
+
"@dxos/react-ui": "0.8.4-main.fd6878d",
|
|
77
|
+
"@dxos/react-ui-theme": "0.8.4-main.fd6878d"
|
|
74
78
|
},
|
|
75
79
|
"publishConfig": {
|
|
76
80
|
"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 { 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,7 +24,7 @@ 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
30
|
},
|
|
@@ -37,7 +37,7 @@ export const ChessPlugin = () =>
|
|
|
37
37
|
contributes(
|
|
38
38
|
SpaceCapabilities.ObjectForm,
|
|
39
39
|
defineObjectForm({
|
|
40
|
-
objectSchema:
|
|
40
|
+
objectSchema: Chess.Game,
|
|
41
41
|
getIntent: () => createIntent(ChessAction.Create),
|
|
42
42
|
}),
|
|
43
43
|
),
|
|
@@ -53,8 +53,8 @@ export const ChessPlugin = () =>
|
|
|
53
53
|
activate: IntentResolver,
|
|
54
54
|
}),
|
|
55
55
|
defineModule({
|
|
56
|
-
id: `${meta.id}/module/
|
|
56
|
+
id: `${meta.id}/module/blueprint`,
|
|
57
57
|
activatesOn: Events.SetupArtifactDefinition,
|
|
58
|
-
activate:
|
|
58
|
+
activate: BlueprintDefinition,
|
|
59
59
|
}),
|
|
60
60
|
]);
|
|
@@ -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,34 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { ToolId } from '@dxos/ai';
|
|
6
|
+
import { Capabilities, contributes } from '@dxos/app-framework';
|
|
7
|
+
import { Blueprint, Template } from '@dxos/blueprints';
|
|
8
|
+
import { trim } from '@dxos/util';
|
|
9
|
+
|
|
10
|
+
import { move, play } from '../functions';
|
|
11
|
+
|
|
12
|
+
const functions = [move, play];
|
|
13
|
+
|
|
14
|
+
export default () => {
|
|
15
|
+
return [
|
|
16
|
+
contributes(
|
|
17
|
+
Capabilities.BlueprintDefinition,
|
|
18
|
+
Blueprint.make({
|
|
19
|
+
key: 'dxos.org/blueprint/chess',
|
|
20
|
+
name: 'Chess',
|
|
21
|
+
instructions: Template.make({
|
|
22
|
+
source: trim`
|
|
23
|
+
You are an expert chess player.
|
|
24
|
+
You could suggest a good next move or offer to play a move.
|
|
25
|
+
Don't actually make a move unless you are asked to.
|
|
26
|
+
To analyze a game you can retrieve the "pgn" property from the context object.
|
|
27
|
+
`,
|
|
28
|
+
}),
|
|
29
|
+
tools: functions.map((tool) => ToolId.make(tool.name)),
|
|
30
|
+
}),
|
|
31
|
+
),
|
|
32
|
+
contributes(Capabilities.Functions, functions),
|
|
33
|
+
];
|
|
34
|
+
};
|
|
@@ -4,6 +4,6 @@
|
|
|
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'));
|
|
@@ -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 } 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 storybook: Meta<DefaultStoryProps> = {
|
|
24
|
+
title: 'plugins/plugin-chess/Card',
|
|
25
|
+
render: ({ role, game }) => (
|
|
26
|
+
<CardContainer icon={meta.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 storybook;
|
|
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<DefaultStoryProps>;
|
|
48
|
+
|
|
49
|
+
export const Popover = {
|
|
50
|
+
args: {
|
|
51
|
+
role: 'card--popover',
|
|
52
|
+
game: game,
|
|
53
|
+
},
|
|
54
|
+
} satisfies Story;
|
|
55
|
+
|
|
56
|
+
export const Intrinsic = {
|
|
57
|
+
args: {
|
|
58
|
+
role: 'card--intrinsic',
|
|
59
|
+
game: game,
|
|
60
|
+
},
|
|
61
|
+
} satisfies Story;
|
|
62
|
+
|
|
63
|
+
export const Extrinsic = {
|
|
64
|
+
args: {
|
|
65
|
+
role: 'card--extrinsic',
|
|
66
|
+
game: game,
|
|
67
|
+
},
|
|
68
|
+
} satisfies Story;
|
|
@@ -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
|
-
|
|
16
|
-
|
|
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';
|
|
14
|
+
|
|
15
|
+
import { ChessboardArticle } from './ChessboardArticle';
|
|
29
16
|
|
|
30
|
-
const meta: Meta<typeof
|
|
17
|
+
const meta: Meta<typeof ChessboardArticle> = {
|
|
31
18
|
title: 'plugins/plugin-chess/Chessboard',
|
|
32
|
-
component:
|
|
33
|
-
|
|
34
|
-
|
|
19
|
+
component: ChessboardArticle,
|
|
20
|
+
decorators: [withClientProvider({ createIdentity: true }), withTheme, withLayout({ fullscreen: true })],
|
|
21
|
+
parameters: {
|
|
22
|
+
translations,
|
|
23
|
+
},
|
|
35
24
|
};
|
|
36
25
|
|
|
37
|
-
type Story = StoryObj<typeof
|
|
26
|
+
type Story = StoryObj<typeof meta>;
|
|
38
27
|
|
|
39
28
|
export default meta;
|
|
40
29
|
|
|
41
|
-
export const Default
|
|
30
|
+
export const Default = {
|
|
31
|
+
args: {
|
|
32
|
+
game: Chess.makeGame(),
|
|
33
|
+
},
|
|
34
|
+
} satisfies Story;
|
|
35
|
+
|
|
36
|
+
export const EndGame = {
|
|
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
|
+
} satisfies Story;
|
|
43
|
+
|
|
44
|
+
export const Promption = {
|
|
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
|
+
} satisfies Story;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { type PropsWithChildren, useCallback, useEffect, useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
import { log } from '@dxos/log';
|
|
8
|
+
import { type ThemedClassName } from '@dxos/react-ui';
|
|
9
|
+
import {
|
|
10
|
+
ChessModel,
|
|
11
|
+
Gameboard,
|
|
12
|
+
type GameboardRootProps,
|
|
13
|
+
Chessboard as NativeChessboard,
|
|
14
|
+
type ChessboardProps as NativeChessboardProps,
|
|
15
|
+
} from '@dxos/react-ui-gameboard';
|
|
16
|
+
import { mx } from '@dxos/react-ui-theme';
|
|
17
|
+
|
|
18
|
+
import { type Chess } from '../types';
|
|
19
|
+
|
|
20
|
+
import { ChessboardInfo, type ChessboardInfoProps } from './ChessboardInfo';
|
|
21
|
+
import { ChessboardPlayers, type ChessboardPlayersProps } from './ChessboardPlayers';
|
|
22
|
+
|
|
23
|
+
export class ExtendedChessModel extends ChessModel {
|
|
24
|
+
constructor(readonly object: Chess.Game) {
|
|
25
|
+
super();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//
|
|
30
|
+
// Root
|
|
31
|
+
//
|
|
32
|
+
|
|
33
|
+
type ChessboardRootProps = PropsWithChildren<{
|
|
34
|
+
game: Chess.Game;
|
|
35
|
+
}>;
|
|
36
|
+
|
|
37
|
+
const ChessboardRoot = ({ game, children }: ChessboardRootProps) => {
|
|
38
|
+
const model = useMemo(() => new ExtendedChessModel(game), []);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
model.update(game.pgn);
|
|
41
|
+
log('update', { pgn: game.pgn });
|
|
42
|
+
}, [game.pgn]);
|
|
43
|
+
|
|
44
|
+
const handleDrop = useCallback<NonNullable<GameboardRootProps<ChessModel>['onDrop']>>(
|
|
45
|
+
(move) => {
|
|
46
|
+
if (model.makeMove(move)) {
|
|
47
|
+
game.pgn = model.pgn;
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return false;
|
|
52
|
+
},
|
|
53
|
+
[model],
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<Gameboard.Root model={model} onDrop={handleDrop}>
|
|
58
|
+
{children}
|
|
59
|
+
</Gameboard.Root>
|
|
60
|
+
);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
//
|
|
64
|
+
// Content
|
|
65
|
+
//
|
|
66
|
+
|
|
67
|
+
type Role = 'card--popover' | 'card--intrinsic' | 'card--extrinsic';
|
|
68
|
+
|
|
69
|
+
type ChessboardContentProps = ThemedClassName<PropsWithChildren<{ role?: Role }>>;
|
|
70
|
+
|
|
71
|
+
const ChessboardContent = ({ classNames, children, role }: ChessboardContentProps) => {
|
|
72
|
+
return (
|
|
73
|
+
<Gameboard.Content
|
|
74
|
+
classNames={mx(classNames, role === 'card--popover' && 'size-container popover-square')}
|
|
75
|
+
grow={!role || role === 'card--extrinsic'}
|
|
76
|
+
contain={!role || role === 'card--extrinsic' || role === 'card--popover'}
|
|
77
|
+
>
|
|
78
|
+
{children}
|
|
79
|
+
</Gameboard.Content>
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
//
|
|
84
|
+
// Chessboard
|
|
85
|
+
//
|
|
86
|
+
|
|
87
|
+
export const Chessboard = {
|
|
88
|
+
Root: ChessboardRoot,
|
|
89
|
+
Content: ChessboardContent,
|
|
90
|
+
Board: NativeChessboard,
|
|
91
|
+
Info: ChessboardInfo,
|
|
92
|
+
Players: ChessboardPlayers,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export type {
|
|
96
|
+
ChessboardRootProps,
|
|
97
|
+
ChessboardContentProps,
|
|
98
|
+
NativeChessboardProps as ChessboardBoardProps,
|
|
99
|
+
ChessboardInfoProps,
|
|
100
|
+
ChessboardPlayersProps,
|
|
101
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { IconButton, 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 } from './Chessboard';
|
|
16
|
+
|
|
17
|
+
export const ChessboardArticle = ({ game }: { game: Chess.Game }) => {
|
|
18
|
+
const { t } = useTranslation(meta.id);
|
|
19
|
+
const [orientation, setOrientation] = useState<Player>('white');
|
|
20
|
+
const [open, setOpen] = useState(true);
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<StackItem.Content classNames='@container bs-full is-full overflow-hidden'>
|
|
24
|
+
<Chessboard.Root game={game}>
|
|
25
|
+
<div className={mx('grid grid-rows-[1fr_4rem] bs-full is-full gap-2', open && '@3xl:grid-cols-[1fr_320px]')}>
|
|
26
|
+
<Chessboard.Content>
|
|
27
|
+
<Chessboard.Board orientation={orientation} />
|
|
28
|
+
</Chessboard.Content>
|
|
29
|
+
{open && (
|
|
30
|
+
<div className='hidden @3xl:flex flex-col p-8 justify-center items-center overflow-hidden'>
|
|
31
|
+
<Chessboard.Info
|
|
32
|
+
orientation={orientation}
|
|
33
|
+
min={8}
|
|
34
|
+
max={8}
|
|
35
|
+
onOrientationChange={setOrientation}
|
|
36
|
+
onClose={() => setOpen(false)}
|
|
37
|
+
/>
|
|
38
|
+
</div>
|
|
39
|
+
)}
|
|
40
|
+
<div className='flex justify-center items-center'>
|
|
41
|
+
<Chessboard.Players>
|
|
42
|
+
<IconButton
|
|
43
|
+
variant='ghost'
|
|
44
|
+
icon='ph--info--regular'
|
|
45
|
+
iconOnly
|
|
46
|
+
label={t('button toggle info')}
|
|
47
|
+
size={6}
|
|
48
|
+
classNames={mx('invisible', !open && '@3xl:visible')}
|
|
49
|
+
onClick={() => setOpen((open) => !open)}
|
|
50
|
+
/>
|
|
51
|
+
</Chessboard.Players>
|
|
52
|
+
</div>
|
|
53
|
+
</div>
|
|
54
|
+
</Chessboard.Root>
|
|
55
|
+
</StackItem.Content>
|
|
56
|
+
);
|
|
57
|
+
};
|