@dxos/plugin-chess 0.7.5-main.499c70c → 0.7.5-main.5ae2ba8

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 (143) hide show
  1. package/dist/lib/browser/ChessContainer-XERPODLK.mjs +86 -0
  2. package/dist/lib/browser/ChessContainer-XERPODLK.mjs.map +7 -0
  3. package/dist/lib/browser/artifact-definition-D2SD45UX.mjs +180 -0
  4. package/dist/lib/browser/artifact-definition-D2SD45UX.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-NNA3W3LX.mjs +69 -0
  6. package/dist/lib/browser/chunk-NNA3W3LX.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-R26FYVUS.mjs +8 -0
  8. package/dist/lib/browser/chunk-R26FYVUS.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-VRWXC5L2.mjs +42 -0
  10. package/dist/lib/browser/chunk-VRWXC5L2.mjs.map +7 -0
  11. package/dist/lib/browser/index.mjs +70 -563
  12. package/dist/lib/browser/index.mjs.map +4 -4
  13. package/dist/lib/browser/intent-resolver-KBIH2KYC.mjs +28 -0
  14. package/dist/lib/browser/intent-resolver-KBIH2KYC.mjs.map +7 -0
  15. package/dist/lib/browser/meta.json +1 -1
  16. package/dist/lib/browser/react-surface-2PI2KNSU.mjs +42 -0
  17. package/dist/lib/browser/react-surface-2PI2KNSU.mjs.map +7 -0
  18. package/dist/lib/browser/types/index.mjs +3 -4
  19. package/dist/lib/node/ChessContainer-LEPLNICP.cjs +108 -0
  20. package/dist/lib/node/ChessContainer-LEPLNICP.cjs.map +7 -0
  21. package/dist/lib/node/artifact-definition-YDPYM4NV.cjs +194 -0
  22. package/dist/lib/node/artifact-definition-YDPYM4NV.cjs.map +7 -0
  23. package/dist/lib/node/chunk-CSRNUKOH.cjs +74 -0
  24. package/dist/lib/node/chunk-CSRNUKOH.cjs.map +7 -0
  25. package/dist/lib/node/chunk-ITDMCBQQ.cjs +40 -0
  26. package/dist/lib/node/chunk-ITDMCBQQ.cjs.map +7 -0
  27. package/dist/lib/node/{chunk-URYVXDF3.cjs → chunk-VXYRI6VA.cjs} +32 -15
  28. package/dist/lib/node/chunk-VXYRI6VA.cjs.map +7 -0
  29. package/dist/lib/node/index.cjs +70 -540
  30. package/dist/lib/node/index.cjs.map +4 -4
  31. package/dist/lib/node/intent-resolver-TZFKPQOV.cjs +43 -0
  32. package/dist/lib/node/intent-resolver-TZFKPQOV.cjs.map +7 -0
  33. package/dist/lib/node/meta.json +1 -1
  34. package/dist/lib/node/react-surface-OHQIPHSN.cjs +62 -0
  35. package/dist/lib/node/react-surface-OHQIPHSN.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-S76WNBWN.mjs +87 -0
  39. package/dist/lib/node-esm/ChessContainer-S76WNBWN.mjs.map +7 -0
  40. package/dist/lib/node-esm/artifact-definition-LHQK5BBZ.mjs +181 -0
  41. package/dist/lib/node-esm/artifact-definition-LHQK5BBZ.mjs.map +7 -0
  42. package/dist/lib/node-esm/chunk-6SEDGO5G.mjs +44 -0
  43. package/dist/lib/node-esm/chunk-6SEDGO5G.mjs.map +7 -0
  44. package/dist/lib/node-esm/chunk-B72CIN6T.mjs +10 -0
  45. package/dist/lib/node-esm/chunk-B72CIN6T.mjs.map +7 -0
  46. package/dist/lib/node-esm/chunk-IP66EHSW.mjs +71 -0
  47. package/dist/lib/node-esm/chunk-IP66EHSW.mjs.map +7 -0
  48. package/dist/lib/node-esm/index.mjs +70 -563
  49. package/dist/lib/node-esm/index.mjs.map +4 -4
  50. package/dist/lib/node-esm/intent-resolver-WBUS64KC.mjs +29 -0
  51. package/dist/lib/node-esm/intent-resolver-WBUS64KC.mjs.map +7 -0
  52. package/dist/lib/node-esm/meta.json +1 -1
  53. package/dist/lib/node-esm/react-surface-XX4VFNRS.mjs +43 -0
  54. package/dist/lib/node-esm/react-surface-XX4VFNRS.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-definition.d.ts +11 -0
  59. package/dist/types/src/capabilities/artifact-definition.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/ChessComponent.d.ts +5 -0
  67. package/dist/types/src/components/ChessComponent.d.ts.map +1 -0
  68. package/dist/types/src/components/ChessContainer.d.ts +4 -4
  69. package/dist/types/src/components/ChessContainer.d.ts.map +1 -1
  70. package/dist/types/src/components/ChessPanel.d.ts +11 -0
  71. package/dist/types/src/components/ChessPanel.d.ts.map +1 -0
  72. package/dist/types/src/components/Chessboard.stories.d.ts +8 -0
  73. package/dist/types/src/components/Chessboard.stories.d.ts.map +1 -0
  74. package/dist/types/src/components/PlayerSelector.d.ts +7 -0
  75. package/dist/types/src/components/PlayerSelector.d.ts.map +1 -0
  76. package/dist/types/src/components/index.d.ts +4 -2
  77. package/dist/types/src/components/index.d.ts.map +1 -1
  78. package/dist/types/src/index.d.ts +3 -2
  79. package/dist/types/src/index.d.ts.map +1 -1
  80. package/dist/types/src/meta.d.ts +2 -2
  81. package/dist/types/src/meta.d.ts.map +1 -1
  82. package/dist/types/src/types/schema.d.ts +4 -2
  83. package/dist/types/src/types/schema.d.ts.map +1 -1
  84. package/dist/types/src/types/types.d.ts +4 -7
  85. package/dist/types/src/types/types.d.ts.map +1 -1
  86. package/dist/types/tsconfig.tsbuildinfo +1 -1
  87. package/package.json +23 -27
  88. package/src/ChessPlugin.tsx +50 -40
  89. package/src/capabilities/artifact-definition.ts +115 -0
  90. package/src/capabilities/index.ts +9 -0
  91. package/src/capabilities/intent-resolver.ts +26 -0
  92. package/src/capabilities/react-surface.tsx +29 -0
  93. package/src/components/ChessComponent.tsx +49 -0
  94. package/src/components/ChessContainer.tsx +17 -6
  95. package/src/components/ChessPanel.tsx +67 -0
  96. package/src/components/Chessboard.stories.tsx +39 -0
  97. package/src/components/{Chess.tsx → PlayerSelector.tsx} +3 -50
  98. package/src/components/index.ts +2 -0
  99. package/src/index.ts +3 -3
  100. package/src/meta.ts +4 -2
  101. package/src/translations.ts +2 -2
  102. package/src/types/schema.ts +3 -1
  103. package/src/types/types.ts +6 -20
  104. package/dist/lib/browser/chunk-2H2BTWYT.mjs +0 -15
  105. package/dist/lib/browser/chunk-2H2BTWYT.mjs.map +0 -7
  106. package/dist/lib/browser/chunk-3UQBTNX5.mjs +0 -53
  107. package/dist/lib/browser/chunk-3UQBTNX5.mjs.map +0 -7
  108. package/dist/lib/browser/meta.mjs +0 -9
  109. package/dist/lib/browser/meta.mjs.map +0 -7
  110. package/dist/lib/node/chunk-Q4NVPVPX.cjs +0 -38
  111. package/dist/lib/node/chunk-Q4NVPVPX.cjs.map +0 -7
  112. package/dist/lib/node/chunk-URYVXDF3.cjs.map +0 -7
  113. package/dist/lib/node/meta.cjs +0 -30
  114. package/dist/lib/node/meta.cjs.map +0 -7
  115. package/dist/lib/node-esm/chunk-IE2S5YZ2.mjs +0 -54
  116. package/dist/lib/node-esm/chunk-IE2S5YZ2.mjs.map +0 -7
  117. package/dist/lib/node-esm/chunk-WNE2FPQW.mjs +0 -17
  118. package/dist/lib/node-esm/chunk-WNE2FPQW.mjs.map +0 -7
  119. package/dist/lib/node-esm/meta.mjs +0 -10
  120. package/dist/lib/node-esm/meta.mjs.map +0 -7
  121. package/dist/types/src/components/Chess.d.ts +0 -9
  122. package/dist/types/src/components/Chess.d.ts.map +0 -1
  123. package/dist/types/src/components/Chessboard/Chessboard.d.ts +0 -37
  124. package/dist/types/src/components/Chessboard/Chessboard.d.ts.map +0 -1
  125. package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts +0 -13
  126. package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts.map +0 -1
  127. package/dist/types/src/components/Chessboard/index.d.ts +0 -2
  128. package/dist/types/src/components/Chessboard/index.d.ts.map +0 -1
  129. package/dist/types/src/components/Chessboard/pieces/custom.d.ts +0 -3
  130. package/dist/types/src/components/Chessboard/pieces/custom.d.ts.map +0 -1
  131. package/dist/types/src/components/Chessboard/pieces/index.d.ts +0 -4
  132. package/dist/types/src/components/Chessboard/pieces/index.d.ts.map +0 -1
  133. package/dist/types/src/components/Chessboard/pieces/phosphor.d.ts +0 -3
  134. package/dist/types/src/components/Chessboard/pieces/phosphor.d.ts.map +0 -1
  135. package/dist/types/src/components/Chessboard/pieces/riohacha.d.ts +0 -3
  136. package/dist/types/src/components/Chessboard/pieces/riohacha.d.ts.map +0 -1
  137. package/src/components/Chessboard/Chessboard.stories.tsx +0 -43
  138. package/src/components/Chessboard/Chessboard.tsx +0 -170
  139. package/src/components/Chessboard/index.ts +0 -5
  140. package/src/components/Chessboard/pieces/custom.tsx +0 -82
  141. package/src/components/Chessboard/pieces/index.ts +0 -7
  142. package/src/components/Chessboard/pieces/phosphor.tsx +0 -71
  143. package/src/components/Chessboard/pieces/riohacha.tsx +0 -166
@@ -1,23 +1,20 @@
1
- import type { IntentResolverProvides, MetadataRecordsProvides, SurfaceProvides, TranslationsProvides } from '@dxos/app-framework';
2
1
  import { S } from '@dxos/echo-schema';
3
- import { type SchemaProvides } from '@dxos/plugin-space';
4
- import { GameType } from './schema';
2
+ import { ChessType } from './schema';
5
3
  export declare namespace ChessAction {
6
4
  const Create_base: S.TaggedClass<Create, "dxos.org/plugin/chess/action/create", {
7
5
  readonly _tag: S.tag<"dxos.org/plugin/chess/action/create">;
8
6
  } & {
9
7
  input: S.Struct<{
10
8
  name: S.optional<typeof S.String>;
9
+ fen: S.optional<typeof S.String>;
11
10
  }>;
12
11
  output: S.Struct<{
13
- object: typeof GameType;
12
+ object: typeof ChessType;
14
13
  }>;
15
14
  }>;
16
15
  export class Create extends Create_base {
17
16
  }
18
17
  export {};
19
18
  }
20
- export type ChessProvides = {};
21
- export type ChessPluginProvides = SurfaceProvides & IntentResolverProvides & MetadataRecordsProvides & TranslationsProvides & SchemaProvides;
22
- export declare const isObject: (object: unknown) => object is GameType;
19
+ export declare const isObject: (object: unknown) => object is typeof ChessType;
23
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,sBAAsB,EACtB,uBAAuB,EACvB,eAAe,EACf,oBAAoB,EACrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAEtC,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGpC,yBAAiB,WAAW,CAAC;;;;;;;;;;;IAG3B,MAAM,OAAO,MAAO,SAAQ,WAO1B;KAAG;;CACN;AAED,MAAM,MAAM,aAAa,GAAG,EAAE,CAAC;AAE/B,MAAM,MAAM,mBAAmB,GAAG,eAAe,GAC/C,sBAAsB,GACtB,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"}
@@ -1 +1 @@
1
- {"version":"5.7.2"}
1
+ {"version":"5.7.3"}
package/package.json CHANGED
@@ -1,23 +1,19 @@
1
1
  {
2
2
  "name": "@dxos/plugin-chess",
3
- "version": "0.7.5-main.499c70c",
3
+ "version": "0.7.5-main.5ae2ba8",
4
4
  "description": "Chess for new plugin",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
7
7
  "license": "MIT",
8
8
  "author": "DXOS.org",
9
9
  "sideEffects": true,
10
+ "type": "module",
10
11
  "exports": {
11
12
  ".": {
12
13
  "types": "./dist/types/src/index.d.ts",
13
14
  "browser": "./dist/lib/browser/index.mjs",
14
15
  "node": "./dist/lib/node-esm/index.mjs"
15
16
  },
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
17
  "./types": {
22
18
  "types": "./dist/types/src/types/index.d.ts",
23
19
  "browser": "./dist/lib/browser/types/index.mjs",
@@ -27,9 +23,6 @@
27
23
  "types": "dist/types/src/index.d.ts",
28
24
  "typesVersions": {
29
25
  "*": {
30
- "meta": [
31
- "dist/types/src/meta.d.ts"
32
- ],
33
26
  "types": [
34
27
  "dist/types/src/types/index.d.ts"
35
28
  ]
@@ -42,19 +35,22 @@
42
35
  "dependencies": {
43
36
  "@effect/schema": "^0.75.5",
44
37
  "@preact/signals-core": "^1.6.0",
45
- "chess.js": "^1.0.0-beta.8",
46
- "react-chessboard": "^4.7.1",
47
- "react-resize-detector": "^11.0.1",
48
- "@dxos/app-framework": "0.7.5-main.499c70c",
49
- "@dxos/async": "0.7.5-main.499c70c",
50
- "@dxos/display-name": "0.7.5-main.499c70c",
51
- "@dxos/invariant": "0.7.5-main.499c70c",
52
- "@dxos/echo-schema": "0.7.5-main.499c70c",
53
- "@dxos/live-object": "0.7.5-main.499c70c",
54
- "@dxos/plugin-client": "0.7.5-main.499c70c",
55
- "@dxos/plugin-space": "0.7.5-main.499c70c",
56
- "@dxos/plugin-graph": "0.7.5-main.499c70c",
57
- "@dxos/react-client": "0.7.5-main.499c70c"
38
+ "chess.js": "^1.0.0",
39
+ "effect": "^3.12.3",
40
+ "@dxos/app-framework": "0.7.5-main.5ae2ba8",
41
+ "@dxos/assistant": "0.7.5-main.5ae2ba8",
42
+ "@dxos/artifact": "0.7.5-main.5ae2ba8",
43
+ "@dxos/async": "0.7.5-main.5ae2ba8",
44
+ "@dxos/display-name": "0.7.5-main.5ae2ba8",
45
+ "@dxos/echo-schema": "0.7.5-main.5ae2ba8",
46
+ "@dxos/live-object": "0.7.5-main.5ae2ba8",
47
+ "@dxos/invariant": "0.7.5-main.5ae2ba8",
48
+ "@dxos/plugin-client": "0.7.5-main.5ae2ba8",
49
+ "@dxos/plugin-graph": "0.7.5-main.5ae2ba8",
50
+ "@dxos/plugin-space": "0.7.5-main.5ae2ba8",
51
+ "@dxos/react-client": "0.7.5-main.5ae2ba8",
52
+ "@dxos/react-ui-gameboard": "0.7.5-main.5ae2ba8",
53
+ "@dxos/react-ui-stack": "0.7.5-main.5ae2ba8"
58
54
  },
59
55
  "devDependencies": {
60
56
  "@phosphor-icons/react": "^2.1.5",
@@ -63,16 +59,16 @@
63
59
  "react": "~18.2.0",
64
60
  "react-dom": "~18.2.0",
65
61
  "vite": "5.4.7",
66
- "@dxos/react-ui": "0.7.5-main.499c70c",
67
- "@dxos/react-ui-theme": "0.7.5-main.499c70c",
68
- "@dxos/storybook-utils": "0.7.5-main.499c70c"
62
+ "@dxos/react-ui": "0.7.5-main.5ae2ba8",
63
+ "@dxos/react-ui-theme": "0.7.5-main.5ae2ba8",
64
+ "@dxos/storybook-utils": "0.7.5-main.5ae2ba8"
69
65
  },
70
66
  "peerDependencies": {
71
67
  "@phosphor-icons/react": "^2.1.5",
72
68
  "react": "~18.2.0",
73
69
  "react-dom": "~18.2.0",
74
- "@dxos/react-ui": "0.7.5-main.499c70c",
75
- "@dxos/react-ui-theme": "0.7.5-main.499c70c"
70
+ "@dxos/react-ui-theme": "0.7.5-main.5ae2ba8",
71
+ "@dxos/react-ui": "0.7.5-main.5ae2ba8"
76
72
  },
77
73
  "publishConfig": {
78
74
  "access": "public"
@@ -2,50 +2,60 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import React from 'react';
5
+ import { Capabilities, contributes, createIntent, defineModule, definePlugin, Events } from '@dxos/app-framework';
6
+ import { ClientEvents } from '@dxos/plugin-client';
7
+ import { SpaceCapabilities } from '@dxos/plugin-space';
8
+ import { defineObjectForm } from '@dxos/plugin-space/types';
6
9
 
7
- import { createIntent, createResolver, createSurface, type PluginDefinition } from '@dxos/app-framework';
8
- import { create } from '@dxos/live-object';
9
-
10
- import ChessContainer from './components/ChessContainer';
11
- import meta, { CHESS_PLUGIN } from './meta';
10
+ import { ArtifactDefinition, IntentResolver, ReactSurface } from './capabilities';
11
+ import { CHESS_PLUGIN, meta } from './meta';
12
12
  import translations from './translations';
13
- import { ChessAction, type ChessPluginProvides, GameType, isObject } from './types';
13
+ import { ChessAction, ChessType } from './types';
14
14
 
15
- export const ChessPlugin = (): PluginDefinition<ChessPluginProvides> => {
16
- return {
17
- meta,
18
- provides: {
19
- metadata: {
20
- records: {
21
- [GameType.typename]: {
22
- createObject: (props: { name?: string }) => createIntent(ChessAction.Create, props),
15
+ export const ChessPlugin = () =>
16
+ definePlugin(meta, [
17
+ defineModule({
18
+ id: `${meta.id}/module/translations`,
19
+ activatesOn: Events.SetupTranslations,
20
+ activate: () => contributes(Capabilities.Translations, translations),
21
+ }),
22
+ defineModule({
23
+ id: `${meta.id}/module/metadata`,
24
+ activatesOn: Events.SetupMetadata,
25
+ activate: () =>
26
+ contributes(Capabilities.Metadata, {
27
+ id: ChessType.typename,
28
+ metadata: {
23
29
  placeholder: ['game title placeholder', { ns: CHESS_PLUGIN }],
24
30
  icon: 'ph--shield-chevron--regular',
25
31
  },
26
- },
27
- },
28
- echo: {
29
- schema: [GameType],
30
- },
31
- translations,
32
- surface: {
33
- definitions: () =>
34
- createSurface({
35
- id: CHESS_PLUGIN,
36
- role: ['article', 'section'],
37
- filter: (data): data is { subject: GameType } => isObject(data.subject),
38
- component: ({ data, role }) => <ChessContainer game={data.subject} role={role} />,
32
+ }),
33
+ }),
34
+ defineModule({
35
+ id: `${meta.id}/module/object-form`,
36
+ activatesOn: ClientEvents.SetupSchema,
37
+ activate: () =>
38
+ contributes(
39
+ SpaceCapabilities.ObjectForm,
40
+ defineObjectForm({
41
+ objectSchema: ChessType,
42
+ getIntent: () => createIntent(ChessAction.Create),
39
43
  }),
40
- },
41
- intent: {
42
- resolvers: () =>
43
- createResolver(ChessAction.Create, ({ name }) => ({
44
- data: {
45
- object: create(GameType, { name }),
46
- },
47
- })),
48
- },
49
- },
50
- };
51
- };
44
+ ),
45
+ }),
46
+ defineModule({
47
+ id: `${meta.id}/module/react-surface`,
48
+ activatesOn: Events.SetupReactSurface,
49
+ activate: ReactSurface,
50
+ }),
51
+ defineModule({
52
+ id: `${meta.id}/module/intent-resolver`,
53
+ activatesOn: Events.SetupIntentResolver,
54
+ activate: IntentResolver,
55
+ }),
56
+ defineModule({
57
+ id: `${meta.id}/module/artifact-definition`,
58
+ activatesOn: Events.SetupArtifactDefinition,
59
+ activate: ArtifactDefinition,
60
+ }),
61
+ ]);
@@ -0,0 +1,115 @@
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 { meta } from '../meta';
17
+ import { ChessAction, ChessType } from '../types';
18
+
19
+ // TODO(burdon): Factor out.
20
+ declare global {
21
+ interface ToolContextExtensions {
22
+ space?: Space;
23
+ dispatch?: PromiseIntentDispatcher;
24
+ }
25
+ }
26
+
27
+ export default () => {
28
+ const definition = defineArtifact({
29
+ id: meta.id,
30
+ name: meta.name,
31
+ description: 'Provides a simple chess engine.',
32
+ instructions: `
33
+ - 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.
34
+ `,
35
+ schema: ChessType,
36
+ tools: [
37
+ defineTool(meta.id, {
38
+ name: 'create',
39
+ description: 'Create a new chess game. Returns the artifact definition for the game.',
40
+ caption: 'Creating chess game...',
41
+ schema: S.Struct({
42
+ fen: S.String.annotations({ description: 'The state of the chess game in the FEN format.' }),
43
+ }),
44
+ execute: async ({ fen }, { extensions }) => {
45
+ invariant(extensions?.space, 'No space');
46
+ invariant(extensions?.dispatch, 'No intent dispatcher');
47
+ const intent = pipe(
48
+ createIntent(ChessAction.Create, { fen }),
49
+ chain(SpaceAction.AddObject, { target: extensions.space }),
50
+ );
51
+ const { data, error } = await extensions.dispatch(intent);
52
+ if (!data || error) {
53
+ return ToolResult.Error(error?.message ?? 'Failed to create chess game');
54
+ }
55
+
56
+ return ToolResult.Success(createArtifactElement(data.id));
57
+ },
58
+ }),
59
+ defineTool(meta.id, {
60
+ name: 'list',
61
+ description: 'Query all active chess games.',
62
+ caption: 'Getting games...',
63
+ schema: S.Struct({}),
64
+ execute: async (_, { extensions }) => {
65
+ invariant(extensions?.space, 'No space');
66
+ const { objects: games } = await extensions.space.db.query(Filter.schema(ChessType)).run();
67
+ invariant(games.length > 0, 'No chess games found');
68
+ return ToolResult.Success(games);
69
+ },
70
+ }),
71
+ defineTool(meta.id, {
72
+ name: 'inspect',
73
+ description: 'Get the current state of the chess game.',
74
+ caption: 'Inspecting game...',
75
+ schema: S.Struct({ id: ObjectId }),
76
+ execute: async ({ id }, { extensions }) => {
77
+ invariant(extensions?.space, 'No space');
78
+ const { objects: games } = await extensions.space.db.query(Filter.schema(ChessType)).run();
79
+ const game = games.find((game) => game.id === id);
80
+ invariant(isInstanceOf(ChessType, game));
81
+ return ToolResult.Success(game.fen);
82
+ },
83
+ }),
84
+ defineTool(meta.id, {
85
+ name: 'move',
86
+ description: 'Make a move in the chess game.',
87
+ caption: 'Making chess move...',
88
+ schema: S.Struct({
89
+ id: ObjectId,
90
+ move: S.String.annotations({
91
+ description: 'The move to make in the chess game.',
92
+ examples: ['e4', 'Bf3'],
93
+ }),
94
+ }),
95
+ execute: async ({ id, move }, { extensions }) => {
96
+ invariant(extensions?.space, 'No space');
97
+ const { objects: games } = await extensions.space.db.query(Filter.schema(ChessType)).run();
98
+ const game = games.find((game) => game.id === id);
99
+ invariant(isInstanceOf(ChessType, game));
100
+ const board = new Chess(game.fen);
101
+ try {
102
+ board.move(move);
103
+ } catch (error: any) {
104
+ return ToolResult.Error(error.message);
105
+ }
106
+ game.pgn = board.pgn();
107
+ game.fen = board.fen();
108
+ return ToolResult.Success(game.fen);
109
+ },
110
+ }),
111
+ ],
112
+ });
113
+
114
+ return contributes(Capabilities.ArtifactDefinition, definition);
115
+ };
@@ -0,0 +1,9 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { lazy } from '@dxos/app-framework';
6
+
7
+ export const ArtifactDefinition = lazy(() => import('./artifact-definition'));
8
+ export const IntentResolver = lazy(() => import('./intent-resolver'));
9
+ export const ReactSurface = lazy(() => import('./react-surface'));
@@ -0,0 +1,26 @@
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({
16
+ intent: ChessAction.Create,
17
+ resolve: ({ name, fen }) => {
18
+ const pgn = fen ? new Chess(fen).pgn() : undefined;
19
+ return {
20
+ data: {
21
+ object: create(ChessType, { name, fen, pgn }),
22
+ },
23
+ };
24
+ },
25
+ }),
26
+ );
@@ -0,0 +1,29 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import React from 'react';
6
+
7
+ import { Capabilities, contributes, createSurface } from '@dxos/app-framework';
8
+ import { isInstanceOf } from '@dxos/echo-schema';
9
+
10
+ import { ChessContainer } from '../components';
11
+ import { ChessComponent } from '../components/ChessComponent';
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 }) => <ChessComponent game={data} />,
28
+ }),
29
+ ]);
@@ -0,0 +1,49 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { Chess } from 'chess.js';
6
+ import React, { useCallback, useEffect, useMemo } from 'react';
7
+
8
+ import { getSpace } from '@dxos/react-client/echo';
9
+ import { ChessModel, Board, Chessboard, type BoardRootProps } from '@dxos/react-ui-gameboard';
10
+
11
+ import { type ChessType } from '../types';
12
+
13
+ export const ChessComponent = ({ game }: { game: ChessType }) => {
14
+ const model = useMemo(() => new ChessModel(), []);
15
+ useEffect(() => {
16
+ if (!model || game.pgn !== model?.game.pgn()) {
17
+ const chess = new Chess();
18
+ if (game.pgn) {
19
+ chess.loadPgn(game.pgn);
20
+ }
21
+
22
+ model.initialize(chess.fen());
23
+ }
24
+ }, [game.pgn]);
25
+
26
+ const space = getSpace(game);
27
+ if (!space) {
28
+ return null;
29
+ }
30
+
31
+ const handleDrop = useCallback<NonNullable<BoardRootProps['onDrop']>>(
32
+ (move) => {
33
+ if (model.makeMove(move)) {
34
+ game.pgn = model.game.pgn();
35
+ game.fen = model.game.fen();
36
+ return true;
37
+ }
38
+
39
+ return false;
40
+ },
41
+ [model],
42
+ );
43
+
44
+ return (
45
+ <Board.Root model={model} onDrop={handleDrop}>
46
+ <Chessboard />
47
+ </Board.Root>
48
+ );
49
+ };
@@ -2,22 +2,33 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import React, { type ComponentProps } from 'react';
5
+ import React from 'react';
6
6
 
7
7
  import { getSpace } from '@dxos/react-client/echo';
8
+ import { StackItem } from '@dxos/react-ui-stack';
8
9
 
9
- import { Chess } from './Chess';
10
+ import { ChessComponent } from './ChessComponent';
11
+ import { PlayerSelector } from './PlayerSelector';
12
+ import { type ChessType } from '../types';
10
13
 
11
- const ChessContainer = ({ game, role }: Pick<ComponentProps<typeof Chess>, 'game'> & { role?: string }) => {
14
+ const ChessContainer = ({ game }: { game: ChessType; role?: string }) => {
12
15
  const space = getSpace(game);
13
16
  if (!space) {
14
17
  return null;
15
18
  }
16
19
 
17
20
  return (
18
- <div role='none' className='flex flex-col row-span-2 is-full overflow-hidden'>
19
- <Chess game={game} space={space} playerSelector={role === 'article'} />
20
- </div>
21
+ <StackItem.Content toolbar={false}>
22
+ <div role='none' className='grid grid-rows-[60px_1fr_60px] grow overflow-hidden'>
23
+ <div />
24
+
25
+ <div className='flex m-4 overflow-hidden'>
26
+ <ChessComponent game={game} />
27
+ </div>
28
+
29
+ <PlayerSelector space={space} game={game} />
30
+ </div>
31
+ </StackItem.Content>
21
32
  );
22
33
  };
23
34
 
@@ -0,0 +1,67 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { ArrowURightDown, Circle } from '@phosphor-icons/react';
6
+ import { type Color } from 'chess.js';
7
+ import React, { type FC } from 'react';
8
+
9
+ import { type ThemedClassName } from '@dxos/react-ui';
10
+ import { type ChessModel } from '@dxos/react-ui-gameboard';
11
+ import { getSize, mx } from '@dxos/react-ui-theme';
12
+
13
+ export type ChessPanelProps = ThemedClassName<{
14
+ model: ChessModel;
15
+ orientation?: Color;
16
+ onFlip?: () => void;
17
+ }>;
18
+
19
+ export const ChessPanel: FC<ChessPanelProps> = ({ classNames, model, orientation = 'w', onFlip }) => {
20
+ const game = model.game;
21
+ const history = game.history();
22
+ const label = game.isGameOver()
23
+ ? game.isCheckmate()
24
+ ? 'CHECKMATE'
25
+ : game.isStalemate()
26
+ ? 'STALEMATE'
27
+ : 'DRAW'
28
+ : game.isCheck()
29
+ ? 'CHECK'
30
+ : history.length
31
+ ? `Move ${history.length}`
32
+ : '';
33
+
34
+ const Player = ({ color }: { color: Color }) => {
35
+ const turn = color === game.turn();
36
+
37
+ return (
38
+ <div className='flex items-center'>
39
+ <Circle
40
+ className={mx(getSize(4), turn && (game.isCheckmate() ? 'text-red-500' : 'text-green-500'))}
41
+ weight={turn ? 'fill' : 'thin'}
42
+ />
43
+ </div>
44
+ );
45
+ };
46
+
47
+ return (
48
+ <div className={mx('flex flex-col', classNames)}>
49
+ <div className='flex items-center justify-between pl-2 pr-2 border-b' style={{ height: 32 }}>
50
+ <Player color={orientation === 'w' ? 'b' : 'w'} />
51
+ {onFlip && (
52
+ <button onClick={onFlip}>
53
+ <ArrowURightDown weight='thin' className={getSize(6)} />
54
+ </button>
55
+ )}
56
+ </div>
57
+
58
+ <div className='flex flex-col justify-center pl-2 font-thin' style={{ height: 40 }}>
59
+ {label}
60
+ </div>
61
+
62
+ <div className='flex items-center justify-between pl-2 pr-2 border-t' style={{ height: 32 }}>
63
+ <Player color={orientation} />
64
+ </div>
65
+ </div>
66
+ );
67
+ };
@@ -0,0 +1,39 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import '@dxos-theme';
6
+
7
+ import { type Meta, type StoryObj } from '@storybook/react';
8
+ import React, { useMemo } from 'react';
9
+
10
+ import { Board, Chessboard, ChessModel } from '@dxos/react-ui-gameboard';
11
+ import { withLayout, withTheme } from '@dxos/storybook-utils';
12
+
13
+ import { ChessPanel } from './ChessPanel';
14
+
15
+ const Render = () => {
16
+ const model = useMemo(() => new ChessModel(), []);
17
+
18
+ return (
19
+ <div className='flex grow mx-8 gap-8 items-center overflow-hidden'>
20
+ <Board.Root model={model} onDrop={(move) => model.makeMove(move)}>
21
+ <Chessboard />
22
+ </Board.Root>
23
+ <ChessPanel model={model} classNames='w-[200px]' />
24
+ </div>
25
+ );
26
+ };
27
+
28
+ const meta: Meta<typeof Chessboard> = {
29
+ title: 'plugins/plugin-chess/Chessboard',
30
+ component: Chessboard,
31
+ render: Render,
32
+ decorators: [withTheme, withLayout({ fullscreen: true })],
33
+ };
34
+
35
+ type Story = StoryObj<typeof Chessboard>;
36
+
37
+ export default meta;
38
+
39
+ export const Default: Story = {};