@dxos/app-framework 0.8.4-main.67995b8 → 0.8.4-main.72ec0f3

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 (226) hide show
  1. package/.storybook/main.mts +11 -0
  2. package/.storybook/preview.mts +8 -0
  3. package/.swc/plugins/linux_x86_64_19.0.0/727453fb3a62f7f1d952a41e051ca8a6f88cadc45cee43c6a4d1aa45f9b75665.wasmer-v7 +0 -0
  4. package/.swc/plugins/{v7_linux_x86_64_13.0.0/fce1bdb8e20a094e4af08bad09cc81497ed0e2e7c51223b07d371063cca18429 → linux_x86_64_19.0.0/fce1bdb8e20a094e4af08bad09cc81497ed0e2e7c51223b07d371063cca18429.wasmer-v7} +0 -0
  5. package/dist/lib/browser/{app-graph-builder-LYF7EKNN.mjs → app-graph-builder-OIEZZC45.mjs} +32 -31
  6. package/dist/lib/browser/app-graph-builder-OIEZZC45.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-ORWHM7CO.mjs → chunk-SCPE4ZO2.mjs} +11 -8
  8. package/dist/lib/browser/chunk-SCPE4ZO2.mjs.map +7 -0
  9. package/dist/lib/browser/{chunk-FO2PH7M3.mjs → chunk-VFUKEZIN.mjs} +254 -186
  10. package/dist/lib/browser/chunk-VFUKEZIN.mjs.map +7 -0
  11. package/dist/lib/browser/{chunk-FMN65HSW.mjs → chunk-WPW5VVAX.mjs} +397 -265
  12. package/dist/lib/browser/chunk-WPW5VVAX.mjs.map +7 -0
  13. package/dist/lib/browser/index.mjs +20 -56
  14. package/dist/lib/browser/index.mjs.map +3 -3
  15. package/dist/lib/browser/{intent-dispatcher-LSYQZSEB.mjs → intent-dispatcher-LZ4AE66E.mjs} +2 -2
  16. package/dist/lib/browser/{intent-resolver-ZTNOSO3A.mjs → intent-resolver-QVCKRX6G.mjs} +7 -7
  17. package/dist/lib/browser/intent-resolver-QVCKRX6G.mjs.map +7 -0
  18. package/dist/lib/browser/meta.json +1 -1
  19. package/dist/lib/browser/react/index.mjs +34 -0
  20. package/dist/lib/browser/{store-KML2R4IE.mjs → store-CNPHOYTJ.mjs} +5 -5
  21. package/dist/lib/browser/store-CNPHOYTJ.mjs.map +7 -0
  22. package/dist/lib/browser/testing/index.mjs +17 -21
  23. package/dist/lib/browser/testing/index.mjs.map +3 -3
  24. package/dist/lib/node-esm/{app-graph-builder-SAOWGJDK.mjs → app-graph-builder-EBU4NVWD.mjs} +32 -31
  25. package/dist/lib/node-esm/app-graph-builder-EBU4NVWD.mjs.map +7 -0
  26. package/dist/lib/node-esm/{chunk-73HGSHKE.mjs → chunk-IJOHO66N.mjs} +254 -186
  27. package/dist/lib/node-esm/chunk-IJOHO66N.mjs.map +7 -0
  28. package/dist/lib/node-esm/{chunk-ZEZ4FVEU.mjs → chunk-XJZGUJ3H.mjs} +397 -265
  29. package/dist/lib/node-esm/chunk-XJZGUJ3H.mjs.map +7 -0
  30. package/dist/lib/node-esm/{chunk-UMZQERLE.mjs → chunk-ZX63QUGE.mjs} +11 -8
  31. package/dist/lib/node-esm/chunk-ZX63QUGE.mjs.map +7 -0
  32. package/dist/lib/node-esm/index.mjs +20 -56
  33. package/dist/lib/node-esm/index.mjs.map +3 -3
  34. package/dist/lib/node-esm/{intent-dispatcher-6CYNGPSW.mjs → intent-dispatcher-MGOJ3CHD.mjs} +2 -2
  35. package/dist/lib/node-esm/{intent-resolver-W7Z7WFFM.mjs → intent-resolver-URF3HN3G.mjs} +7 -7
  36. package/dist/lib/node-esm/intent-resolver-URF3HN3G.mjs.map +7 -0
  37. package/dist/lib/node-esm/meta.json +1 -1
  38. package/dist/lib/node-esm/react/index.mjs +35 -0
  39. package/dist/lib/node-esm/{store-QEXGXLWZ.mjs → store-RK5B4XEL.mjs} +5 -5
  40. package/dist/lib/node-esm/store-RK5B4XEL.mjs.map +7 -0
  41. package/dist/lib/node-esm/testing/index.mjs +17 -21
  42. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  43. package/dist/types/src/common/capabilities.d.ts +110 -39
  44. package/dist/types/src/common/capabilities.d.ts.map +1 -1
  45. package/dist/types/src/common/collaboration.d.ts +10 -9
  46. package/dist/types/src/common/collaboration.d.ts.map +1 -1
  47. package/dist/types/src/common/events.d.ts.map +1 -1
  48. package/dist/types/src/common/file.d.ts +1 -1
  49. package/dist/types/src/common/file.d.ts.map +1 -1
  50. package/dist/types/src/common/index.d.ts +1 -1
  51. package/dist/types/src/common/index.d.ts.map +1 -1
  52. package/dist/types/src/common/layout.d.ts +1 -3
  53. package/dist/types/src/common/layout.d.ts.map +1 -1
  54. package/dist/types/src/common/surface.d.ts +19 -16
  55. package/dist/types/src/common/surface.d.ts.map +1 -1
  56. package/dist/types/src/common/translations.d.ts +1 -1
  57. package/dist/types/src/common/translations.d.ts.map +1 -1
  58. package/dist/types/src/core/capabilities.d.ts +19 -16
  59. package/dist/types/src/core/capabilities.d.ts.map +1 -1
  60. package/dist/types/src/core/manager.d.ts +7 -3
  61. package/dist/types/src/core/manager.d.ts.map +1 -1
  62. package/dist/types/src/core/plugin.d.ts +8 -1
  63. package/dist/types/src/core/plugin.d.ts.map +1 -1
  64. package/dist/types/src/index.d.ts +0 -2
  65. package/dist/types/src/index.d.ts.map +1 -1
  66. package/dist/types/src/playground/debug/Debug.d.ts +1 -1
  67. package/dist/types/src/playground/debug/plugin.d.ts +1 -1
  68. package/dist/types/src/playground/debug/plugin.d.ts.map +1 -1
  69. package/dist/types/src/playground/generator/Main.d.ts +1 -1
  70. package/dist/types/src/playground/generator/Main.d.ts.map +1 -1
  71. package/dist/types/src/playground/generator/Toolbar.d.ts +1 -1
  72. package/dist/types/src/playground/generator/Toolbar.d.ts.map +1 -1
  73. package/dist/types/src/playground/generator/generator.d.ts +1 -1
  74. package/dist/types/src/playground/generator/generator.d.ts.map +1 -1
  75. package/dist/types/src/playground/generator/plugin.d.ts +1 -1
  76. package/dist/types/src/playground/generator/plugin.d.ts.map +1 -1
  77. package/dist/types/src/playground/layout/Layout.d.ts +2 -2
  78. package/dist/types/src/playground/layout/plugin.d.ts +1 -1
  79. package/dist/types/src/playground/layout/plugin.d.ts.map +1 -1
  80. package/dist/types/src/playground/logger/Toolbar.d.ts +1 -1
  81. package/dist/types/src/playground/logger/Toolbar.d.ts.map +1 -1
  82. package/dist/types/src/playground/logger/plugin.d.ts +1 -1
  83. package/dist/types/src/playground/logger/plugin.d.ts.map +1 -1
  84. package/dist/types/src/playground/logger/schema.d.ts +1 -1
  85. package/dist/types/src/playground/logger/schema.d.ts.map +1 -1
  86. package/dist/types/src/playground/playground.stories.d.ts +5 -4
  87. package/dist/types/src/playground/playground.stories.d.ts.map +1 -1
  88. package/dist/types/src/plugin-intent/IntentPlugin.d.ts +1 -1
  89. package/dist/types/src/plugin-intent/IntentPlugin.d.ts.map +1 -1
  90. package/dist/types/src/plugin-intent/actions.d.ts +5 -7
  91. package/dist/types/src/plugin-intent/actions.d.ts.map +1 -1
  92. package/dist/types/src/plugin-intent/errors.d.ts.map +1 -1
  93. package/dist/types/src/plugin-intent/index.d.ts +1 -0
  94. package/dist/types/src/plugin-intent/index.d.ts.map +1 -1
  95. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts +7 -7
  96. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts.map +1 -1
  97. package/dist/types/src/plugin-intent/intent.d.ts +1 -1
  98. package/dist/types/src/plugin-intent/intent.d.ts.map +1 -1
  99. package/dist/types/src/plugin-intent/meta.d.ts +3 -0
  100. package/dist/types/src/plugin-intent/meta.d.ts.map +1 -0
  101. package/dist/types/src/plugin-settings/SettingsPlugin.d.ts +1 -1
  102. package/dist/types/src/plugin-settings/SettingsPlugin.d.ts.map +1 -1
  103. package/dist/types/src/plugin-settings/actions.d.ts +5 -7
  104. package/dist/types/src/plugin-settings/actions.d.ts.map +1 -1
  105. package/dist/types/src/plugin-settings/app-graph-builder.d.ts +1 -1
  106. package/dist/types/src/plugin-settings/app-graph-builder.d.ts.map +1 -1
  107. package/dist/types/src/plugin-settings/intent-resolver.d.ts +1 -1
  108. package/dist/types/src/plugin-settings/intent-resolver.d.ts.map +1 -1
  109. package/dist/types/src/plugin-settings/meta.d.ts +3 -0
  110. package/dist/types/src/plugin-settings/meta.d.ts.map +1 -0
  111. package/dist/types/src/plugin-settings/store.d.ts +1 -1
  112. package/dist/types/src/plugin-settings/store.d.ts.map +1 -1
  113. package/dist/types/src/plugin-settings/translations.d.ts +2 -1
  114. package/dist/types/src/plugin-settings/translations.d.ts.map +1 -1
  115. package/dist/types/src/react/App.d.ts +10 -0
  116. package/dist/types/src/react/App.d.ts.map +1 -0
  117. package/dist/types/src/react/App.stories.d.ts +14 -0
  118. package/dist/types/src/react/App.stories.d.ts.map +1 -0
  119. package/dist/types/src/react/DefaultFallback.d.ts +8 -0
  120. package/dist/types/src/react/DefaultFallback.d.ts.map +1 -0
  121. package/dist/types/src/react/ErrorBoundary.d.ts +13 -14
  122. package/dist/types/src/react/ErrorBoundary.d.ts.map +1 -1
  123. package/dist/types/src/react/IntentContext.d.ts.map +1 -1
  124. package/dist/types/src/react/Surface.d.ts +5 -5
  125. package/dist/types/src/react/Surface.d.ts.map +1 -1
  126. package/dist/types/src/react/Surface.stories.d.ts +8 -10
  127. package/dist/types/src/react/Surface.stories.d.ts.map +1 -1
  128. package/dist/types/src/react/common.d.ts.map +1 -1
  129. package/dist/types/src/react/index.d.ts +2 -0
  130. package/dist/types/src/react/index.d.ts.map +1 -1
  131. package/dist/types/src/react/types.d.ts +14 -0
  132. package/dist/types/src/react/types.d.ts.map +1 -0
  133. package/dist/types/src/{App.d.ts → react/useApp.d.ts} +7 -6
  134. package/dist/types/src/react/useApp.d.ts.map +1 -0
  135. package/dist/types/src/react/useCapabilities.d.ts.map +1 -1
  136. package/dist/types/src/react/useLoading.d.ts +19 -0
  137. package/dist/types/src/react/useLoading.d.ts.map +1 -0
  138. package/dist/types/src/testing/withPluginManager.d.ts +9 -8
  139. package/dist/types/src/testing/withPluginManager.d.ts.map +1 -1
  140. package/dist/types/src/testing/withPluginManager.stories.d.ts +9 -3
  141. package/dist/types/src/testing/withPluginManager.stories.d.ts.map +1 -1
  142. package/dist/types/tsconfig.tsbuildinfo +1 -1
  143. package/moon.yml +5 -1
  144. package/package.json +48 -43
  145. package/src/common/capabilities.ts +116 -20
  146. package/src/common/collaboration.ts +6 -9
  147. package/src/common/events.ts +3 -1
  148. package/src/common/file.ts +1 -1
  149. package/src/common/index.ts +1 -1
  150. package/src/common/layout.ts +3 -4
  151. package/src/common/surface.ts +23 -21
  152. package/src/common/translations.ts +1 -1
  153. package/src/core/capabilities.test.ts +3 -3
  154. package/src/core/capabilities.ts +36 -27
  155. package/src/core/manager.test.ts +22 -21
  156. package/src/core/manager.ts +141 -56
  157. package/src/core/plugin.ts +13 -2
  158. package/src/helpers.test.ts +1 -1
  159. package/src/index.ts +0 -2
  160. package/src/playground/debug/Debug.tsx +1 -1
  161. package/src/playground/debug/plugin.ts +7 -8
  162. package/src/playground/generator/Main.tsx +0 -1
  163. package/src/playground/generator/Toolbar.tsx +2 -1
  164. package/src/playground/generator/generator.ts +4 -4
  165. package/src/playground/generator/plugin.ts +12 -13
  166. package/src/playground/layout/plugin.ts +10 -9
  167. package/src/playground/logger/Toolbar.tsx +2 -1
  168. package/src/playground/logger/plugin.ts +30 -25
  169. package/src/playground/logger/schema.ts +1 -1
  170. package/src/playground/playground.stories.tsx +20 -16
  171. package/src/plugin-intent/IntentPlugin.ts +13 -13
  172. package/src/plugin-intent/actions.ts +4 -6
  173. package/src/plugin-intent/errors.ts +2 -1
  174. package/src/plugin-intent/index.ts +1 -0
  175. package/src/plugin-intent/intent-dispatcher.test.ts +10 -3
  176. package/src/plugin-intent/intent-dispatcher.ts +21 -12
  177. package/src/plugin-intent/intent.ts +1 -1
  178. package/src/plugin-intent/meta.ts +10 -0
  179. package/src/plugin-settings/SettingsPlugin.ts +27 -28
  180. package/src/plugin-settings/actions.ts +9 -13
  181. package/src/plugin-settings/app-graph-builder.ts +25 -22
  182. package/src/plugin-settings/intent-resolver.ts +5 -4
  183. package/src/plugin-settings/meta.ts +10 -0
  184. package/src/plugin-settings/store.ts +3 -3
  185. package/src/plugin-settings/translations.ts +4 -4
  186. package/src/react/App.stories.tsx +33 -0
  187. package/src/react/App.tsx +59 -0
  188. package/src/react/DefaultFallback.tsx +26 -0
  189. package/src/react/ErrorBoundary.tsx +26 -15
  190. package/src/react/IntentContext.tsx +3 -2
  191. package/src/react/Surface.stories.tsx +81 -52
  192. package/src/react/Surface.tsx +70 -38
  193. package/src/react/common.ts +2 -1
  194. package/src/react/index.ts +4 -0
  195. package/src/react/types.ts +37 -0
  196. package/src/react/useApp.tsx +165 -0
  197. package/src/react/useCapabilities.ts +4 -3
  198. package/src/react/useLoading.tsx +70 -0
  199. package/src/testing/withPluginManager.stories.tsx +9 -5
  200. package/src/testing/withPluginManager.tsx +33 -32
  201. package/tsconfig.json +11 -9
  202. package/vitest.config.ts +8 -6
  203. package/.swc/plugins/v7_linux_x86_64_13.0.0/f45bdff002284d9e8f9ef3f0be909de12da36c049cbcf261ac78fc00abb09a2d +0 -0
  204. package/dist/lib/browser/app-graph-builder-LYF7EKNN.mjs.map +0 -7
  205. package/dist/lib/browser/chunk-FMN65HSW.mjs.map +0 -7
  206. package/dist/lib/browser/chunk-FO2PH7M3.mjs.map +0 -7
  207. package/dist/lib/browser/chunk-ORWHM7CO.mjs.map +0 -7
  208. package/dist/lib/browser/intent-resolver-ZTNOSO3A.mjs.map +0 -7
  209. package/dist/lib/browser/store-KML2R4IE.mjs.map +0 -7
  210. package/dist/lib/browser/worker.mjs +0 -79
  211. package/dist/lib/node-esm/app-graph-builder-SAOWGJDK.mjs.map +0 -7
  212. package/dist/lib/node-esm/chunk-73HGSHKE.mjs.map +0 -7
  213. package/dist/lib/node-esm/chunk-UMZQERLE.mjs.map +0 -7
  214. package/dist/lib/node-esm/chunk-ZEZ4FVEU.mjs.map +0 -7
  215. package/dist/lib/node-esm/intent-resolver-W7Z7WFFM.mjs.map +0 -7
  216. package/dist/lib/node-esm/store-QEXGXLWZ.mjs.map +0 -7
  217. package/dist/lib/node-esm/worker.mjs +0 -80
  218. package/dist/types/src/App.d.ts.map +0 -1
  219. package/dist/types/src/worker.d.ts +0 -4
  220. package/dist/types/src/worker.d.ts.map +0 -1
  221. package/src/App.tsx +0 -276
  222. package/src/worker.ts +0 -11
  223. /package/dist/lib/browser/{intent-dispatcher-LSYQZSEB.mjs.map → intent-dispatcher-LZ4AE66E.mjs.map} +0 -0
  224. /package/dist/lib/browser/{worker.mjs.map → react/index.mjs.map} +0 -0
  225. /package/dist/lib/node-esm/{intent-dispatcher-6CYNGPSW.mjs.map → intent-dispatcher-MGOJ3CHD.mjs.map} +0 -0
  226. /package/dist/lib/node-esm/{worker.mjs.map → react/index.mjs.map} +0 -0
@@ -1,108 +1,17 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
2
 
3
3
  // src/plugin-intent/intent-dispatcher.ts
4
- import { Effect as Effect3, Option, pipe as pipe2, Ref as Ref2 } from "effect";
4
+ import * as Effect3 from "effect/Effect";
5
+ import * as Function2 from "effect/Function";
6
+ import * as Option from "effect/Option";
7
+ import * as Ref2 from "effect/Ref";
5
8
  import { live as live2 } from "@dxos/live-object";
6
9
  import { log as log3 } from "@dxos/log";
7
10
  import { byPosition } from "@dxos/util";
8
11
 
9
- // src/plugin-intent/actions.ts
10
- import { Schema as Schema2 } from "effect";
11
-
12
- // src/plugin-intent/intent.ts
13
- import { Schema } from "effect";
14
- var createIntent = (schema, data = {}, params = {}) => {
15
- const _ = Schema.validateSync(schema.fields.input)(data);
16
- const intent = {
17
- ...params,
18
- _schema: schema,
19
- id: schema._tag,
20
- data
21
- };
22
- return {
23
- first: intent,
24
- last: intent,
25
- all: [
26
- intent
27
- ]
28
- };
29
- };
30
- var chain = (schema, data = {}, params = {}) => (intent) => {
31
- const intents = "all" in intent ? intent.all : [
32
- intent
33
- ];
34
- const first = intents[0];
35
- const last = {
36
- ...params,
37
- _schema: schema,
38
- id: schema._tag,
39
- data
40
- };
41
- return {
42
- first,
43
- last,
44
- all: [
45
- ...intents,
46
- last
47
- ]
48
- };
49
- };
50
- var Label = Schema.Union(Schema.String, Schema.mutable(Schema.Tuple(Schema.String, Schema.mutable(Schema.Struct({
51
- ns: Schema.String,
52
- count: Schema.optional(Schema.Number),
53
- defaultValue: Schema.optional(Schema.String)
54
- })))));
55
-
56
- // src/plugin-intent/actions.ts
57
- var INTENT_PLUGIN = "dxos.org/plugin/intent";
58
- var INTENT_ACTION = `${INTENT_PLUGIN}/action`;
59
- (function(IntentAction2) {
60
- class Track extends Schema2.TaggedClass()(`${INTENT_ACTION}/track`, {
61
- input: Schema2.Struct({
62
- intents: Schema2.Array(Schema2.String),
63
- error: Schema2.optional(Schema2.String)
64
- }),
65
- output: Schema2.Void
66
- }) {
67
- }
68
- IntentAction2.Track = Track;
69
- class ShowUndo extends Schema2.TaggedClass()(`${INTENT_ACTION}/show-undo`, {
70
- input: Schema2.Struct({
71
- message: Label
72
- }),
73
- output: Schema2.Void
74
- }) {
75
- }
76
- IntentAction2.ShowUndo = ShowUndo;
77
- })(IntentAction || (IntentAction = {}));
78
- var IntentAction;
79
-
80
- // src/plugin-intent/errors.ts
81
- var BaseError = class extends Error {
82
- constructor(code, message, context) {
83
- super(message ?? code, {
84
- cause: context
85
- }), this.code = code, this.context = context;
86
- this.name = code;
87
- Object.setPrototypeOf(this, new.target.prototype);
88
- }
89
- };
90
- var NoResolversError = class extends BaseError {
91
- constructor(action) {
92
- super("NO_RESOLVERS", "No resolvers were found for the action", {
93
- action
94
- });
95
- }
96
- };
97
- var CycleDetectedError = class extends BaseError {
98
- constructor(context) {
99
- super("CYCLE_DETECTED", "Intent execution limit exceeded. This is likely due to an infinite loop within intent resolvers.", context);
100
- }
101
- };
102
-
103
12
  // src/core/capabilities.ts
104
- import { Rx } from "@effect-rx/rx-react";
105
- import { Effect } from "effect";
13
+ import { Atom } from "@effect-atom/atom-react";
14
+ import * as Effect from "effect/Effect";
106
15
  import { Trigger } from "@dxos/async";
107
16
  import { invariant } from "@dxos/invariant";
108
17
  import { log } from "@dxos/log";
@@ -114,6 +23,8 @@ var defineCapability = (identifier) => {
114
23
  };
115
24
  };
116
25
  var CapabilityImpl = class {
26
+ moduleId;
27
+ implementation;
117
28
  constructor(moduleId, implementation) {
118
29
  this.moduleId = moduleId;
119
30
  this.implementation = implementation;
@@ -131,31 +42,44 @@ var lazy = (c) => async (props) => {
131
42
  return async () => getCapability(props);
132
43
  };
133
44
  var PluginContext = class {
134
- constructor({ registry, activate, reset }) {
135
- this._capabilityImpls = Rx.family(() => {
136
- return Rx.make([]).pipe(Rx.keepAlive);
137
- });
138
- this._capabilities = Rx.family((id) => {
139
- return Rx.make((get) => {
140
- const current = get(this._capabilityImpls(id));
141
- return current.map((c) => c.implementation);
142
- });
45
+ _registry;
46
+ _capabilityImpls = Atom.family(() => {
47
+ return Atom.make([]).pipe(Atom.keepAlive);
48
+ });
49
+ _capabilities = Atom.family((id) => {
50
+ return Atom.make((get) => {
51
+ const current = get(this._capabilityImpls(id));
52
+ return current.map((c) => c.implementation);
143
53
  });
144
- this._capability = Rx.family((id) => {
145
- return Rx.make((get) => {
146
- const current = get(this._capabilities(id));
147
- invariant(current.length > 0, `No capability found for ${id}`, {
148
- F: __dxlog_file,
149
- L: 117,
150
- S: this,
151
- A: [
152
- "current.length > 0",
153
- "`No capability found for ${id}`"
154
- ]
155
- });
156
- return current[0];
54
+ });
55
+ _capability = Atom.family((id) => {
56
+ return Atom.make((get) => {
57
+ const current = get(this._capabilities(id));
58
+ invariant(current.length > 0, `No capability found for ${id}`, {
59
+ F: __dxlog_file,
60
+ L: 126,
61
+ S: this,
62
+ A: [
63
+ "current.length > 0",
64
+ "`No capability found for ${id}`"
65
+ ]
157
66
  });
67
+ return current[0];
158
68
  });
69
+ });
70
+ /**
71
+ * Activates plugins based on the activation event.
72
+ * @param event The activation event.
73
+ * @returns Whether the activation was successful.
74
+ */
75
+ activate;
76
+ /**
77
+ * Re-activates the modules that were activated by the event.
78
+ * @param event The activation event.
79
+ * @returns Whether the reset was successful.
80
+ */
81
+ reset;
82
+ constructor({ registry, activate, reset }) {
159
83
  this._registry = registry;
160
84
  this.activate = activate;
161
85
  this.reset = reset;
@@ -179,7 +103,7 @@ var PluginContext = class {
179
103
  count: current.length
180
104
  }, {
181
105
  F: __dxlog_file,
182
- L: 161,
106
+ L: 170,
183
107
  S: this,
184
108
  C: (f, a) => f(...a)
185
109
  });
@@ -200,7 +124,7 @@ var PluginContext = class {
200
124
  count: current.length
201
125
  }, {
202
126
  F: __dxlog_file,
203
- L: 180,
127
+ L: 189,
204
128
  S: this,
205
129
  C: (f, a) => f(...a)
206
130
  });
@@ -209,26 +133,26 @@ var PluginContext = class {
209
133
  id: interfaceDef.identifier
210
134
  }, {
211
135
  F: __dxlog_file,
212
- L: 182,
136
+ L: 191,
213
137
  S: this,
214
138
  C: (f, a) => f(...a)
215
139
  });
216
140
  }
217
141
  }
218
142
  /**
219
- * Get the Rx reference to the available capabilities for a given interface.
220
- * Primarily useful for deriving other Rx values based on the capabilities or
143
+ * Get the Atom reference to the available capabilities for a given interface.
144
+ * Primarily useful for deriving other Atom values based on the capabilities or
221
145
  * for subscribing to changes in the capabilities.
222
- * @returns An Rx reference to the available capabilities.
146
+ * @returns An atom reference to the available capabilities.
223
147
  */
224
148
  capabilities(interfaceDef) {
225
149
  return this._capabilities(interfaceDef.identifier);
226
150
  }
227
151
  /**
228
- * Get the Rx reference to the available capabilities for a given interface.
229
- * Primarily useful for deriving other Rx values based on the capability or
152
+ * Get the Atom reference to the available capabilities for a given interface.
153
+ * Primarily useful for deriving other Atom values based on the capability or
230
154
  * for subscribing to changes in the capability.
231
- * @returns An Rx reference to the available capability.
155
+ * @returns An atom reference to the available capability.
232
156
  * @throws If no capability is found.
233
157
  */
234
158
  capability(interfaceDef) {
@@ -299,20 +223,35 @@ var getEvents = (events) => "type" in events ? events.events : [
299
223
  ];
300
224
 
301
225
  // src/core/manager.ts
302
- import { Registry } from "@effect-rx/rx-react";
226
+ import { Registry } from "@effect-atom/atom-react";
303
227
  import { untracked } from "@preact/signals-core";
304
- import { Array as A, Effect as Effect2, Either, Match, pipe } from "effect";
228
+ import * as Array from "effect/Array";
229
+ import * as Duration from "effect/Duration";
230
+ import * as Effect2 from "effect/Effect";
231
+ import * as Fiber from "effect/Fiber";
232
+ import * as Function from "effect/Function";
233
+ import * as HashSet from "effect/HashSet";
234
+ import * as Match from "effect/Match";
235
+ import * as Ref from "effect/Ref";
305
236
  import { Event } from "@dxos/async";
306
237
  import { live } from "@dxos/live-object";
307
238
  import { log as log2 } from "@dxos/log";
308
239
  var __dxlog_file2 = "/__w/dxos/dxos/packages/sdk/app-framework/src/core/manager.ts";
309
- var isPromise = (value) => {
310
- return value !== null && typeof value === "object" && "then" in value;
240
+ var isPromise = (value2) => {
241
+ return value2 !== null && typeof value2 === "object" && "then" in value2;
311
242
  };
312
243
  var PluginManager = class {
313
- constructor({ pluginLoader, plugins = [], core = plugins.map(({ meta }) => meta.id), enabled = [], registry }) {
314
- this.activation = new Event();
315
- this._capabilities = /* @__PURE__ */ new Map();
244
+ activation = new Event();
245
+ context;
246
+ registry;
247
+ // TODO(wittjosiah): Replace with Atom.
248
+ _state;
249
+ _pluginLoader;
250
+ _capabilities = /* @__PURE__ */ new Map();
251
+ _moduleMemoMap = /* @__PURE__ */ new Map();
252
+ _activatingEvents = Effect2.runSync(Ref.make([]));
253
+ _activatingModules = Effect2.runSync(Ref.make([]));
254
+ constructor({ pluginLoader, plugins = [], core = plugins.map(({ meta: meta2 }) => meta2.id), enabled = [], registry }) {
316
255
  this.registry = registry ?? Registry.make();
317
256
  this.context = new PluginContext({
318
257
  registry: this.registry,
@@ -326,8 +265,8 @@ var PluginManager = class {
326
265
  enabled,
327
266
  modules: [],
328
267
  active: [],
329
- pendingReset: [],
330
- eventsFired: []
268
+ eventsFired: [],
269
+ pendingReset: []
331
270
  });
332
271
  plugins.forEach((plugin) => this._addPlugin(plugin));
333
272
  core.forEach((id) => this.enable(id));
@@ -399,7 +338,7 @@ var PluginManager = class {
399
338
  id
400
339
  }, {
401
340
  F: __dxlog_file2,
402
- L: 154,
341
+ L: 164,
403
342
  S: this,
404
343
  C: (f, a) => f(...a)
405
344
  });
@@ -418,7 +357,7 @@ var PluginManager = class {
418
357
  id
419
358
  }, {
420
359
  F: __dxlog_file2,
421
- L: 167,
360
+ L: 177,
422
361
  S: this,
423
362
  C: (f, a) => f(...a)
424
363
  });
@@ -439,7 +378,7 @@ var PluginManager = class {
439
378
  ]
440
379
  }, {
441
380
  F: __dxlog_file2,
442
- L: 182,
381
+ L: 192,
443
382
  S: this,
444
383
  C: (f, a) => f(...a)
445
384
  });
@@ -459,7 +398,7 @@ var PluginManager = class {
459
398
  id
460
399
  }, {
461
400
  F: __dxlog_file2,
462
- L: 200,
401
+ L: 210,
463
402
  S: this,
464
403
  C: (f, a) => f(...a)
465
404
  });
@@ -481,7 +420,7 @@ var PluginManager = class {
481
420
  id
482
421
  }, {
483
422
  F: __dxlog_file2,
484
- L: 217,
423
+ L: 227,
485
424
  S: this,
486
425
  C: (f, a) => f(...a)
487
426
  });
@@ -533,7 +472,7 @@ var PluginManager = class {
533
472
  id: plugin.meta.id
534
473
  }, {
535
474
  F: __dxlog_file2,
536
- L: 270,
475
+ L: 280,
537
476
  S: this,
538
477
  C: (f, a) => f(...a)
539
478
  });
@@ -548,7 +487,7 @@ var PluginManager = class {
548
487
  id
549
488
  }, {
550
489
  F: __dxlog_file2,
551
- L: 279,
490
+ L: 290,
552
491
  S: this,
553
492
  C: (f, a) => f(...a)
554
493
  });
@@ -564,7 +503,7 @@ var PluginManager = class {
564
503
  id: module.id
565
504
  }, {
566
505
  F: __dxlog_file2,
567
- L: 289,
506
+ L: 300,
568
507
  S: this,
569
508
  C: (f, a) => f(...a)
570
509
  });
@@ -579,7 +518,7 @@ var PluginManager = class {
579
518
  id
580
519
  }, {
581
520
  F: __dxlog_file2,
582
- L: 298,
521
+ L: 310,
583
522
  S: this,
584
523
  C: (f, a) => f(...a)
585
524
  });
@@ -607,13 +546,13 @@ var PluginManager = class {
607
546
  _setPendingResetByModule(module) {
608
547
  return untracked(() => {
609
548
  const activationEvents = getEvents(module.activatesOn).map(eventKey).filter((key) => this._state.eventsFired.includes(key));
610
- const pendingReset = Array.from(new Set(activationEvents)).filter((event) => !this._state.pendingReset.includes(event));
549
+ const pendingReset = Array.fromIterable(new Set(activationEvents)).filter((event) => !this._state.pendingReset.includes(event));
611
550
  if (pendingReset.length > 0) {
612
551
  log2("pending reset", {
613
552
  events: pendingReset
614
553
  }, {
615
554
  F: __dxlog_file2,
616
- L: 336,
555
+ L: 348,
617
556
  S: this,
618
557
  C: (f, a) => f(...a)
619
558
  });
@@ -625,35 +564,40 @@ var PluginManager = class {
625
564
  * @internal
626
565
  */
627
566
  // TODO(wittjosiah): Improve error typing.
628
- _activate(event) {
567
+ _activate(event, params) {
629
568
  return Effect2.gen(this, function* () {
630
569
  const key = typeof event === "string" ? event : eventKey(event);
631
570
  log2("activating", {
632
- key
571
+ key,
572
+ ...params
633
573
  }, {
634
574
  F: __dxlog_file2,
635
- L: 349,
575
+ L: 364,
636
576
  S: this,
637
577
  C: (f, a) => f(...a)
638
578
  });
579
+ yield* Ref.update(this._activatingEvents, (activating) => Array.append(activating, key));
639
580
  const pendingIndex = this._state.pendingReset.findIndex((event2) => event2 === key);
640
581
  if (pendingIndex !== -1) {
641
582
  this._state.pendingReset.splice(pendingIndex, 1);
642
583
  }
584
+ const activatingEvents = yield* this._activatingEvents;
585
+ const activatingModules = yield* this._activatingModules;
643
586
  const modules = this._getInactiveModulesByEvent(key).filter((module) => {
644
587
  const allOf2 = isAllOf(module.activatesOn);
645
588
  if (!allOf2) {
646
589
  return true;
647
590
  }
648
591
  const events = module.activatesOn.events.filter((event2) => eventKey(event2) !== key);
649
- return events.every((event2) => this._state.eventsFired.includes(eventKey(event2)));
592
+ return events.every((event2) => this._state.eventsFired.includes(eventKey(event2)) || activatingEvents.includes(eventKey(event2))) && !activatingModules.includes(module.id);
650
593
  });
594
+ yield* Ref.update(this._activatingModules, (activating) => Array.appendAll(activating, modules.map((module) => module.id)));
651
595
  if (modules.length === 0) {
652
596
  log2("no modules to activate", {
653
597
  key
654
598
  }, {
655
599
  F: __dxlog_file2,
656
- L: 365,
600
+ L: 395,
657
601
  S: this,
658
602
  C: (f, a) => f(...a)
659
603
  });
@@ -667,7 +611,7 @@ var PluginManager = class {
667
611
  modules: modules.map((module) => module.id)
668
612
  }, {
669
613
  F: __dxlog_file2,
670
- L: 372,
614
+ L: 402,
671
615
  S: this,
672
616
  C: (f, a) => f(...a)
673
617
  });
@@ -675,29 +619,34 @@ var PluginManager = class {
675
619
  event: key,
676
620
  state: "activating"
677
621
  });
678
- const getCapabilities = yield* Effect2.all(modules.map(({ activate }) => Effect2.tryPromise({
679
- try: async () => activate(this.context),
680
- catch: (error) => error
681
- })), {
622
+ yield* Function.pipe(modules, Array.flatMap((module) => module.activatesBefore ?? []), HashSet.fromIterable, HashSet.toValues, Array.filter((event2) => !activatingEvents.includes(eventKey(event2))), Array.map((event2) => this._activate(event2, {
623
+ before: key
624
+ })), Effect2.allWith({
682
625
  concurrency: "unbounded"
683
- });
684
- const result = yield* pipe(
685
- modules,
686
- A.zip(getCapabilities),
687
- A.map(([module, getCapabilities2]) => this._activateModule(module, getCapabilities2)),
688
- // TODO(wittjosiah): This currently can't be run in parallel.
689
- // Running this with concurrency causes races with `allOf` activation events.
690
- Effect2.all,
691
- Effect2.either
692
- );
693
- if (Either.isLeft(result)) {
626
+ }));
627
+ const getCapabilities = yield* Function.pipe(modules, Array.map((mod) => this._loadModule(mod)), Effect2.allWith({
628
+ concurrency: "unbounded"
629
+ }), Effect2.catchAll((error) => {
694
630
  this.activation.emit({
695
631
  event: key,
696
632
  state: "error",
697
- error: result.left
633
+ error
698
634
  });
699
- yield* Effect2.fail(result.left);
700
- }
635
+ return Effect2.fail(error);
636
+ }));
637
+ yield* Function.pipe(
638
+ modules,
639
+ Array.zip(getCapabilities),
640
+ Array.map(([module, capabilities]) => this._contributeCapabilities(module, capabilities)),
641
+ Effect2.all
642
+ );
643
+ yield* Function.pipe(modules, Array.flatMap((module) => module.activatesAfter ?? []), HashSet.fromIterable, HashSet.toValues, Array.filter((event2) => !activatingEvents.includes(eventKey(event2))), Array.map((event2) => this._activate(event2, {
644
+ after: key
645
+ })), Effect2.allWith({
646
+ concurrency: "unbounded"
647
+ }));
648
+ yield* Ref.update(this._activatingEvents, (activating) => Array.filter(activating, (event2) => event2 !== key));
649
+ yield* Ref.update(this._activatingModules, (activating) => Array.filter(activating, (module) => !modules.map((module2) => module2.id).includes(module)));
701
650
  if (!this._state.eventsFired.includes(key)) {
702
651
  this._state.eventsFired.push(key);
703
652
  }
@@ -709,39 +658,76 @@ var PluginManager = class {
709
658
  key
710
659
  }, {
711
660
  F: __dxlog_file2,
712
- L: 406,
661
+ L: 458,
713
662
  S: this,
714
663
  C: (f, a) => f(...a)
715
664
  });
716
665
  return true;
717
666
  });
718
667
  }
719
- _activateModule(module, getCapabilities) {
668
+ // Memoized with _moduleMemoMap
669
+ _loadModule = (mod) => Effect2.tryPromise({
670
+ try: async () => {
671
+ const entry = this._moduleMemoMap.get(mod.id);
672
+ if (entry) {
673
+ return entry;
674
+ }
675
+ const promise2 = (async () => {
676
+ const start = performance.now();
677
+ let failed = false;
678
+ try {
679
+ log2("loading module", {
680
+ module: mod.id
681
+ }, {
682
+ F: __dxlog_file2,
683
+ L: 477,
684
+ S: this,
685
+ C: (f, a) => f(...a)
686
+ });
687
+ let activationResult = await mod.activate(this.context);
688
+ if (typeof activationResult === "function") {
689
+ activationResult = await activationResult();
690
+ }
691
+ return Array.isArray(activationResult) ? activationResult : [
692
+ activationResult
693
+ ];
694
+ } catch (error) {
695
+ failed = true;
696
+ throw error;
697
+ } finally {
698
+ performance.measure("activate-module", {
699
+ start,
700
+ end: performance.now(),
701
+ detail: {
702
+ module: mod.id
703
+ }
704
+ });
705
+ log2("loaded module", {
706
+ module: mod.id,
707
+ elapsed: performance.now() - start,
708
+ failed
709
+ }, {
710
+ F: __dxlog_file2,
711
+ L: 495,
712
+ S: this,
713
+ C: (f, a) => f(...a)
714
+ });
715
+ }
716
+ })();
717
+ this._moduleMemoMap.set(mod.id, promise2);
718
+ return promise2;
719
+ },
720
+ catch: (error) => error
721
+ }).pipe(Effect2.withSpan("PluginManager._loadModule"), together(Effect2.sleep(Duration.seconds(10)).pipe(Effect2.andThen(Effect2.sync(() => log2.warn(`module is taking a long time to activate`, {
722
+ module: mod.id
723
+ }, {
724
+ F: __dxlog_file2,
725
+ L: 506,
726
+ S: this,
727
+ C: (f, a) => f(...a)
728
+ }))))));
729
+ _contributeCapabilities(module, capabilities) {
720
730
  return Effect2.gen(this, function* () {
721
- yield* Effect2.all(module.activatesBefore?.map((event) => this._activate(event)) ?? [], {
722
- concurrency: "unbounded"
723
- });
724
- log2("activating module...", {
725
- module: module.id
726
- }, {
727
- F: __dxlog_file2,
728
- L: 421,
729
- S: this,
730
- C: (f, a) => f(...a)
731
- });
732
- const maybeCapabilities = typeof getCapabilities === "function" ? getCapabilities() : getCapabilities;
733
- const resolvedCapabilities = yield* Match.value(maybeCapabilities).pipe(
734
- // TODO(wittjosiah): Activate with an effect?
735
- // Match.when(Effect.isEffect, (effect) => effect),
736
- Match.when(isPromise, (promise) => Effect2.tryPromise({
737
- try: () => promise,
738
- catch: (error) => error
739
- })),
740
- Match.orElse((program) => Effect2.succeed(program))
741
- );
742
- const capabilities = Match.value(resolvedCapabilities).pipe(Match.when(Array.isArray, (array) => array), Match.orElse((value) => [
743
- value
744
- ]));
745
731
  capabilities.forEach((capability) => {
746
732
  this.context.contributeCapability({
747
733
  module: module.id,
@@ -750,17 +736,6 @@ var PluginManager = class {
750
736
  });
751
737
  this._state.active.push(module.id);
752
738
  this._capabilities.set(module.id, capabilities);
753
- log2("activated module", {
754
- module: module.id
755
- }, {
756
- F: __dxlog_file2,
757
- L: 444,
758
- S: this,
759
- C: (f, a) => f(...a)
760
- });
761
- yield* Effect2.all(module.activatesAfter?.map((event) => this._activate(event)) ?? [], {
762
- concurrency: "unbounded"
763
- });
764
739
  });
765
740
  }
766
741
  _deactivate(id) {
@@ -783,17 +758,18 @@ var PluginManager = class {
783
758
  id
784
759
  }, {
785
760
  F: __dxlog_file2,
786
- L: 471,
761
+ L: 540,
787
762
  S: this,
788
763
  C: (f, a) => f(...a)
789
764
  });
765
+ this._moduleMemoMap.delete(id);
790
766
  const capabilities = this._capabilities.get(id);
791
767
  if (capabilities) {
792
768
  for (const capability of capabilities) {
793
769
  this.context.removeCapability(capability.interface, capability.implementation);
794
770
  const program = capability.deactivate?.();
795
- yield* Match.value(program).pipe(Match.when(Effect2.isEffect, (effect) => effect), Match.when(isPromise, (promise) => Effect2.tryPromise({
796
- try: () => promise,
771
+ yield* Match.value(program).pipe(Match.when(Effect2.isEffect, (effect) => effect), Match.when(isPromise, (promise2) => Effect2.tryPromise({
772
+ try: () => promise2,
797
773
  catch: (error) => error
798
774
  })), Match.orElse((program2) => Effect2.succeed(program2)));
799
775
  }
@@ -807,7 +783,7 @@ var PluginManager = class {
807
783
  id
808
784
  }, {
809
785
  F: __dxlog_file2,
810
- L: 497,
786
+ L: 567,
811
787
  S: this,
812
788
  C: (f, a) => f(...a)
813
789
  });
@@ -821,7 +797,7 @@ var PluginManager = class {
821
797
  key
822
798
  }, {
823
799
  F: __dxlog_file2,
824
- L: 505,
800
+ L: 575,
825
801
  S: this,
826
802
  C: (f, a) => f(...a)
827
803
  });
@@ -837,9 +813,20 @@ var PluginManager = class {
837
813
  });
838
814
  }
839
815
  };
816
+ var together = (togetherEffect) => (effect) => Effect2.gen(function* () {
817
+ const togetherFiber = yield* Effect2.fork(togetherEffect);
818
+ const result = yield* effect;
819
+ yield* Fiber.interrupt(togetherFiber);
820
+ return result;
821
+ });
840
822
 
841
823
  // src/core/plugin.ts
842
824
  var PluginModule = class {
825
+ id;
826
+ activatesOn;
827
+ activatesBefore;
828
+ activatesAfter;
829
+ activate;
843
830
  constructor(options) {
844
831
  this.id = options.id;
845
832
  this.activatesOn = options.activatesOn;
@@ -850,20 +837,27 @@ var PluginModule = class {
850
837
  };
851
838
  var defineModule = (options) => new PluginModule(options);
852
839
  var Plugin = class {
853
- constructor(meta, modules) {
854
- this.meta = meta;
840
+ meta;
841
+ modules;
842
+ constructor(meta2, modules) {
843
+ this.meta = meta2;
855
844
  this.modules = modules;
856
845
  }
857
846
  };
858
- var definePlugin = (meta, modules) => {
859
- return new Plugin(meta, modules);
847
+ var definePlugin = (meta2, provider) => {
848
+ const factory = (args) => {
849
+ return new Plugin(meta2, provider(args));
850
+ };
851
+ return Object.assign(factory, {
852
+ meta: meta2
853
+ });
860
854
  };
861
855
 
862
856
  // src/common/capabilities.ts
863
857
  (function(Capabilities2) {
864
858
  Capabilities2.Null = defineCapability("dxos.org/app-framework/capability/null");
865
859
  Capabilities2.PluginManager = defineCapability("dxos.org/app-framework/capability/plugin-manager");
866
- Capabilities2.RxRegistry = defineCapability("dxos.org/app-framework/capability/rx-registry");
860
+ Capabilities2.AtomRegistry = defineCapability("dxos.org/app-framework/capability/atom-registry");
867
861
  Capabilities2.ReactContext = defineCapability("dxos.org/app-framework/capability/react-context");
868
862
  Capabilities2.ReactRoot = defineCapability("dxos.org/app-framework/capability/react-root");
869
863
  Capabilities2.ReactSurface = defineCapability("dxos.org/app-framework/common/react-surface");
@@ -877,8 +871,10 @@ var definePlugin = (meta, modules) => {
877
871
  Capabilities2.SettingsStore = defineCapability("dxos.org/app-framework/capability/settings-store");
878
872
  Capabilities2.Settings = defineCapability("dxos.org/app-framework/capability/settings");
879
873
  Capabilities2.Metadata = defineCapability("dxos.org/app-framework/capability/metadata");
880
- Capabilities2.Tools = defineCapability("dxos.org/app-framework/capability/tools");
881
- Capabilities2.ArtifactDefinition = defineCapability("dxos.org/app-framework/capability/artifact-definition");
874
+ Capabilities2.Toolkit = defineCapability("dxos.org/app-framework/capability/ai-toolkit");
875
+ Capabilities2.BlueprintDefinition = defineCapability("dxos.org/app-framework/capability/blueprint-definition");
876
+ Capabilities2.AiServiceLayer = defineCapability("dxos.org/app-framework/capability/ai-service-factory");
877
+ Capabilities2.AiModelResolver = defineCapability("dxos.org/app-framework/capability/ai-model-resolver");
882
878
  Capabilities2.Functions = defineCapability("dxos.org/app-framework/capability/functions");
883
879
  Capabilities2.FileUploader = defineCapability("dxos.org/app-framework/capability/file-uploader");
884
880
  Capabilities2.AnchorSort = defineCapability("dxos.org/app-framework/capability/anchor-sort");
@@ -886,22 +882,19 @@ var definePlugin = (meta, modules) => {
886
882
  var Capabilities;
887
883
 
888
884
  // src/common/collaboration.ts
889
- import { Schema as Schema3 } from "effect";
890
- import { Expando, Ref } from "@dxos/echo-schema";
885
+ import * as Schema from "effect/Schema";
886
+ import { ContentBlock } from "@dxos/types";
891
887
  (function(CollaborationActions2) {
892
- class InsertContent extends Schema3.TaggedClass()("assistant/intent-content", {
893
- input: Schema3.Struct({
894
- target: Expando,
895
- object: Ref(Expando),
896
- at: Schema3.optional(Schema3.String),
897
- label: Schema3.String.pipe(Schema3.optional)
898
- }).annotations({
899
- description: "Enables plugins to inject content blocks or references into a related entity."
888
+ class AcceptProposal extends Schema.TaggedClass()("collaboration/accept-proposal", {
889
+ input: Schema.Struct({
890
+ subject: Schema.Any,
891
+ anchor: Schema.String,
892
+ proposal: ContentBlock.Proposal
900
893
  }),
901
- output: Schema3.Void
894
+ output: Schema.Void
902
895
  }) {
903
896
  }
904
- CollaborationActions2.InsertContent = InsertContent;
897
+ CollaborationActions2.AcceptProposal = AcceptProposal;
905
898
  })(CollaborationActions || (CollaborationActions = {}));
906
899
  var CollaborationActions;
907
900
 
@@ -924,7 +917,7 @@ var CollaborationActions;
924
917
  var Events;
925
918
 
926
919
  // src/common/file.ts
927
- import { Schema as Schema4 } from "effect";
920
+ import * as Schema2 from "effect/Schema";
928
921
  var defaultFileTypes = {
929
922
  images: [
930
923
  "png",
@@ -944,23 +937,120 @@ var defaultFileTypes = {
944
937
  "md"
945
938
  ]
946
939
  };
947
- var FileInfoSchema = Schema4.Struct({
948
- name: Schema4.String,
949
- type: Schema4.String,
950
- url: Schema4.optional(Schema4.String),
951
- cid: Schema4.optional(Schema4.String)
940
+ var FileInfoSchema = Schema2.Struct({
941
+ name: Schema2.String,
942
+ type: Schema2.String,
943
+ url: Schema2.optional(Schema2.String),
944
+ cid: Schema2.optional(Schema2.String)
952
945
  });
953
946
 
954
947
  // src/common/layout.ts
955
- import { Schema as Schema5 } from "effect";
948
+ import * as Schema5 from "effect/Schema";
956
949
 
957
- // src/plugin-intent/IntentPlugin.ts
958
- var IntentPlugin = () => definePlugin({
959
- id: INTENT_PLUGIN,
950
+ // src/plugin-intent/actions.ts
951
+ import * as Schema4 from "effect/Schema";
952
+
953
+ // src/plugin-intent/intent.ts
954
+ import * as Schema3 from "effect/Schema";
955
+ var createIntent = (schema, data = {}, params = {}) => {
956
+ const _ = Schema3.validateSync(schema.fields.input)(data);
957
+ const intent = {
958
+ ...params,
959
+ _schema: schema,
960
+ id: schema._tag,
961
+ data
962
+ };
963
+ return {
964
+ first: intent,
965
+ last: intent,
966
+ all: [
967
+ intent
968
+ ]
969
+ };
970
+ };
971
+ var chain = (schema, data = {}, params = {}) => (intent) => {
972
+ const intents = "all" in intent ? intent.all : [
973
+ intent
974
+ ];
975
+ const first = intents[0];
976
+ const last = {
977
+ ...params,
978
+ _schema: schema,
979
+ id: schema._tag,
980
+ data
981
+ };
982
+ return {
983
+ first,
984
+ last,
985
+ all: [
986
+ ...intents,
987
+ last
988
+ ]
989
+ };
990
+ };
991
+ var Label = Schema3.Union(Schema3.String, Schema3.mutable(Schema3.Tuple(Schema3.String, Schema3.mutable(Schema3.Struct({
992
+ ns: Schema3.String,
993
+ count: Schema3.optional(Schema3.Number),
994
+ defaultValue: Schema3.optional(Schema3.String)
995
+ })))));
996
+
997
+ // src/plugin-intent/meta.ts
998
+ var meta = {
999
+ id: "dxos.org/plugin/intent",
960
1000
  name: "Intent"
961
- }, [
1001
+ };
1002
+
1003
+ // src/plugin-intent/actions.ts
1004
+ (function(IntentAction2) {
1005
+ class Track extends Schema4.TaggedClass()(`${meta.id}/action/track`, {
1006
+ input: Schema4.Struct({
1007
+ intents: Schema4.Array(Schema4.String),
1008
+ error: Schema4.optional(Schema4.String)
1009
+ }),
1010
+ output: Schema4.Void
1011
+ }) {
1012
+ }
1013
+ IntentAction2.Track = Track;
1014
+ class ShowUndo extends Schema4.TaggedClass()(`${meta.id}/action/show-undo`, {
1015
+ input: Schema4.Struct({
1016
+ message: Label
1017
+ }),
1018
+ output: Schema4.Void
1019
+ }) {
1020
+ }
1021
+ IntentAction2.ShowUndo = ShowUndo;
1022
+ })(IntentAction || (IntentAction = {}));
1023
+ var IntentAction;
1024
+
1025
+ // src/plugin-intent/errors.ts
1026
+ var BaseError = class extends Error {
1027
+ code;
1028
+ context;
1029
+ constructor(code, message, context) {
1030
+ super(message ?? code, {
1031
+ cause: context
1032
+ }), this.code = code, this.context = context;
1033
+ this.name = code;
1034
+ Object.setPrototypeOf(this, new.target.prototype);
1035
+ }
1036
+ };
1037
+ var NoResolversError = class extends BaseError {
1038
+ constructor(action) {
1039
+ super("NO_RESOLVERS", `No resolvers were found for the action: ${action}`, {
1040
+ action
1041
+ });
1042
+ }
1043
+ };
1044
+ var CycleDetectedError = class extends BaseError {
1045
+ constructor(context) {
1046
+ super("CYCLE_DETECTED", "Intent execution limit exceeded. This is likely due to an infinite loop within intent resolvers.", context);
1047
+ }
1048
+ };
1049
+
1050
+ // src/plugin-intent/IntentPlugin.ts
1051
+ var IntentPlugin = definePlugin(meta, () => [
962
1052
  defineModule({
963
- id: `${INTENT_PLUGIN}/module/dispatcher`,
1053
+ id: `${meta.id}/module/dispatcher`,
964
1054
  // TODO(wittjosiah): This will mean that startup needs to be reset when intents are added or removed.
965
1055
  // This is fine for now because it's how it worked prior to capabilities api anyways.
966
1056
  // In the future, the intent dispatcher should be able to be reset without resetting the entire app.
@@ -968,15 +1058,14 @@ var IntentPlugin = () => definePlugin({
968
1058
  activatesAfter: [
969
1059
  Events.DispatcherReady
970
1060
  ],
971
- activate: lazy(() => import("./intent-dispatcher-6CYNGPSW.mjs"))
1061
+ activate: lazy(() => import("./intent-dispatcher-MGOJ3CHD.mjs"))
972
1062
  })
973
1063
  ]);
974
1064
 
975
1065
  // src/common/layout.ts
976
1066
  var LAYOUT_PLUGIN = "dxos.org/plugin/layout";
977
- var LAYOUT_ACTION = `${LAYOUT_PLUGIN}/action`;
978
1067
  (function(LayoutAction2) {
979
- LayoutAction2.UPDATE_LAYOUT = `${LAYOUT_ACTION}/update-layout`;
1068
+ LayoutAction2.UPDATE_LAYOUT = `${LAYOUT_PLUGIN}/action/update-layout`;
980
1069
  class UpdateLayout extends Schema5.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
981
1070
  input: Schema5.Struct({
982
1071
  part: Schema5.String.annotations({
@@ -1313,7 +1402,7 @@ var LayoutAction;
1313
1402
  var createSurface = (definition) => definition;
1314
1403
 
1315
1404
  // src/common/translations.ts
1316
- import { Schema as Schema6 } from "effect";
1405
+ import * as Schema6 from "effect/Schema";
1317
1406
  var ResourceKey = Schema6.Union(Schema6.String, Schema6.Record({
1318
1407
  key: Schema6.String,
1319
1408
  value: Schema6.Any
@@ -1338,7 +1427,7 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1338
1427
  const handleIntent = (intent) => Effect3.gen(function* () {
1339
1428
  const candidates = getResolvers().filter((resolver) => resolver.intent._tag === intent.id).filter((resolver) => !resolver.filter || resolver.filter(intent.data)).toSorted(byPosition);
1340
1429
  if (candidates.length === 0) {
1341
- yield* Effect3.fail(new NoResolversError(intent.id));
1430
+ return yield* Effect3.fail(new NoResolversError(intent.id));
1342
1431
  }
1343
1432
  const effect = candidates[0].resolve(intent.data, intent.undo ?? false);
1344
1433
  const result = Effect3.isEffect(effect) ? yield* effect : yield* Effect3.promise(async () => effect);
@@ -1348,12 +1437,29 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1348
1437
  };
1349
1438
  });
1350
1439
  const dispatch = (intentChain, depth = 0) => {
1440
+ log3("dispatch", {
1441
+ intentChain: intentChain.all.map((i) => i.id),
1442
+ depth
1443
+ }, {
1444
+ F: __dxlog_file3,
1445
+ L: 212,
1446
+ S: void 0,
1447
+ C: (f, a) => f(...a)
1448
+ });
1351
1449
  return Effect3.gen(function* () {
1352
1450
  if (depth > executionLimit) {
1353
- yield* Effect3.fail(new CycleDetectedError());
1451
+ return yield* Effect3.fail(new CycleDetectedError());
1354
1452
  }
1355
1453
  const resultsRef = yield* Ref2.make([]);
1356
1454
  for (const intent of intentChain.all) {
1455
+ log3("processing", {
1456
+ intent
1457
+ }, {
1458
+ F: __dxlog_file3,
1459
+ L: 220,
1460
+ S: this,
1461
+ C: (f, a) => f(...a)
1462
+ });
1357
1463
  const { data: prev } = (yield* resultsRef.get)[0] ?? {};
1358
1464
  const result2 = yield* handleIntent({
1359
1465
  ...intent,
@@ -1362,6 +1468,15 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1362
1468
  ...prev
1363
1469
  }
1364
1470
  });
1471
+ log3("ok", {
1472
+ intent: intent.id,
1473
+ result: result2
1474
+ }, {
1475
+ F: __dxlog_file3,
1476
+ L: 223,
1477
+ S: this,
1478
+ C: (f, a) => f(...a)
1479
+ });
1365
1480
  yield* Ref2.update(resultsRef, (results2) => [
1366
1481
  result2,
1367
1482
  ...results2
@@ -1372,7 +1487,16 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1372
1487
  }
1373
1488
  }
1374
1489
  if (result2.error) {
1375
- yield* Effect3.fail(result2.error);
1490
+ log3.error("failed", {
1491
+ intent: intent.id,
1492
+ error: result2.error
1493
+ }, {
1494
+ F: __dxlog_file3,
1495
+ L: 240,
1496
+ S: this,
1497
+ C: (f, a) => f(...a)
1498
+ });
1499
+ return yield* Effect3.fail(result2.error);
1376
1500
  }
1377
1501
  }
1378
1502
  const results = yield* resultsRef.get;
@@ -1388,10 +1512,19 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1388
1512
  return next;
1389
1513
  });
1390
1514
  if (result.undoable && isUndoable(results)) {
1391
- yield* pipe2(dispatch(createIntent(IntentAction.ShowUndo, {
1515
+ yield* Function2.pipe(dispatch(createIntent(IntentAction.ShowUndo, {
1392
1516
  message: result.undoable.message
1393
1517
  })), Effect3.catchSome((err) => err instanceof NoResolversError ? Option.some(Effect3.succeed(void 0)) : Option.none()));
1394
1518
  }
1519
+ log3("done", {
1520
+ intent: intentChain.all.map((i) => i.id),
1521
+ result: result.data
1522
+ }, {
1523
+ F: __dxlog_file3,
1524
+ L: 270,
1525
+ S: this,
1526
+ C: (f, a) => f(...a)
1527
+ });
1395
1528
  return result.data;
1396
1529
  });
1397
1530
  };
@@ -1401,7 +1534,7 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1401
1534
  })).catch((error) => {
1402
1535
  log3.catch(error, void 0, {
1403
1536
  F: __dxlog_file3,
1404
- L: 270,
1537
+ L: 279,
1405
1538
  S: void 0,
1406
1539
  C: (f, a) => f(...a)
1407
1540
  });
@@ -1416,7 +1549,7 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1416
1549
  const last = history.findLastIndex(isUndoable);
1417
1550
  const result = last !== -1 ? history[last] : void 0;
1418
1551
  if (result) {
1419
- const all = result.map(({ _intent, undoable }) => {
1552
+ const all2 = result.map(({ _intent, undoable }) => {
1420
1553
  const data = _intent.data;
1421
1554
  const undoData = undoable?.data ?? {};
1422
1555
  return {
@@ -1429,9 +1562,9 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1429
1562
  };
1430
1563
  });
1431
1564
  const intent = {
1432
- first: all[0],
1433
- last: all.at(-1),
1434
- all
1565
+ first: all2[0],
1566
+ last: all2.at(-1),
1567
+ all: all2
1435
1568
  };
1436
1569
  yield* Ref2.update(historyRef, (h) => h.filter((_, index) => index !== last));
1437
1570
  return yield* dispatch(intent);
@@ -1454,7 +1587,7 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1454
1587
  };
1455
1588
  var defaultEffect = () => Effect3.fail(new Error("Intent runtime not ready"));
1456
1589
  var defaultPromise = () => Effect3.runPromise(defaultEffect());
1457
- var intent_dispatcher_default = (context) => {
1590
+ var intent_dispatcher_default = ((context) => {
1458
1591
  const state = live2({
1459
1592
  dispatch: defaultEffect,
1460
1593
  dispatchPromise: defaultPromise,
@@ -1476,7 +1609,7 @@ var intent_dispatcher_default = (context) => {
1476
1609
  state.undo = undo;
1477
1610
  state.undoPromise = undoPromise;
1478
1611
  return contributes(Capabilities.IntentDispatcher, state);
1479
- };
1612
+ });
1480
1613
 
1481
1614
  export {
1482
1615
  defineCapability,
@@ -1503,19 +1636,18 @@ export {
1503
1636
  createIntent,
1504
1637
  chain,
1505
1638
  Label,
1506
- INTENT_PLUGIN,
1507
- INTENT_ACTION,
1508
1639
  IntentAction,
1640
+ BaseError,
1641
+ NoResolversError,
1642
+ CycleDetectedError,
1509
1643
  createResolver,
1510
1644
  createDispatcher,
1511
1645
  intent_dispatcher_default,
1512
1646
  IntentPlugin,
1513
- LAYOUT_PLUGIN,
1514
- LAYOUT_ACTION,
1515
1647
  LayoutAction,
1516
1648
  createSurface,
1517
1649
  ResourceKey,
1518
1650
  ResourceLanguage,
1519
1651
  Resource
1520
1652
  };
1521
- //# sourceMappingURL=chunk-ZEZ4FVEU.mjs.map
1653
+ //# sourceMappingURL=chunk-XJZGUJ3H.mjs.map