@dxos/plugin-chess 0.8.4-main.c1de068 → 0.8.4-main.dedc0f3

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 (156) hide show
  1. package/dist/lib/browser/ChessboardContainer-LIZDOGHI.mjs +97 -0
  2. package/dist/lib/browser/ChessboardContainer-LIZDOGHI.mjs.map +7 -0
  3. package/dist/lib/browser/blueprint-definition-RVS32T67.mjs +11 -0
  4. package/dist/lib/browser/blueprint-definition-RVS32T67.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-EKNL3H3U.mjs +306 -0
  6. package/dist/lib/browser/chunk-EKNL3H3U.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-KD4I5VTZ.mjs +8 -0
  8. package/dist/lib/browser/chunk-KD4I5VTZ.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-KYO4ODJJ.mjs +163 -0
  10. package/dist/lib/browser/chunk-KYO4ODJJ.mjs.map +7 -0
  11. package/dist/lib/browser/chunk-PE3IWOFR.mjs +28 -0
  12. package/dist/lib/browser/chunk-PE3IWOFR.mjs.map +7 -0
  13. package/dist/lib/browser/chunk-T275KG4U.mjs +84 -0
  14. package/dist/lib/browser/chunk-T275KG4U.mjs.map +7 -0
  15. package/dist/lib/browser/index.mjs +52 -25
  16. package/dist/lib/browser/index.mjs.map +3 -3
  17. package/dist/lib/browser/{intent-resolver-KQYYX44R.mjs → intent-resolver-DA5H5633.mjs} +8 -11
  18. package/dist/lib/browser/intent-resolver-DA5H5633.mjs.map +7 -0
  19. package/dist/lib/browser/meta.json +1 -1
  20. package/dist/lib/browser/{react-surface-PLUCWIYP.mjs → react-surface-MIMI6LPO.mjs} +11 -9
  21. package/dist/lib/browser/react-surface-MIMI6LPO.mjs.map +7 -0
  22. package/dist/lib/browser/types/index.mjs +6 -7
  23. package/dist/lib/node-esm/ChessboardContainer-XWVQ5K7N.mjs +98 -0
  24. package/dist/lib/node-esm/ChessboardContainer-XWVQ5K7N.mjs.map +7 -0
  25. package/dist/lib/node-esm/blueprint-definition-F57ZSRAG.mjs +12 -0
  26. package/dist/lib/node-esm/blueprint-definition-F57ZSRAG.mjs.map +7 -0
  27. package/dist/lib/node-esm/chunk-5DYLCQBR.mjs +85 -0
  28. package/dist/lib/node-esm/chunk-5DYLCQBR.mjs.map +7 -0
  29. package/dist/lib/node-esm/chunk-6OWCPDUA.mjs +29 -0
  30. package/dist/lib/node-esm/chunk-6OWCPDUA.mjs.map +7 -0
  31. package/dist/lib/node-esm/chunk-A34JOK3K.mjs +164 -0
  32. package/dist/lib/node-esm/chunk-A34JOK3K.mjs.map +7 -0
  33. package/dist/lib/node-esm/chunk-EGBWRJWH.mjs +307 -0
  34. package/dist/lib/node-esm/chunk-EGBWRJWH.mjs.map +7 -0
  35. package/dist/lib/node-esm/{chunk-QFINI7CC.mjs → chunk-Q5LJYIMO.mjs} +3 -3
  36. package/dist/lib/node-esm/chunk-Q5LJYIMO.mjs.map +7 -0
  37. package/dist/lib/node-esm/index.mjs +52 -25
  38. package/dist/lib/node-esm/index.mjs.map +3 -3
  39. package/dist/lib/node-esm/{intent-resolver-GXK2JROQ.mjs → intent-resolver-PODONUD3.mjs} +8 -11
  40. package/dist/lib/node-esm/intent-resolver-PODONUD3.mjs.map +7 -0
  41. package/dist/lib/node-esm/meta.json +1 -1
  42. package/dist/lib/node-esm/{react-surface-NGLNIWN3.mjs → react-surface-XMKFR5BC.mjs} +11 -9
  43. package/dist/lib/node-esm/react-surface-XMKFR5BC.mjs.map +7 -0
  44. package/dist/lib/node-esm/types/index.mjs +6 -7
  45. package/dist/types/src/ChessPlugin.d.ts.map +1 -1
  46. package/dist/types/src/capabilities/artifact-definition.d.ts +1 -1
  47. package/dist/types/src/capabilities/artifact-definition.d.ts.map +1 -1
  48. package/dist/types/src/capabilities/blueprint-definition.d.ts +6 -0
  49. package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -0
  50. package/dist/types/src/capabilities/index.d.ts +4 -3
  51. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  52. package/dist/types/src/capabilities/intent-resolver.d.ts +1 -1
  53. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
  54. package/dist/types/src/capabilities/react-surface.d.ts +1 -1
  55. package/dist/types/src/components/Card.stories.d.ts +14 -0
  56. package/dist/types/src/components/Card.stories.d.ts.map +1 -0
  57. package/dist/types/src/components/Chessboard.d.ts +38 -0
  58. package/dist/types/src/components/Chessboard.d.ts.map +1 -0
  59. package/dist/types/src/components/Chessboard.stories.d.ts +40 -4
  60. package/dist/types/src/components/Chessboard.stories.d.ts.map +1 -1
  61. package/dist/types/src/components/ChessboardArticle.d.ts +7 -0
  62. package/dist/types/src/components/ChessboardArticle.d.ts.map +1 -0
  63. package/dist/types/src/components/ChessboardContainer.d.ts +9 -0
  64. package/dist/types/src/components/ChessboardContainer.d.ts.map +1 -0
  65. package/dist/types/src/components/Info.d.ts +21 -0
  66. package/dist/types/src/components/Info.d.ts.map +1 -0
  67. package/dist/types/src/components/index.d.ts +2 -5
  68. package/dist/types/src/components/index.d.ts.map +1 -1
  69. package/dist/types/src/functions/create.d.ts +14 -0
  70. package/dist/types/src/functions/create.d.ts.map +1 -0
  71. package/dist/types/src/functions/index.d.ts +4 -0
  72. package/dist/types/src/functions/index.d.ts.map +1 -0
  73. package/dist/types/src/functions/move.d.ts +8 -0
  74. package/dist/types/src/functions/move.d.ts.map +1 -0
  75. package/dist/types/src/functions/play.d.ts +9 -0
  76. package/dist/types/src/functions/play.d.ts.map +1 -0
  77. package/dist/types/src/index.d.ts +2 -0
  78. package/dist/types/src/index.d.ts.map +1 -1
  79. package/dist/types/src/meta.d.ts.map +1 -1
  80. package/dist/types/src/translations.d.ts +10 -2
  81. package/dist/types/src/translations.d.ts.map +1 -1
  82. package/dist/types/src/types/Chess.d.ts +27 -0
  83. package/dist/types/src/types/Chess.d.ts.map +1 -0
  84. package/dist/types/src/types/ChessAction.d.ts +24 -0
  85. package/dist/types/src/types/ChessAction.d.ts.map +1 -0
  86. package/dist/types/src/types/index.d.ts +2 -2
  87. package/dist/types/src/types/index.d.ts.map +1 -1
  88. package/dist/types/tsconfig.tsbuildinfo +1 -1
  89. package/package.json +38 -26
  90. package/src/ChessPlugin.tsx +8 -7
  91. package/src/capabilities/artifact-definition.ts +24 -20
  92. package/src/capabilities/blueprint-definition.ts +36 -0
  93. package/src/capabilities/index.ts +3 -1
  94. package/src/capabilities/intent-resolver.ts +3 -7
  95. package/src/capabilities/react-surface.tsx +5 -5
  96. package/src/components/Card.stories.tsx +68 -0
  97. package/src/components/Chessboard.stories.tsx +35 -26
  98. package/src/components/Chessboard.tsx +177 -0
  99. package/src/components/ChessboardArticle.tsx +69 -0
  100. package/src/components/ChessboardContainer.tsx +44 -0
  101. package/src/components/Info.tsx +236 -0
  102. package/src/components/index.ts +2 -2
  103. package/src/functions/create.ts +30 -0
  104. package/src/functions/index.ts +7 -0
  105. package/src/functions/move.ts +43 -0
  106. package/src/functions/play.ts +53 -0
  107. package/src/index.ts +2 -0
  108. package/src/meta.ts +4 -2
  109. package/src/translations.ts +10 -2
  110. package/src/types/Chess.ts +66 -0
  111. package/src/types/ChessAction.ts +19 -0
  112. package/src/types/index.ts +2 -2
  113. package/dist/lib/browser/ChessContainer-SC4ZV6XZ.mjs +0 -129
  114. package/dist/lib/browser/ChessContainer-SC4ZV6XZ.mjs.map +0 -7
  115. package/dist/lib/browser/artifact-definition-A2FSM255.mjs +0 -182
  116. package/dist/lib/browser/artifact-definition-A2FSM255.mjs.map +0 -7
  117. package/dist/lib/browser/chunk-A3WEUKPK.mjs +0 -61
  118. package/dist/lib/browser/chunk-A3WEUKPK.mjs.map +0 -7
  119. package/dist/lib/browser/chunk-KDADGLPC.mjs +0 -8
  120. package/dist/lib/browser/chunk-KDADGLPC.mjs.map +0 -7
  121. package/dist/lib/browser/chunk-ZXH3N4NA.mjs +0 -66
  122. package/dist/lib/browser/chunk-ZXH3N4NA.mjs.map +0 -7
  123. package/dist/lib/browser/intent-resolver-KQYYX44R.mjs.map +0 -7
  124. package/dist/lib/browser/react-surface-PLUCWIYP.mjs.map +0 -7
  125. package/dist/lib/node-esm/ChessContainer-7GLY5KLY.mjs +0 -130
  126. package/dist/lib/node-esm/ChessContainer-7GLY5KLY.mjs.map +0 -7
  127. package/dist/lib/node-esm/artifact-definition-2H7OUBZO.mjs +0 -183
  128. package/dist/lib/node-esm/artifact-definition-2H7OUBZO.mjs.map +0 -7
  129. package/dist/lib/node-esm/chunk-27D3JA3K.mjs +0 -68
  130. package/dist/lib/node-esm/chunk-27D3JA3K.mjs.map +0 -7
  131. package/dist/lib/node-esm/chunk-IS3Y25PL.mjs +0 -63
  132. package/dist/lib/node-esm/chunk-IS3Y25PL.mjs.map +0 -7
  133. package/dist/lib/node-esm/chunk-QFINI7CC.mjs.map +0 -7
  134. package/dist/lib/node-esm/intent-resolver-GXK2JROQ.mjs.map +0 -7
  135. package/dist/lib/node-esm/react-surface-NGLNIWN3.mjs.map +0 -7
  136. package/dist/types/src/components/Chess.d.ts +0 -14
  137. package/dist/types/src/components/Chess.d.ts.map +0 -1
  138. package/dist/types/src/components/ChessContainer.d.ts +0 -8
  139. package/dist/types/src/components/ChessContainer.d.ts.map +0 -1
  140. package/dist/types/src/components/ChessContainer.stories.d.ts +0 -23
  141. package/dist/types/src/components/ChessContainer.stories.d.ts.map +0 -1
  142. package/dist/types/src/components/ChessPanel.d.ts +0 -11
  143. package/dist/types/src/components/ChessPanel.d.ts.map +0 -1
  144. package/dist/types/src/components/PlayerSelector.d.ts +0 -8
  145. package/dist/types/src/components/PlayerSelector.d.ts.map +0 -1
  146. package/dist/types/src/types/schema.d.ts +0 -29
  147. package/dist/types/src/types/schema.d.ts.map +0 -1
  148. package/dist/types/src/types/types.d.ts +0 -32
  149. package/dist/types/src/types/types.d.ts.map +0 -1
  150. package/src/components/Chess.tsx +0 -60
  151. package/src/components/ChessContainer.stories.tsx +0 -110
  152. package/src/components/ChessContainer.tsx +0 -71
  153. package/src/components/ChessPanel.tsx +0 -67
  154. package/src/components/PlayerSelector.tsx +0 -82
  155. package/src/types/schema.ts +0 -34
  156. 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.c1de068",
3
+ "version": "0.8.4-main.dedc0f3",
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.0",
40
- "@dxos/ai": "0.8.4-main.c1de068",
41
- "@dxos/app-framework": "0.8.4-main.c1de068",
42
- "@dxos/assistant": "0.8.4-main.c1de068",
43
- "@dxos/display-name": "0.8.4-main.c1de068",
44
- "@dxos/blueprints": "0.8.4-main.c1de068",
45
- "@dxos/echo": "0.8.4-main.c1de068",
46
- "@dxos/echo-schema": "0.8.4-main.c1de068",
47
- "@dxos/async": "0.8.4-main.c1de068",
48
- "@dxos/invariant": "0.8.4-main.c1de068",
49
- "@dxos/live-object": "0.8.4-main.c1de068",
50
- "@dxos/log": "0.8.4-main.c1de068",
51
- "@dxos/plugin-client": "0.8.4-main.c1de068",
52
- "@dxos/plugin-space": "0.8.4-main.c1de068",
53
- "@dxos/plugin-graph": "0.8.4-main.c1de068",
54
- "@dxos/react-ui-gameboard": "0.8.4-main.c1de068",
55
- "@dxos/react-client": "0.8.4-main.c1de068",
56
- "@dxos/react-ui-stack": "0.8.4-main.c1de068"
47
+ "effect": "3.17.7",
48
+ "@dxos/ai": "0.8.4-main.dedc0f3",
49
+ "@dxos/app-framework": "0.8.4-main.dedc0f3",
50
+ "@dxos/assistant": "0.8.4-main.dedc0f3",
51
+ "@dxos/async": "0.8.4-main.dedc0f3",
52
+ "@dxos/display-name": "0.8.4-main.dedc0f3",
53
+ "@dxos/echo": "0.8.4-main.dedc0f3",
54
+ "@dxos/blueprints": "0.8.4-main.dedc0f3",
55
+ "@dxos/echo-schema": "0.8.4-main.dedc0f3",
56
+ "@dxos/functions": "0.8.4-main.dedc0f3",
57
+ "@dxos/invariant": "0.8.4-main.dedc0f3",
58
+ "@dxos/live-object": "0.8.4-main.dedc0f3",
59
+ "@dxos/log": "0.8.4-main.dedc0f3",
60
+ "@dxos/plugin-client": "0.8.4-main.dedc0f3",
61
+ "@dxos/plugin-graph": "0.8.4-main.dedc0f3",
62
+ "@dxos/plugin-space": "0.8.4-main.dedc0f3",
63
+ "@dxos/react-client": "0.8.4-main.dedc0f3",
64
+ "@dxos/react-ui-gameboard": "0.8.4-main.dedc0f3",
65
+ "@dxos/react-ui-sfx": "0.8.4-main.dedc0f3",
66
+ "@dxos/react-ui-stack": "0.8.4-main.dedc0f3",
67
+ "@dxos/schema": "0.8.4-main.dedc0f3",
68
+ "@dxos/util": "0.8.4-main.dedc0f3"
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": "5.4.7",
64
- "@dxos/plugin-theme": "0.8.4-main.c1de068",
65
- "@dxos/react-ui": "0.8.4-main.c1de068",
66
- "@dxos/react-ui-theme": "0.8.4-main.c1de068",
67
- "@dxos/storybook-utils": "0.8.4-main.c1de068"
75
+ "vite": "7.1.1",
76
+ "@dxos/react-ui": "0.8.4-main.dedc0f3",
77
+ "@dxos/plugin-theme": "0.8.4-main.dedc0f3",
78
+ "@dxos/react-ui-theme": "0.8.4-main.dedc0f3",
79
+ "@dxos/storybook-utils": "0.8.4-main.dedc0f3"
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.c1de068",
73
- "@dxos/react-ui-theme": "0.8.4-main.c1de068"
84
+ "@dxos/react-ui": "0.8.4-main.dedc0f3",
85
+ "@dxos/react-ui-theme": "0.8.4-main.dedc0f3"
74
86
  },
75
87
  "publishConfig": {
76
88
  "access": "public"
@@ -2,15 +2,15 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { Capabilities, contributes, createIntent, defineModule, definePlugin, Events } from '@dxos/app-framework';
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 { ArtifactDefinition, IntentResolver, ReactSurface } from './capabilities';
10
+ import { BLUEPRINT_KEY, BlueprintDefinition, IntentResolver, ReactSurface } from './capabilities';
11
11
  import { meta } from './meta';
12
12
  import { translations } from './translations';
13
- import { ChessAction, ChessType } from './types';
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: ChessType.typename,
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: ChessType,
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/artifact-definition`,
57
+ id: `${meta.id}/module/blueprint`,
57
58
  activatesOn: Events.SetupArtifactDefinition,
58
- activate: ArtifactDefinition,
59
+ activate: BlueprintDefinition,
59
60
  }),
60
61
  ]);
@@ -2,20 +2,24 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Chess } from 'chess.js';
6
- import { pipe, Schema } from 'effect';
5
+ // ISSUE(burdon): defineArtifact
6
+ // @ts-nocheck
7
7
 
8
- import { createTool, ToolResult } from '@dxos/ai';
9
- import { Capabilities, chain, contributes, createIntent, type PromiseIntentDispatcher } from '@dxos/app-framework';
10
- import { createArtifactElement, VersionPin, ArtifactId } from '@dxos/assistant';
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 { ChessAction, ChessType } from '../types';
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: ChessType,
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
- fen: Schema.String.annotations({ description: 'The state of the chess game in the FEN format.' }),
48
+ pgn: Schema.String.annotations({ description: 'The state of the chess game in the PGN format.' }),
45
49
  }),
46
- execute: async ({ fen }, { extensions }) => {
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, { fen }),
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(ChessType)).run();
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(ChessType, game));
90
+ invariant(Obj.instanceOf(Chess.Game, game));
87
91
 
88
- return ToolResult.Success(game.fen);
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(ChessType, game));
111
+ invariant(Obj.instanceOf(Chess.Game, game));
108
112
 
109
- const board = new Chess(game.fen);
113
+ const chess = new ChessJS(game.pgn);
110
114
  try {
111
- board.move(move);
115
+ chess.move(move);
112
116
  } catch (error: any) {
113
117
  return ToolResult.Error(error.message);
114
118
  }
115
- game.pgn = board.pgn();
116
- game.fen = board.fen();
117
- return ToolResult.Success(game.fen);
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 ArtifactDefinition = lazy(() => import('./artifact-definition'));
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 { ChessAction, ChessType } from '../types';
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, fen }) => {
18
- const pgn = fen ? new Chess(fen).pgn() : undefined;
14
+ resolve: ({ name, pgn }) => {
19
15
  return {
20
16
  data: {
21
- object: Obj.make(ChessType, { name, fen, pgn }),
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 { ChessContainer } from '../components';
10
+ import { ChessboardContainer } from '../components';
11
11
  import { meta } from '../meta';
12
- import { ChessType } from '../types';
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 (like below)?
20
- filter: (data): data is { subject: ChessType } => Obj.instanceOf(ChessType, data.subject),
21
- component: ({ data, role }) => <ChessContainer game={data.subject} role={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 { Gameboard, Chessboard, ChessModel } from '@dxos/react-ui-gameboard';
9
+ import { withClientProvider } from '@dxos/react-client/testing';
11
10
  import { withLayout, withTheme } from '@dxos/storybook-utils';
12
11
 
13
- import { ChessPanel } from './ChessPanel';
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
- const meta: Meta<typeof Chessboard> = {
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
- type Story = StoryObj<typeof Chessboard>;
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
- export const Default: Story = {};
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
+ };