@dxos/plugin-chess 0.7.4 → 0.7.5-labs.5f04cf6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/ChessContainer-G736GS2V.mjs +26 -0
- package/dist/lib/browser/ChessContainer-G736GS2V.mjs.map +7 -0
- package/dist/lib/browser/artifact-YWAB5JJL.mjs +174 -0
- package/dist/lib/browser/artifact-YWAB5JJL.mjs.map +7 -0
- package/dist/lib/browser/chunk-JUAC2NNR.mjs +548 -0
- package/dist/lib/browser/chunk-JUAC2NNR.mjs.map +7 -0
- package/dist/lib/browser/chunk-LAYER2WV.mjs +8 -0
- package/dist/lib/browser/chunk-LAYER2WV.mjs.map +7 -0
- package/dist/lib/browser/chunk-VYBCAEUF.mjs +66 -0
- package/dist/lib/browser/chunk-VYBCAEUF.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +76 -623
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/intent-resolver-UZRNSQFI.mjs +25 -0
- package/dist/lib/browser/intent-resolver-UZRNSQFI.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react-surface-EP4LXPH7.mjs +50 -0
- package/dist/lib/browser/react-surface-EP4LXPH7.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +3 -4
- package/dist/lib/node/ChessContainer-P4BZ62FN.cjs +52 -0
- package/dist/lib/node/ChessContainer-P4BZ62FN.cjs.map +7 -0
- package/dist/lib/node/artifact-YWL3LBIO.cjs +189 -0
- package/dist/lib/node/artifact-YWL3LBIO.cjs.map +7 -0
- package/dist/lib/node/chunk-6F6WTM5L.cjs +40 -0
- package/dist/lib/node/chunk-6F6WTM5L.cjs.map +7 -0
- package/dist/lib/node/chunk-HPYER4GF.cjs +574 -0
- package/dist/lib/node/chunk-HPYER4GF.cjs.map +7 -0
- package/dist/lib/node/{chunk-3VNSWSKR.cjs → chunk-J5YKJRP3.cjs} +39 -14
- package/dist/lib/node/chunk-J5YKJRP3.cjs.map +7 -0
- package/dist/lib/node/index.cjs +75 -599
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/intent-resolver-AENA6D5K.cjs +40 -0
- package/dist/lib/node/intent-resolver-AENA6D5K.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/react-surface-JMOSMAIC.cjs +70 -0
- package/dist/lib/node/react-surface-JMOSMAIC.cjs.map +7 -0
- package/dist/lib/node/types/index.cjs +6 -7
- package/dist/lib/node/types/index.cjs.map +2 -2
- package/dist/lib/node-esm/ChessContainer-2LFJ6RHB.mjs +27 -0
- package/dist/lib/node-esm/ChessContainer-2LFJ6RHB.mjs.map +7 -0
- package/dist/lib/node-esm/artifact-B6IEF7U5.mjs +175 -0
- package/dist/lib/node-esm/artifact-B6IEF7U5.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-OMGVSBVI.mjs +550 -0
- package/dist/lib/node-esm/chunk-OMGVSBVI.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-QXDXLFXD.mjs +10 -0
- package/dist/lib/node-esm/chunk-QXDXLFXD.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-TXUWVQWY.mjs +68 -0
- package/dist/lib/node-esm/chunk-TXUWVQWY.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +76 -623
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/intent-resolver-T7NNHOYR.mjs +26 -0
- package/dist/lib/node-esm/intent-resolver-T7NNHOYR.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/react-surface-ENB7VY45.mjs +51 -0
- package/dist/lib/node-esm/react-surface-ENB7VY45.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +3 -4
- package/dist/types/src/ChessPlugin.d.ts +1 -3
- package/dist/types/src/ChessPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/artifact.d.ts +11 -0
- package/dist/types/src/capabilities/artifact.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +4 -0
- package/dist/types/src/capabilities/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/intent-resolver.d.ts +4 -0
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface.d.ts +4 -0
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
- package/dist/types/src/components/Chess.d.ts +2 -2
- package/dist/types/src/components/Chess.d.ts.map +1 -1
- package/dist/types/src/components/ChessContainer.d.ts.map +1 -1
- package/dist/types/src/components/Chessboard/Chessboard.d.ts +2 -2
- package/dist/types/src/components/Chessboard/Chessboard.d.ts.map +1 -1
- package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts +14 -3
- package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +2 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +3 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +1 -2
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/types/schema.d.ts +13 -9
- package/dist/types/src/types/schema.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +18 -8
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +24 -26
- package/src/ChessPlugin.tsx +51 -89
- package/src/capabilities/artifact.ts +109 -0
- package/src/capabilities/index.ts +9 -0
- package/src/capabilities/intent-resolver.ts +24 -0
- package/src/capabilities/react-surface.tsx +38 -0
- package/src/components/Chess.tsx +7 -6
- package/src/components/ChessContainer.tsx +3 -2
- package/src/components/Chessboard/Chessboard.stories.tsx +21 -8
- package/src/components/Chessboard/Chessboard.tsx +29 -17
- package/src/components/index.ts +3 -0
- package/src/index.ts +3 -3
- package/src/meta.ts +1 -1
- package/src/translations.ts +2 -2
- package/src/types/schema.ts +4 -1
- package/src/types/types.ts +15 -23
- package/dist/lib/browser/chunk-2H2BTWYT.mjs +0 -15
- package/dist/lib/browser/chunk-2H2BTWYT.mjs.map +0 -7
- package/dist/lib/browser/chunk-BG7NXK4E.mjs +0 -42
- package/dist/lib/browser/chunk-BG7NXK4E.mjs.map +0 -7
- package/dist/lib/browser/meta.mjs +0 -9
- package/dist/lib/browser/meta.mjs.map +0 -7
- package/dist/lib/node/chunk-3VNSWSKR.cjs.map +0 -7
- package/dist/lib/node/chunk-Q4NVPVPX.cjs +0 -38
- package/dist/lib/node/chunk-Q4NVPVPX.cjs.map +0 -7
- package/dist/lib/node/meta.cjs +0 -30
- package/dist/lib/node/meta.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-RIQ5MOYO.mjs +0 -43
- package/dist/lib/node-esm/chunk-RIQ5MOYO.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-WNE2FPQW.mjs +0 -17
- package/dist/lib/node-esm/chunk-WNE2FPQW.mjs.map +0 -7
- package/dist/lib/node-esm/meta.mjs +0 -10
- package/dist/lib/node-esm/meta.mjs.map +0 -7
|
@@ -8,20 +8,24 @@ export declare const MoveSchema: S.mutable<S.SchemaClass<{
|
|
|
8
8
|
readonly target?: string | undefined;
|
|
9
9
|
readonly piece?: string | undefined;
|
|
10
10
|
}, never>>;
|
|
11
|
-
declare const
|
|
12
|
-
|
|
13
|
-
playerBlack?: string | undefined;
|
|
14
|
-
moves?: string[] | undefined;
|
|
15
|
-
pgn?: string | undefined;
|
|
16
|
-
} & {
|
|
17
|
-
id: string;
|
|
18
|
-
}, S.Struct.Encoded<{
|
|
11
|
+
declare const ChessType_base: import("@dxos/echo-schema").TypedObjectPrototype<import("packages/core/echo/echo-schema/dist/types/src/object/common").TypedObjectFields<{
|
|
12
|
+
name: S.optional<typeof S.String>;
|
|
19
13
|
playerWhite: typeof S.String;
|
|
20
14
|
playerBlack: typeof S.String;
|
|
21
15
|
moves: S.mutable<S.Array$<typeof S.String>>;
|
|
22
16
|
pgn: typeof S.String;
|
|
17
|
+
fen: typeof S.String;
|
|
18
|
+
}, {
|
|
19
|
+
partial: true;
|
|
20
|
+
}>, S.Struct.Encoded<{
|
|
21
|
+
name: S.optional<typeof S.String>;
|
|
22
|
+
playerWhite: typeof S.String;
|
|
23
|
+
playerBlack: typeof S.String;
|
|
24
|
+
moves: S.mutable<S.Array$<typeof S.String>>;
|
|
25
|
+
pgn: typeof S.String;
|
|
26
|
+
fen: typeof S.String;
|
|
23
27
|
}>>;
|
|
24
|
-
export declare class
|
|
28
|
+
export declare class ChessType extends ChessType_base {
|
|
25
29
|
}
|
|
26
30
|
export {};
|
|
27
31
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/types/schema.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAe,MAAM,mBAAmB,CAAC;AAEnD,eAAO,MAAM,UAAU;;;;;;;;UAQtB,CAAC
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/types/schema.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAe,MAAM,mBAAmB,CAAC;AAEnD,eAAO,MAAM,UAAU;;;;;;;;UAQtB,CAAC;;;;;;;;;;;;;;;;;;AAEF,qBAAa,SAAU,SAAQ,cAW9B;CAAG"}
|
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { S } from '@dxos/echo-schema';
|
|
2
|
+
import { ChessType } from './schema';
|
|
3
|
+
export declare namespace ChessAction {
|
|
4
|
+
const Create_base: S.TaggedClass<Create, "dxos.org/plugin/chess/action/create", {
|
|
5
|
+
readonly _tag: S.tag<"dxos.org/plugin/chess/action/create">;
|
|
6
|
+
} & {
|
|
7
|
+
input: S.Struct<{
|
|
8
|
+
name: S.optional<typeof S.String>;
|
|
9
|
+
fen: S.optional<typeof S.String>;
|
|
10
|
+
}>;
|
|
11
|
+
output: S.Struct<{
|
|
12
|
+
object: typeof ChessType;
|
|
13
|
+
}>;
|
|
14
|
+
}>;
|
|
15
|
+
export class Create extends Create_base {
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
6
18
|
}
|
|
7
|
-
export
|
|
8
|
-
export type ChessPluginProvides = SurfaceProvides & IntentResolverProvides & GraphBuilderProvides & MetadataRecordsProvides & TranslationsProvides & SchemaProvides;
|
|
9
|
-
export declare const isObject: (object: unknown) => object is GameType;
|
|
19
|
+
export declare const isObject: (object: unknown) => object is typeof ChessType;
|
|
10
20
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types/types.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAgB,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGrC,yBAAiB,WAAW,CAAC;;;;;;;;;;;;IAG3B,MAAM,OAAO,MAAO,SAAQ,WAQ1B;KAAG;;CACN;AAED,eAAO,MAAM,QAAQ,WAAY,OAAO,KAAG,MAAM,IAAI,OAAO,SAE3D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":"5.7.2"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/plugin-chess",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5-labs.5f04cf6",
|
|
4
4
|
"description": "Chess for new plugin",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -13,11 +13,6 @@
|
|
|
13
13
|
"browser": "./dist/lib/browser/index.mjs",
|
|
14
14
|
"node": "./dist/lib/node-esm/index.mjs"
|
|
15
15
|
},
|
|
16
|
-
"./meta": {
|
|
17
|
-
"types": "./dist/types/src/meta.d.ts",
|
|
18
|
-
"browser": "./dist/lib/browser/meta.mjs",
|
|
19
|
-
"node": "./dist/lib/node-esm/meta.mjs"
|
|
20
|
-
},
|
|
21
16
|
"./types": {
|
|
22
17
|
"types": "./dist/types/src/types/index.d.ts",
|
|
23
18
|
"browser": "./dist/lib/browser/types/index.mjs",
|
|
@@ -27,9 +22,6 @@
|
|
|
27
22
|
"types": "dist/types/src/index.d.ts",
|
|
28
23
|
"typesVersions": {
|
|
29
24
|
"*": {
|
|
30
|
-
"meta": [
|
|
31
|
-
"dist/types/src/meta.d.ts"
|
|
32
|
-
],
|
|
33
25
|
"types": [
|
|
34
26
|
"dist/types/src/types/index.d.ts"
|
|
35
27
|
]
|
|
@@ -42,37 +34,43 @@
|
|
|
42
34
|
"dependencies": {
|
|
43
35
|
"@effect/schema": "^0.75.5",
|
|
44
36
|
"@preact/signals-core": "^1.6.0",
|
|
45
|
-
"chess.js": "^1.0.0
|
|
46
|
-
"react-chessboard": "^4.7.
|
|
37
|
+
"chess.js": "^1.0.0",
|
|
38
|
+
"react-chessboard": "^4.7.2",
|
|
39
|
+
"react-dnd-html5-backend": "^16.0.1",
|
|
47
40
|
"react-resize-detector": "^11.0.1",
|
|
48
|
-
"@dxos/app-framework": "0.7.
|
|
49
|
-
"@dxos/
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/live-object": "0.7.
|
|
56
|
-
"@dxos/
|
|
57
|
-
"@dxos/plugin-
|
|
41
|
+
"@dxos/app-framework": "0.7.5-labs.5f04cf6",
|
|
42
|
+
"@dxos/artifact": "0.7.5-labs.5f04cf6",
|
|
43
|
+
"@dxos/assistant": "0.7.5-labs.5f04cf6",
|
|
44
|
+
"@dxos/echo-schema": "0.7.5-labs.5f04cf6",
|
|
45
|
+
"@dxos/display-name": "0.7.5-labs.5f04cf6",
|
|
46
|
+
"@dxos/async": "0.7.5-labs.5f04cf6",
|
|
47
|
+
"@dxos/invariant": "0.7.5-labs.5f04cf6",
|
|
48
|
+
"@dxos/live-object": "0.7.5-labs.5f04cf6",
|
|
49
|
+
"@dxos/plugin-client": "0.7.5-labs.5f04cf6",
|
|
50
|
+
"@dxos/plugin-graph": "0.7.5-labs.5f04cf6",
|
|
51
|
+
"@dxos/plugin-space": "0.7.5-labs.5f04cf6",
|
|
52
|
+
"@dxos/react-ui-stack": "0.7.5-labs.5f04cf6",
|
|
53
|
+
"@dxos/react-client": "0.7.5-labs.5f04cf6"
|
|
58
54
|
},
|
|
59
55
|
"devDependencies": {
|
|
60
56
|
"@phosphor-icons/react": "^2.1.5",
|
|
61
57
|
"@types/react": "~18.2.0",
|
|
62
58
|
"@types/react-dom": "~18.2.0",
|
|
59
|
+
"effect": "^3.12.3",
|
|
63
60
|
"react": "~18.2.0",
|
|
64
61
|
"react-dom": "~18.2.0",
|
|
65
62
|
"vite": "5.4.7",
|
|
66
|
-
"@dxos/react-ui": "0.7.
|
|
67
|
-
"@dxos/
|
|
68
|
-
"@dxos/
|
|
63
|
+
"@dxos/react-ui-theme": "0.7.5-labs.5f04cf6",
|
|
64
|
+
"@dxos/storybook-utils": "0.7.5-labs.5f04cf6",
|
|
65
|
+
"@dxos/react-ui": "0.7.5-labs.5f04cf6"
|
|
69
66
|
},
|
|
70
67
|
"peerDependencies": {
|
|
71
68
|
"@phosphor-icons/react": "^2.1.5",
|
|
69
|
+
"effect": "^3.12.3",
|
|
72
70
|
"react": "~18.2.0",
|
|
73
71
|
"react-dom": "~18.2.0",
|
|
74
|
-
"@dxos/react-ui": "0.7.
|
|
75
|
-
"@dxos/react-ui-theme": "0.7.
|
|
72
|
+
"@dxos/react-ui": "0.7.5-labs.5f04cf6",
|
|
73
|
+
"@dxos/react-ui-theme": "0.7.5-labs.5f04cf6"
|
|
76
74
|
},
|
|
77
75
|
"publishConfig": {
|
|
78
76
|
"access": "public"
|
package/src/ChessPlugin.tsx
CHANGED
|
@@ -2,98 +2,60 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import {
|
|
6
|
+
Capabilities,
|
|
7
|
+
contributes,
|
|
8
|
+
createIntent,
|
|
9
|
+
defineModule,
|
|
10
|
+
definePlugin,
|
|
11
|
+
Events,
|
|
12
|
+
oneOf,
|
|
13
|
+
} from '@dxos/app-framework';
|
|
14
|
+
import { ClientCapabilities, ClientEvents } from '@dxos/plugin-client';
|
|
6
15
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { parseClientPlugin } from '@dxos/plugin-client';
|
|
10
|
-
import { type ActionGroup, createExtension, isActionGroup } from '@dxos/plugin-graph';
|
|
11
|
-
import { SpaceAction } from '@dxos/plugin-space';
|
|
12
|
-
|
|
13
|
-
import ChessContainer from './components/ChessContainer';
|
|
14
|
-
import meta, { CHESS_PLUGIN } from './meta';
|
|
16
|
+
import { Artifact, IntentResolver, ReactSurface } from './capabilities';
|
|
17
|
+
import { CHESS_PLUGIN, meta } from './meta';
|
|
15
18
|
import translations from './translations';
|
|
16
|
-
import { ChessAction,
|
|
19
|
+
import { ChessAction, ChessType } from './types';
|
|
17
20
|
|
|
18
|
-
export const ChessPlugin = ()
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
export const ChessPlugin = () =>
|
|
22
|
+
definePlugin(meta, [
|
|
23
|
+
defineModule({
|
|
24
|
+
id: `${meta.id}/module/translations`,
|
|
25
|
+
activatesOn: Events.SetupTranslations,
|
|
26
|
+
activate: () => contributes(Capabilities.Translations, translations),
|
|
27
|
+
}),
|
|
28
|
+
defineModule({
|
|
29
|
+
id: `${meta.id}/module/metadata`,
|
|
30
|
+
activatesOn: oneOf(Events.Startup, Events.SetupAppGraph),
|
|
31
|
+
activate: () =>
|
|
32
|
+
contributes(Capabilities.Metadata, {
|
|
33
|
+
id: ChessType.typename,
|
|
34
|
+
metadata: {
|
|
35
|
+
createObject: (props: { name?: string }) => createIntent(ChessAction.Create, props),
|
|
26
36
|
placeholder: ['game title placeholder', { ns: CHESS_PLUGIN }],
|
|
27
37
|
icon: 'ph--shield-chevron--regular',
|
|
28
38
|
},
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return [
|
|
56
|
-
{
|
|
57
|
-
id: `${CHESS_PLUGIN}/create/${node.id}`,
|
|
58
|
-
data: async () => {
|
|
59
|
-
await dispatch([
|
|
60
|
-
{ plugin: CHESS_PLUGIN, action: ChessAction.CREATE },
|
|
61
|
-
{ action: SpaceAction.ADD_OBJECT, data: { target } },
|
|
62
|
-
{ action: NavigationAction.OPEN },
|
|
63
|
-
]);
|
|
64
|
-
},
|
|
65
|
-
properties: {
|
|
66
|
-
label: ['create game label', { ns: CHESS_PLUGIN }],
|
|
67
|
-
icon: 'ph--shield-chevron--regular',
|
|
68
|
-
testId: 'chessPlugin.createObject',
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
];
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
translations,
|
|
77
|
-
surface: {
|
|
78
|
-
component: ({ data, role }) => {
|
|
79
|
-
switch (role) {
|
|
80
|
-
case 'article':
|
|
81
|
-
case 'section':
|
|
82
|
-
return isObject(data.object) ? <ChessContainer game={data.object} role={role} /> : null;
|
|
83
|
-
default:
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
intent: {
|
|
89
|
-
resolver: (intent) => {
|
|
90
|
-
switch (intent.action) {
|
|
91
|
-
case ChessAction.CREATE: {
|
|
92
|
-
return { data: create(GameType, {}) };
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
};
|
|
39
|
+
}),
|
|
40
|
+
}),
|
|
41
|
+
defineModule({
|
|
42
|
+
id: `${meta.id}/module/schema`,
|
|
43
|
+
activatesOn: ClientEvents.SetupClient,
|
|
44
|
+
activate: () => contributes(ClientCapabilities.Schema, [ChessType]),
|
|
45
|
+
}),
|
|
46
|
+
defineModule({
|
|
47
|
+
id: `${meta.id}/module/react-surface`,
|
|
48
|
+
activatesOn: Events.Startup,
|
|
49
|
+
activate: ReactSurface,
|
|
50
|
+
}),
|
|
51
|
+
defineModule({
|
|
52
|
+
id: `${meta.id}/module/intent-resolver`,
|
|
53
|
+
activatesOn: Events.Startup,
|
|
54
|
+
activate: IntentResolver,
|
|
55
|
+
}),
|
|
56
|
+
defineModule({
|
|
57
|
+
id: `${meta.id}/module/artifact`,
|
|
58
|
+
activatesOn: Events.Startup,
|
|
59
|
+
activate: Artifact,
|
|
60
|
+
}),
|
|
61
|
+
]);
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Chess } from 'chess.js';
|
|
6
|
+
import { pipe } from 'effect';
|
|
7
|
+
|
|
8
|
+
import { Capabilities, chain, contributes, createIntent, type PromiseIntentDispatcher } from '@dxos/app-framework';
|
|
9
|
+
import { defineArtifact, defineTool, ToolResult } from '@dxos/artifact';
|
|
10
|
+
import { createArtifactElement } from '@dxos/assistant';
|
|
11
|
+
import { isInstanceOf, ObjectId, S } from '@dxos/echo-schema';
|
|
12
|
+
import { invariant } from '@dxos/invariant';
|
|
13
|
+
import { SpaceAction } from '@dxos/plugin-space/types';
|
|
14
|
+
import { Filter, type Space } from '@dxos/react-client/echo';
|
|
15
|
+
|
|
16
|
+
import { ChessAction, ChessType } from '../types';
|
|
17
|
+
|
|
18
|
+
// TODO(burdon): Factor out.
|
|
19
|
+
declare global {
|
|
20
|
+
interface ToolContextExtensions {
|
|
21
|
+
space?: Space;
|
|
22
|
+
dispatch?: PromiseIntentDispatcher;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default () => {
|
|
27
|
+
const definition = defineArtifact({
|
|
28
|
+
id: 'plugin-chess',
|
|
29
|
+
instructions: `
|
|
30
|
+
Chess:
|
|
31
|
+
- If the user's message relates to a chess game, you must return the chess game inside the artifact tag as a valid FEN string with no additional text.
|
|
32
|
+
`,
|
|
33
|
+
schema: ChessType,
|
|
34
|
+
tools: [
|
|
35
|
+
defineTool({
|
|
36
|
+
name: 'chess_new',
|
|
37
|
+
description: 'Create a new chess game. Returns the artifact definition for the game',
|
|
38
|
+
schema: S.Struct({
|
|
39
|
+
fen: S.String.annotations({ description: 'The state of the chess game in the FEN format.' }),
|
|
40
|
+
}),
|
|
41
|
+
execute: async ({ fen }, { extensions }) => {
|
|
42
|
+
invariant(extensions?.space, 'No space');
|
|
43
|
+
invariant(extensions?.dispatch, 'No intent dispatcher');
|
|
44
|
+
const intent = pipe(
|
|
45
|
+
createIntent(ChessAction.Create, { fen }),
|
|
46
|
+
chain(SpaceAction.AddObject, { target: extensions.space }),
|
|
47
|
+
);
|
|
48
|
+
const { data, error } = await extensions.dispatch(intent);
|
|
49
|
+
if (!data || error) {
|
|
50
|
+
return ToolResult.Error(error?.message ?? 'Failed to create chess game');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return ToolResult.Success(createArtifactElement(data.id));
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
defineTool({
|
|
57
|
+
name: 'chess_query',
|
|
58
|
+
description: 'Query all active chess games.',
|
|
59
|
+
schema: S.Struct({}),
|
|
60
|
+
execute: async (_, { extensions }) => {
|
|
61
|
+
invariant(extensions?.space, 'No space');
|
|
62
|
+
const { objects: games } = await extensions.space.db.query(Filter.schema(ChessType)).run();
|
|
63
|
+
invariant(games.length > 0, 'No chess games found');
|
|
64
|
+
return ToolResult.Success(games);
|
|
65
|
+
},
|
|
66
|
+
}),
|
|
67
|
+
defineTool({
|
|
68
|
+
name: 'chess_inspect',
|
|
69
|
+
description: 'Get the current state of the chess game.',
|
|
70
|
+
schema: S.Struct({ id: ObjectId }),
|
|
71
|
+
execute: async ({ id }, { extensions }) => {
|
|
72
|
+
invariant(extensions?.space, 'No space');
|
|
73
|
+
const { objects: games } = await extensions.space.db.query(Filter.schema(ChessType)).run();
|
|
74
|
+
const game = games.find((game) => game.id === id);
|
|
75
|
+
invariant(isInstanceOf(ChessType, game));
|
|
76
|
+
return ToolResult.Success(game.fen);
|
|
77
|
+
},
|
|
78
|
+
}),
|
|
79
|
+
defineTool({
|
|
80
|
+
name: 'chess_move',
|
|
81
|
+
description: 'Make a move in the chess game.',
|
|
82
|
+
schema: S.Struct({
|
|
83
|
+
id: ObjectId,
|
|
84
|
+
move: S.String.annotations({
|
|
85
|
+
description: 'The move to make in the chess game.',
|
|
86
|
+
examples: ['e4', 'Bf3'],
|
|
87
|
+
}),
|
|
88
|
+
}),
|
|
89
|
+
execute: async ({ id, move }, { extensions }) => {
|
|
90
|
+
invariant(extensions?.space, 'No space');
|
|
91
|
+
const { objects: games } = await extensions.space.db.query(Filter.schema(ChessType)).run();
|
|
92
|
+
const game = games.find((game) => game.id === id);
|
|
93
|
+
invariant(isInstanceOf(ChessType, game));
|
|
94
|
+
const board = new Chess(game.fen);
|
|
95
|
+
try {
|
|
96
|
+
board.move(move);
|
|
97
|
+
} catch (error: any) {
|
|
98
|
+
return ToolResult.Error(error.message);
|
|
99
|
+
}
|
|
100
|
+
game.pgn = board.pgn();
|
|
101
|
+
game.fen = board.fen();
|
|
102
|
+
return ToolResult.Success(game.fen);
|
|
103
|
+
},
|
|
104
|
+
}),
|
|
105
|
+
],
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return contributes(Capabilities.ArtifactDefinition, definition);
|
|
109
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { lazy } from '@dxos/app-framework';
|
|
6
|
+
|
|
7
|
+
export const Artifact = lazy(() => import('./artifact'));
|
|
8
|
+
export const IntentResolver = lazy(() => import('./intent-resolver'));
|
|
9
|
+
export const ReactSurface = lazy(() => import('./react-surface'));
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Chess } from 'chess.js';
|
|
6
|
+
|
|
7
|
+
import { Capabilities, contributes, createResolver } from '@dxos/app-framework';
|
|
8
|
+
import { create } from '@dxos/live-object';
|
|
9
|
+
|
|
10
|
+
import { ChessAction, ChessType } from '../types';
|
|
11
|
+
|
|
12
|
+
export default () =>
|
|
13
|
+
contributes(
|
|
14
|
+
Capabilities.IntentResolver,
|
|
15
|
+
createResolver(ChessAction.Create, ({ name, fen }) => {
|
|
16
|
+
const pgn = fen ? new Chess(fen).pgn() : undefined;
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
data: {
|
|
20
|
+
object: create(ChessType, { name, fen, pgn }),
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}),
|
|
24
|
+
);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Chess } from 'chess.js';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
8
|
+
import { Capabilities, contributes, createSurface } from '@dxos/app-framework';
|
|
9
|
+
import { isInstanceOf } from '@dxos/echo-schema';
|
|
10
|
+
|
|
11
|
+
import { Chessboard, ChessContainer } from '../components';
|
|
12
|
+
import { CHESS_PLUGIN } from '../meta';
|
|
13
|
+
import { ChessType, isObject } from '../types';
|
|
14
|
+
|
|
15
|
+
export default () =>
|
|
16
|
+
contributes(Capabilities.ReactSurface, [
|
|
17
|
+
createSurface({
|
|
18
|
+
id: CHESS_PLUGIN,
|
|
19
|
+
role: ['article', 'section'],
|
|
20
|
+
filter: (data): data is { subject: ChessType } => isObject(data.subject),
|
|
21
|
+
component: ({ data, role }) => <ChessContainer game={data.subject} role={role} />,
|
|
22
|
+
}),
|
|
23
|
+
createSurface({
|
|
24
|
+
id: 'plugin-chess',
|
|
25
|
+
role: 'canvas-node',
|
|
26
|
+
filter: (data): data is any => isInstanceOf(ChessType, data),
|
|
27
|
+
component: ({ data }) => (
|
|
28
|
+
<Chessboard
|
|
29
|
+
model={{ chess: new Chess(data.fen) }}
|
|
30
|
+
onUpdate={(move) => {
|
|
31
|
+
const board = new Chess(data.fen);
|
|
32
|
+
board.move(move);
|
|
33
|
+
data.value = board.fen();
|
|
34
|
+
}}
|
|
35
|
+
/>
|
|
36
|
+
),
|
|
37
|
+
}),
|
|
38
|
+
]);
|
package/src/components/Chess.tsx
CHANGED
|
@@ -13,14 +13,14 @@ import { Input, Select, useThemeContext } from '@dxos/react-ui';
|
|
|
13
13
|
import { getSize, mx } from '@dxos/react-ui-theme';
|
|
14
14
|
|
|
15
15
|
import { Chessboard, type ChessModel, type ChessMove } from './Chessboard';
|
|
16
|
-
import { type
|
|
16
|
+
import { type ChessType } from '../types';
|
|
17
17
|
|
|
18
|
-
const useChessModel = (game:
|
|
18
|
+
const useChessModel = (game: ChessType) => {
|
|
19
19
|
const [model, setModel] = useState<ChessModel>();
|
|
20
20
|
|
|
21
21
|
useEffect(() => {
|
|
22
22
|
if (!model || game.pgn !== model?.chess.pgn()) {
|
|
23
|
-
const chess = new ChessJs();
|
|
23
|
+
const chess = new ChessJs(game.pgn ? undefined : game.fen);
|
|
24
24
|
if (game.pgn) {
|
|
25
25
|
chess.loadPgn(game.pgn);
|
|
26
26
|
}
|
|
@@ -32,7 +32,8 @@ const useChessModel = (game: GameType) => {
|
|
|
32
32
|
const handleUpdate = (move: ChessMove) => {
|
|
33
33
|
invariant(model);
|
|
34
34
|
if (model.chess.move(move)) {
|
|
35
|
-
game
|
|
35
|
+
game.pgn = model.chess.pgn();
|
|
36
|
+
game.fen = model.chess.fen();
|
|
36
37
|
setModel({ ...model });
|
|
37
38
|
}
|
|
38
39
|
};
|
|
@@ -40,7 +41,7 @@ const useChessModel = (game: GameType) => {
|
|
|
40
41
|
return { model, handleUpdate };
|
|
41
42
|
};
|
|
42
43
|
|
|
43
|
-
export const Chess = ({ space, game, playerSelector }: { space: Space; game:
|
|
44
|
+
export const Chess = ({ space, game, playerSelector }: { space: Space; game: ChessType; playerSelector?: boolean }) => {
|
|
44
45
|
const { model, handleUpdate } = useChessModel(game);
|
|
45
46
|
if (!model) {
|
|
46
47
|
return null;
|
|
@@ -59,7 +60,7 @@ export const Chess = ({ space, game, playerSelector }: { space: Space; game: Gam
|
|
|
59
60
|
);
|
|
60
61
|
};
|
|
61
62
|
|
|
62
|
-
const PlayerSelector = ({ game, space }: { game:
|
|
63
|
+
const PlayerSelector = ({ game, space }: { game: ChessType; space: Space }) => {
|
|
63
64
|
const members = useMembers(space.key);
|
|
64
65
|
|
|
65
66
|
return (
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import React, { type ComponentProps } from 'react';
|
|
6
6
|
|
|
7
7
|
import { getSpace } from '@dxos/react-client/echo';
|
|
8
|
+
import { StackItem } from '@dxos/react-ui-stack';
|
|
8
9
|
|
|
9
10
|
import { Chess } from './Chess';
|
|
10
11
|
|
|
@@ -15,9 +16,9 @@ const ChessContainer = ({ game, role }: Pick<ComponentProps<typeof Chess>, 'game
|
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
return (
|
|
18
|
-
<
|
|
19
|
+
<StackItem.Content toolbar={false}>
|
|
19
20
|
<Chess game={game} space={space} playerSelector={role === 'article'} />
|
|
20
|
-
</
|
|
21
|
+
</StackItem.Content>
|
|
21
22
|
);
|
|
22
23
|
};
|
|
23
24
|
|
|
@@ -7,11 +7,12 @@ import '@dxos-theme';
|
|
|
7
7
|
import { Chess } from 'chess.js';
|
|
8
8
|
import React, { useState } from 'react';
|
|
9
9
|
|
|
10
|
+
import { mx } from '@dxos/react-ui-theme';
|
|
10
11
|
import { withTheme } from '@dxos/storybook-utils';
|
|
11
12
|
|
|
12
13
|
import { Chessboard, type ChessModel, type ChessMove, ChessPanel } from './Chessboard';
|
|
13
14
|
|
|
14
|
-
const Story = () => {
|
|
15
|
+
const Story = ({ size, panel = false }: { size?: 'large' | 'small'; panel: boolean }) => {
|
|
15
16
|
const [model, setModel] = useState<ChessModel>({ chess: new Chess() });
|
|
16
17
|
const handleUpdate = (move: ChessMove) => {
|
|
17
18
|
if (model.chess.move(move)) {
|
|
@@ -21,12 +22,14 @@ const Story = () => {
|
|
|
21
22
|
|
|
22
23
|
return (
|
|
23
24
|
<div className='flex flex-row'>
|
|
24
|
-
<div className='w-[
|
|
25
|
-
<Chessboard model={model}
|
|
26
|
-
</div>
|
|
27
|
-
<div className='w-[160px] ml-8'>
|
|
28
|
-
<ChessPanel model={model} />
|
|
25
|
+
<div className={mx(size === 'small' ? 'w-[320px]' : 'w-[640px]')}>
|
|
26
|
+
<Chessboard model={model} onUpdate={handleUpdate} />
|
|
29
27
|
</div>
|
|
28
|
+
{panel && (
|
|
29
|
+
<div className='w-[160px] ml-8'>
|
|
30
|
+
<ChessPanel model={model} />
|
|
31
|
+
</div>
|
|
32
|
+
)}
|
|
30
33
|
</div>
|
|
31
34
|
);
|
|
32
35
|
};
|
|
@@ -38,6 +41,16 @@ export default {
|
|
|
38
41
|
decorators: [withTheme],
|
|
39
42
|
};
|
|
40
43
|
|
|
41
|
-
export const Default = {
|
|
42
|
-
|
|
44
|
+
export const Default = {};
|
|
45
|
+
|
|
46
|
+
export const Panel = {
|
|
47
|
+
args: {
|
|
48
|
+
panel: true,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const Micro = {
|
|
53
|
+
args: {
|
|
54
|
+
size: 'small',
|
|
55
|
+
},
|
|
43
56
|
};
|