@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.
Files changed (116) hide show
  1. package/dist/lib/browser/ChessContainer-G736GS2V.mjs +26 -0
  2. package/dist/lib/browser/ChessContainer-G736GS2V.mjs.map +7 -0
  3. package/dist/lib/browser/artifact-YWAB5JJL.mjs +174 -0
  4. package/dist/lib/browser/artifact-YWAB5JJL.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-JUAC2NNR.mjs +548 -0
  6. package/dist/lib/browser/chunk-JUAC2NNR.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-LAYER2WV.mjs +8 -0
  8. package/dist/lib/browser/chunk-LAYER2WV.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-VYBCAEUF.mjs +66 -0
  10. package/dist/lib/browser/chunk-VYBCAEUF.mjs.map +7 -0
  11. package/dist/lib/browser/index.mjs +76 -623
  12. package/dist/lib/browser/index.mjs.map +4 -4
  13. package/dist/lib/browser/intent-resolver-UZRNSQFI.mjs +25 -0
  14. package/dist/lib/browser/intent-resolver-UZRNSQFI.mjs.map +7 -0
  15. package/dist/lib/browser/meta.json +1 -1
  16. package/dist/lib/browser/react-surface-EP4LXPH7.mjs +50 -0
  17. package/dist/lib/browser/react-surface-EP4LXPH7.mjs.map +7 -0
  18. package/dist/lib/browser/types/index.mjs +3 -4
  19. package/dist/lib/node/ChessContainer-P4BZ62FN.cjs +52 -0
  20. package/dist/lib/node/ChessContainer-P4BZ62FN.cjs.map +7 -0
  21. package/dist/lib/node/artifact-YWL3LBIO.cjs +189 -0
  22. package/dist/lib/node/artifact-YWL3LBIO.cjs.map +7 -0
  23. package/dist/lib/node/chunk-6F6WTM5L.cjs +40 -0
  24. package/dist/lib/node/chunk-6F6WTM5L.cjs.map +7 -0
  25. package/dist/lib/node/chunk-HPYER4GF.cjs +574 -0
  26. package/dist/lib/node/chunk-HPYER4GF.cjs.map +7 -0
  27. package/dist/lib/node/{chunk-3VNSWSKR.cjs → chunk-J5YKJRP3.cjs} +39 -14
  28. package/dist/lib/node/chunk-J5YKJRP3.cjs.map +7 -0
  29. package/dist/lib/node/index.cjs +75 -599
  30. package/dist/lib/node/index.cjs.map +4 -4
  31. package/dist/lib/node/intent-resolver-AENA6D5K.cjs +40 -0
  32. package/dist/lib/node/intent-resolver-AENA6D5K.cjs.map +7 -0
  33. package/dist/lib/node/meta.json +1 -1
  34. package/dist/lib/node/react-surface-JMOSMAIC.cjs +70 -0
  35. package/dist/lib/node/react-surface-JMOSMAIC.cjs.map +7 -0
  36. package/dist/lib/node/types/index.cjs +6 -7
  37. package/dist/lib/node/types/index.cjs.map +2 -2
  38. package/dist/lib/node-esm/ChessContainer-2LFJ6RHB.mjs +27 -0
  39. package/dist/lib/node-esm/ChessContainer-2LFJ6RHB.mjs.map +7 -0
  40. package/dist/lib/node-esm/artifact-B6IEF7U5.mjs +175 -0
  41. package/dist/lib/node-esm/artifact-B6IEF7U5.mjs.map +7 -0
  42. package/dist/lib/node-esm/chunk-OMGVSBVI.mjs +550 -0
  43. package/dist/lib/node-esm/chunk-OMGVSBVI.mjs.map +7 -0
  44. package/dist/lib/node-esm/chunk-QXDXLFXD.mjs +10 -0
  45. package/dist/lib/node-esm/chunk-QXDXLFXD.mjs.map +7 -0
  46. package/dist/lib/node-esm/chunk-TXUWVQWY.mjs +68 -0
  47. package/dist/lib/node-esm/chunk-TXUWVQWY.mjs.map +7 -0
  48. package/dist/lib/node-esm/index.mjs +76 -623
  49. package/dist/lib/node-esm/index.mjs.map +4 -4
  50. package/dist/lib/node-esm/intent-resolver-T7NNHOYR.mjs +26 -0
  51. package/dist/lib/node-esm/intent-resolver-T7NNHOYR.mjs.map +7 -0
  52. package/dist/lib/node-esm/meta.json +1 -1
  53. package/dist/lib/node-esm/react-surface-ENB7VY45.mjs +51 -0
  54. package/dist/lib/node-esm/react-surface-ENB7VY45.mjs.map +7 -0
  55. package/dist/lib/node-esm/types/index.mjs +3 -4
  56. package/dist/types/src/ChessPlugin.d.ts +1 -3
  57. package/dist/types/src/ChessPlugin.d.ts.map +1 -1
  58. package/dist/types/src/capabilities/artifact.d.ts +11 -0
  59. package/dist/types/src/capabilities/artifact.d.ts.map +1 -0
  60. package/dist/types/src/capabilities/index.d.ts +4 -0
  61. package/dist/types/src/capabilities/index.d.ts.map +1 -0
  62. package/dist/types/src/capabilities/intent-resolver.d.ts +4 -0
  63. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -0
  64. package/dist/types/src/capabilities/react-surface.d.ts +4 -0
  65. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
  66. package/dist/types/src/components/Chess.d.ts +2 -2
  67. package/dist/types/src/components/Chess.d.ts.map +1 -1
  68. package/dist/types/src/components/ChessContainer.d.ts.map +1 -1
  69. package/dist/types/src/components/Chessboard/Chessboard.d.ts +2 -2
  70. package/dist/types/src/components/Chessboard/Chessboard.d.ts.map +1 -1
  71. package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts +14 -3
  72. package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts.map +1 -1
  73. package/dist/types/src/components/index.d.ts +2 -0
  74. package/dist/types/src/components/index.d.ts.map +1 -1
  75. package/dist/types/src/index.d.ts +3 -2
  76. package/dist/types/src/index.d.ts.map +1 -1
  77. package/dist/types/src/meta.d.ts +1 -2
  78. package/dist/types/src/meta.d.ts.map +1 -1
  79. package/dist/types/src/types/schema.d.ts +13 -9
  80. package/dist/types/src/types/schema.d.ts.map +1 -1
  81. package/dist/types/src/types/types.d.ts +18 -8
  82. package/dist/types/src/types/types.d.ts.map +1 -1
  83. package/dist/types/tsconfig.tsbuildinfo +1 -0
  84. package/package.json +24 -26
  85. package/src/ChessPlugin.tsx +51 -89
  86. package/src/capabilities/artifact.ts +109 -0
  87. package/src/capabilities/index.ts +9 -0
  88. package/src/capabilities/intent-resolver.ts +24 -0
  89. package/src/capabilities/react-surface.tsx +38 -0
  90. package/src/components/Chess.tsx +7 -6
  91. package/src/components/ChessContainer.tsx +3 -2
  92. package/src/components/Chessboard/Chessboard.stories.tsx +21 -8
  93. package/src/components/Chessboard/Chessboard.tsx +29 -17
  94. package/src/components/index.ts +3 -0
  95. package/src/index.ts +3 -3
  96. package/src/meta.ts +1 -1
  97. package/src/translations.ts +2 -2
  98. package/src/types/schema.ts +4 -1
  99. package/src/types/types.ts +15 -23
  100. package/dist/lib/browser/chunk-2H2BTWYT.mjs +0 -15
  101. package/dist/lib/browser/chunk-2H2BTWYT.mjs.map +0 -7
  102. package/dist/lib/browser/chunk-BG7NXK4E.mjs +0 -42
  103. package/dist/lib/browser/chunk-BG7NXK4E.mjs.map +0 -7
  104. package/dist/lib/browser/meta.mjs +0 -9
  105. package/dist/lib/browser/meta.mjs.map +0 -7
  106. package/dist/lib/node/chunk-3VNSWSKR.cjs.map +0 -7
  107. package/dist/lib/node/chunk-Q4NVPVPX.cjs +0 -38
  108. package/dist/lib/node/chunk-Q4NVPVPX.cjs.map +0 -7
  109. package/dist/lib/node/meta.cjs +0 -30
  110. package/dist/lib/node/meta.cjs.map +0 -7
  111. package/dist/lib/node-esm/chunk-RIQ5MOYO.mjs +0 -43
  112. package/dist/lib/node-esm/chunk-RIQ5MOYO.mjs.map +0 -7
  113. package/dist/lib/node-esm/chunk-WNE2FPQW.mjs +0 -17
  114. package/dist/lib/node-esm/chunk-WNE2FPQW.mjs.map +0 -7
  115. package/dist/lib/node-esm/meta.mjs +0 -10
  116. 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 GameType_base: import("@dxos/echo-schema").AbstractTypedObject<{
12
- playerWhite?: string | undefined;
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 GameType extends GameType_base {
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;;;;;;;;;;;;;;AAEF,qBAAa,QAAS,SAAQ,aAQ7B;CAAG"}
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 type { GraphBuilderProvides, IntentResolverProvides, MetadataRecordsProvides, SurfaceProvides, TranslationsProvides } from '@dxos/app-framework';
2
- import { type SchemaProvides } from '@dxos/plugin-space';
3
- import { GameType } from './schema';
4
- export declare enum ChessAction {
5
- CREATE = "dxos.org/plugin/chess/action/create"
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 type ChessProvides = {};
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,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACtB,uBAAuB,EACvB,eAAe,EACf,oBAAoB,EACrB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAKpC,oBAAY,WAAW;IACrB,MAAM,wCAA2B;CAClC;AAED,MAAM,MAAM,aAAa,GAAG,EAAE,CAAC;AAE/B,MAAM,MAAM,mBAAmB,GAAG,eAAe,GAC/C,sBAAsB,GACtB,oBAAoB,GACpB,uBAAuB,GACvB,oBAAoB,GACpB,cAAc,CAAC;AAEjB,eAAO,MAAM,QAAQ,WAAY,OAAO,KAAG,MAAM,IAAI,QAEpD,CAAC"}
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.4",
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-beta.8",
46
- "react-chessboard": "^4.7.1",
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.4",
49
- "@dxos/async": "0.7.4",
50
- "@dxos/invariant": "0.7.4",
51
- "@dxos/display-name": "0.7.4",
52
- "@dxos/echo-schema": "0.7.4",
53
- "@dxos/plugin-client": "0.7.4",
54
- "@dxos/plugin-graph": "0.7.4",
55
- "@dxos/live-object": "0.7.4",
56
- "@dxos/react-client": "0.7.4",
57
- "@dxos/plugin-space": "0.7.4"
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.4",
67
- "@dxos/react-ui-theme": "0.7.4",
68
- "@dxos/storybook-utils": "0.7.4"
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.4",
75
- "@dxos/react-ui-theme": "0.7.4"
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"
@@ -2,98 +2,60 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import React from 'react';
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 { NavigationAction, parseIntentPlugin, type PluginDefinition, resolvePlugin } from '@dxos/app-framework';
8
- import { create } from '@dxos/live-object';
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, type ChessPluginProvides, GameType, isObject } from './types';
19
+ import { ChessAction, ChessType } from './types';
17
20
 
18
- export const ChessPlugin = (): PluginDefinition<ChessPluginProvides> => {
19
- return {
20
- meta,
21
- provides: {
22
- metadata: {
23
- records: {
24
- [GameType.typename]: {
25
- createObject: ChessAction.CREATE,
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
- echo: {
32
- schema: [GameType],
33
- },
34
- graph: {
35
- builder: (plugins) => {
36
- const client = resolvePlugin(plugins, parseClientPlugin)?.provides.client;
37
- const dispatch = resolvePlugin(plugins, parseIntentPlugin)?.provides.intent.dispatch;
38
- if (!client || !dispatch) {
39
- return [];
40
- }
41
-
42
- return createExtension({
43
- id: ChessAction.CREATE,
44
- filter: (node): node is ActionGroup => isActionGroup(node) && node.id.startsWith(SpaceAction.ADD_OBJECT),
45
- actions: ({ node }) => {
46
- const id = node.id.split('/').at(-1);
47
- const [spaceId, objectId] = id?.split(':') ?? [];
48
- const space = client.spaces.get().find((space) => space.id === spaceId);
49
- const object = objectId && space?.db.getObjectById(objectId);
50
- const target = objectId ? object : space;
51
- if (!target) {
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
+ ]);
@@ -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 GameType } from '../types';
16
+ import { type ChessType } from '../types';
17
17
 
18
- const useChessModel = (game: GameType) => {
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!.pgn = model.chess.pgn();
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: GameType; playerSelector?: boolean }) => {
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: GameType; space: Space }) => {
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
- <div role='none' className='flex flex-col row-span-2 is-full overflow-hidden'>
19
+ <StackItem.Content toolbar={false}>
19
20
  <Chess game={game} space={space} playerSelector={role === 'article'} />
20
- </div>
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-[600px]'>
25
- <Chessboard model={model} boardStyle='default' onUpdate={handleUpdate} />
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
- component: Chessboard,
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
  };