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

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 (199) 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-XH4OYQLC.mjs} +25 -25
  6. package/dist/lib/browser/app-graph-builder-XH4OYQLC.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-FMN65HSW.mjs → chunk-6V54SRFL.mjs} +388 -269
  8. package/dist/lib/browser/chunk-6V54SRFL.mjs.map +7 -0
  9. package/dist/lib/browser/{chunk-ORWHM7CO.mjs → chunk-RGKMLI6U.mjs} +10 -7
  10. package/dist/lib/browser/chunk-RGKMLI6U.mjs.map +7 -0
  11. package/dist/lib/browser/{chunk-FO2PH7M3.mjs → chunk-ZZVFNUHZ.mjs} +189 -137
  12. package/dist/lib/browser/chunk-ZZVFNUHZ.mjs.map +7 -0
  13. package/dist/lib/browser/index.mjs +20 -28
  14. package/dist/lib/browser/index.mjs.map +3 -3
  15. package/dist/lib/browser/{intent-dispatcher-LSYQZSEB.mjs → intent-dispatcher-VFMJVO2M.mjs} +2 -2
  16. package/dist/lib/browser/{intent-resolver-ZTNOSO3A.mjs → intent-resolver-ICAPD4JL.mjs} +5 -5
  17. package/dist/lib/browser/intent-resolver-ICAPD4JL.mjs.map +7 -0
  18. package/dist/lib/browser/meta.json +1 -1
  19. package/dist/lib/browser/{store-KML2R4IE.mjs → store-7ZGMHOGB.mjs} +4 -4
  20. package/dist/lib/browser/{store-KML2R4IE.mjs.map → store-7ZGMHOGB.mjs.map} +2 -2
  21. package/dist/lib/browser/testing/index.mjs +14 -19
  22. package/dist/lib/browser/testing/index.mjs.map +3 -3
  23. package/dist/lib/browser/worker.mjs +7 -9
  24. package/dist/lib/node-esm/{app-graph-builder-SAOWGJDK.mjs → app-graph-builder-C7H22SOL.mjs} +25 -25
  25. package/dist/lib/node-esm/app-graph-builder-C7H22SOL.mjs.map +7 -0
  26. package/dist/lib/node-esm/{chunk-73HGSHKE.mjs → chunk-AXSZKZFD.mjs} +189 -137
  27. package/dist/lib/node-esm/chunk-AXSZKZFD.mjs.map +7 -0
  28. package/dist/lib/node-esm/{chunk-UMZQERLE.mjs → chunk-LKPMRTRR.mjs} +10 -7
  29. package/dist/lib/node-esm/chunk-LKPMRTRR.mjs.map +7 -0
  30. package/dist/lib/node-esm/{chunk-ZEZ4FVEU.mjs → chunk-SOVTUUAY.mjs} +388 -269
  31. package/dist/lib/node-esm/chunk-SOVTUUAY.mjs.map +7 -0
  32. package/dist/lib/node-esm/index.mjs +20 -28
  33. package/dist/lib/node-esm/index.mjs.map +3 -3
  34. package/dist/lib/node-esm/{intent-dispatcher-6CYNGPSW.mjs → intent-dispatcher-SAPOKSLZ.mjs} +2 -2
  35. package/dist/lib/node-esm/{intent-resolver-W7Z7WFFM.mjs → intent-resolver-CRNJ6BMD.mjs} +5 -5
  36. package/dist/lib/node-esm/intent-resolver-CRNJ6BMD.mjs.map +7 -0
  37. package/dist/lib/node-esm/meta.json +1 -1
  38. package/dist/lib/node-esm/{store-QEXGXLWZ.mjs → store-H4F4RMYD.mjs} +4 -4
  39. package/dist/lib/node-esm/{store-QEXGXLWZ.mjs.map → store-H4F4RMYD.mjs.map} +2 -2
  40. package/dist/lib/node-esm/testing/index.mjs +14 -19
  41. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  42. package/dist/lib/node-esm/worker.mjs +7 -9
  43. package/dist/types/src/common/capabilities.d.ts +82 -8
  44. package/dist/types/src/common/capabilities.d.ts.map +1 -1
  45. package/dist/types/src/common/collaboration.d.ts +9 -8
  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/index.d.ts +1 -1
  49. package/dist/types/src/common/index.d.ts.map +1 -1
  50. package/dist/types/src/common/layout.d.ts +0 -2
  51. package/dist/types/src/common/layout.d.ts.map +1 -1
  52. package/dist/types/src/common/surface.d.ts +7 -13
  53. package/dist/types/src/common/surface.d.ts.map +1 -1
  54. package/dist/types/src/components/App.d.ts +10 -0
  55. package/dist/types/src/components/App.d.ts.map +1 -0
  56. package/dist/types/src/components/App.stories.d.ts +14 -0
  57. package/dist/types/src/components/App.stories.d.ts.map +1 -0
  58. package/dist/types/src/components/DefaultFallback.d.ts +8 -0
  59. package/dist/types/src/components/DefaultFallback.d.ts.map +1 -0
  60. package/dist/types/src/components/index.d.ts +2 -0
  61. package/dist/types/src/components/index.d.ts.map +1 -0
  62. package/dist/types/src/{App.d.ts → components/useApp.d.ts} +7 -6
  63. package/dist/types/src/components/useApp.d.ts.map +1 -0
  64. package/dist/types/src/components/useLoading.d.ts +19 -0
  65. package/dist/types/src/components/useLoading.d.ts.map +1 -0
  66. package/dist/types/src/core/capabilities.d.ts +4 -1
  67. package/dist/types/src/core/capabilities.d.ts.map +1 -1
  68. package/dist/types/src/core/manager.d.ts +6 -2
  69. package/dist/types/src/core/manager.d.ts.map +1 -1
  70. package/dist/types/src/core/plugin.d.ts +4 -1
  71. package/dist/types/src/core/plugin.d.ts.map +1 -1
  72. package/dist/types/src/index.d.ts +1 -1
  73. package/dist/types/src/index.d.ts.map +1 -1
  74. package/dist/types/src/playground/debug/Debug.d.ts +1 -1
  75. package/dist/types/src/playground/debug/plugin.d.ts +1 -1
  76. package/dist/types/src/playground/debug/plugin.d.ts.map +1 -1
  77. package/dist/types/src/playground/generator/Main.d.ts +1 -1
  78. package/dist/types/src/playground/generator/Toolbar.d.ts +1 -1
  79. package/dist/types/src/playground/generator/Toolbar.d.ts.map +1 -1
  80. package/dist/types/src/playground/generator/generator.d.ts +1 -1
  81. package/dist/types/src/playground/generator/generator.d.ts.map +1 -1
  82. package/dist/types/src/playground/generator/plugin.d.ts +1 -1
  83. package/dist/types/src/playground/generator/plugin.d.ts.map +1 -1
  84. package/dist/types/src/playground/layout/Layout.d.ts +2 -2
  85. package/dist/types/src/playground/layout/plugin.d.ts +1 -1
  86. package/dist/types/src/playground/layout/plugin.d.ts.map +1 -1
  87. package/dist/types/src/playground/logger/Toolbar.d.ts +1 -1
  88. package/dist/types/src/playground/logger/Toolbar.d.ts.map +1 -1
  89. package/dist/types/src/playground/logger/plugin.d.ts +1 -1
  90. package/dist/types/src/playground/logger/plugin.d.ts.map +1 -1
  91. package/dist/types/src/playground/playground.stories.d.ts +5 -4
  92. package/dist/types/src/playground/playground.stories.d.ts.map +1 -1
  93. package/dist/types/src/plugin-intent/IntentPlugin.d.ts +1 -1
  94. package/dist/types/src/plugin-intent/IntentPlugin.d.ts.map +1 -1
  95. package/dist/types/src/plugin-intent/actions.d.ts +4 -6
  96. package/dist/types/src/plugin-intent/actions.d.ts.map +1 -1
  97. package/dist/types/src/plugin-intent/errors.d.ts.map +1 -1
  98. package/dist/types/src/plugin-intent/index.d.ts +1 -0
  99. package/dist/types/src/plugin-intent/index.d.ts.map +1 -1
  100. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts +3 -3
  101. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts.map +1 -1
  102. package/dist/types/src/plugin-intent/meta.d.ts +3 -0
  103. package/dist/types/src/plugin-intent/meta.d.ts.map +1 -0
  104. package/dist/types/src/plugin-settings/SettingsPlugin.d.ts +1 -1
  105. package/dist/types/src/plugin-settings/SettingsPlugin.d.ts.map +1 -1
  106. package/dist/types/src/plugin-settings/actions.d.ts +4 -6
  107. package/dist/types/src/plugin-settings/actions.d.ts.map +1 -1
  108. package/dist/types/src/plugin-settings/app-graph-builder.d.ts +1 -1
  109. package/dist/types/src/plugin-settings/app-graph-builder.d.ts.map +1 -1
  110. package/dist/types/src/plugin-settings/intent-resolver.d.ts +1 -1
  111. package/dist/types/src/plugin-settings/intent-resolver.d.ts.map +1 -1
  112. package/dist/types/src/plugin-settings/meta.d.ts +3 -0
  113. package/dist/types/src/plugin-settings/meta.d.ts.map +1 -0
  114. package/dist/types/src/plugin-settings/store.d.ts +1 -1
  115. package/dist/types/src/plugin-settings/store.d.ts.map +1 -1
  116. package/dist/types/src/plugin-settings/translations.d.ts +2 -1
  117. package/dist/types/src/plugin-settings/translations.d.ts.map +1 -1
  118. package/dist/types/src/react/ErrorBoundary.d.ts +13 -14
  119. package/dist/types/src/react/ErrorBoundary.d.ts.map +1 -1
  120. package/dist/types/src/react/IntentContext.d.ts.map +1 -1
  121. package/dist/types/src/react/Surface.d.ts +2 -2
  122. package/dist/types/src/react/Surface.d.ts.map +1 -1
  123. package/dist/types/src/react/Surface.stories.d.ts +6 -5
  124. package/dist/types/src/react/Surface.stories.d.ts.map +1 -1
  125. package/dist/types/src/react/common.d.ts.map +1 -1
  126. package/dist/types/src/react/useCapabilities.d.ts.map +1 -1
  127. package/dist/types/src/testing/withPluginManager.d.ts +6 -6
  128. package/dist/types/src/testing/withPluginManager.d.ts.map +1 -1
  129. package/dist/types/src/testing/withPluginManager.stories.d.ts +9 -3
  130. package/dist/types/src/testing/withPluginManager.stories.d.ts.map +1 -1
  131. package/dist/types/tsconfig.tsbuildinfo +1 -1
  132. package/moon.yml +4 -0
  133. package/package.json +37 -35
  134. package/src/common/capabilities.ts +106 -10
  135. package/src/common/collaboration.ts +5 -8
  136. package/src/common/events.ts +3 -1
  137. package/src/common/index.ts +1 -1
  138. package/src/common/layout.ts +2 -3
  139. package/src/common/surface.ts +15 -18
  140. package/src/components/App.stories.tsx +33 -0
  141. package/src/components/App.tsx +59 -0
  142. package/src/components/DefaultFallback.tsx +26 -0
  143. package/src/components/index.ts +5 -0
  144. package/src/{App.tsx → components/useApp.tsx} +24 -136
  145. package/src/components/useLoading.tsx +70 -0
  146. package/src/core/capabilities.test.ts +1 -1
  147. package/src/core/capabilities.ts +11 -6
  148. package/src/core/manager.test.ts +21 -20
  149. package/src/core/manager.ts +132 -54
  150. package/src/core/plugin.ts +8 -2
  151. package/src/helpers.test.ts +1 -1
  152. package/src/index.ts +1 -1
  153. package/src/playground/debug/Debug.tsx +1 -1
  154. package/src/playground/debug/plugin.ts +7 -8
  155. package/src/playground/generator/Toolbar.tsx +2 -1
  156. package/src/playground/generator/generator.ts +3 -3
  157. package/src/playground/generator/plugin.ts +12 -13
  158. package/src/playground/layout/plugin.ts +10 -9
  159. package/src/playground/logger/Toolbar.tsx +2 -1
  160. package/src/playground/logger/plugin.ts +30 -25
  161. package/src/playground/playground.stories.tsx +20 -16
  162. package/src/plugin-intent/IntentPlugin.ts +13 -13
  163. package/src/plugin-intent/actions.ts +3 -5
  164. package/src/plugin-intent/errors.ts +1 -0
  165. package/src/plugin-intent/index.ts +1 -0
  166. package/src/plugin-intent/intent-dispatcher.test.ts +1 -1
  167. package/src/plugin-intent/intent-dispatcher.ts +9 -8
  168. package/src/plugin-intent/meta.ts +10 -0
  169. package/src/plugin-settings/SettingsPlugin.ts +27 -28
  170. package/src/plugin-settings/actions.ts +8 -12
  171. package/src/plugin-settings/app-graph-builder.ts +14 -12
  172. package/src/plugin-settings/intent-resolver.ts +3 -2
  173. package/src/plugin-settings/meta.ts +10 -0
  174. package/src/plugin-settings/store.ts +1 -1
  175. package/src/plugin-settings/translations.ts +3 -3
  176. package/src/react/ErrorBoundary.tsx +24 -15
  177. package/src/react/IntentContext.tsx +3 -2
  178. package/src/react/Surface.stories.tsx +23 -18
  179. package/src/react/Surface.tsx +14 -5
  180. package/src/react/common.ts +2 -1
  181. package/src/react/useCapabilities.ts +2 -1
  182. package/src/testing/withPluginManager.stories.tsx +9 -5
  183. package/src/testing/withPluginManager.tsx +25 -29
  184. package/tsconfig.json +1 -8
  185. package/vitest.config.ts +8 -6
  186. package/.swc/plugins/v7_linux_x86_64_13.0.0/f45bdff002284d9e8f9ef3f0be909de12da36c049cbcf261ac78fc00abb09a2d +0 -0
  187. package/dist/lib/browser/app-graph-builder-LYF7EKNN.mjs.map +0 -7
  188. package/dist/lib/browser/chunk-FMN65HSW.mjs.map +0 -7
  189. package/dist/lib/browser/chunk-FO2PH7M3.mjs.map +0 -7
  190. package/dist/lib/browser/chunk-ORWHM7CO.mjs.map +0 -7
  191. package/dist/lib/browser/intent-resolver-ZTNOSO3A.mjs.map +0 -7
  192. package/dist/lib/node-esm/app-graph-builder-SAOWGJDK.mjs.map +0 -7
  193. package/dist/lib/node-esm/chunk-73HGSHKE.mjs.map +0 -7
  194. package/dist/lib/node-esm/chunk-UMZQERLE.mjs.map +0 -7
  195. package/dist/lib/node-esm/chunk-ZEZ4FVEU.mjs.map +0 -7
  196. package/dist/lib/node-esm/intent-resolver-W7Z7WFFM.mjs.map +0 -7
  197. package/dist/types/src/App.d.ts.map +0 -1
  198. /package/dist/lib/browser/{intent-dispatcher-LSYQZSEB.mjs.map → intent-dispatcher-VFMJVO2M.mjs.map} +0 -0
  199. /package/dist/lib/node-esm/{intent-dispatcher-6CYNGPSW.mjs.map → intent-dispatcher-SAPOKSLZ.mjs.map} +0 -0
@@ -1,111 +1,30 @@
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 { Effect as Effect3, Option, Ref as Ref2, pipe as pipe2 } from "effect";
5
5
  import { live as live2 } from "@dxos/live-object";
6
6
  import { log as log3 } from "@dxos/log";
7
7
  import { byPosition } from "@dxos/util";
8
8
 
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
9
  // src/core/capabilities.ts
104
10
  import { Rx } from "@effect-rx/rx-react";
105
11
  import { Effect } from "effect";
106
12
  import { Trigger } from "@dxos/async";
107
13
  import { invariant } from "@dxos/invariant";
108
14
  import { log } from "@dxos/log";
15
+ function _define_property(obj, key, value) {
16
+ if (key in obj) {
17
+ Object.defineProperty(obj, key, {
18
+ value,
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true
22
+ });
23
+ } else {
24
+ obj[key] = value;
25
+ }
26
+ return obj;
27
+ }
109
28
  var __dxlog_file = "/__w/dxos/dxos/packages/sdk/app-framework/src/core/capabilities.ts";
110
29
  var InterfaceDefTypeId = Symbol.for("InterfaceDefTypeId");
111
30
  var defineCapability = (identifier) => {
@@ -115,6 +34,8 @@ var defineCapability = (identifier) => {
115
34
  };
116
35
  var CapabilityImpl = class {
117
36
  constructor(moduleId, implementation) {
37
+ _define_property(this, "moduleId", void 0);
38
+ _define_property(this, "implementation", void 0);
118
39
  this.moduleId = moduleId;
119
40
  this.implementation = implementation;
120
41
  }
@@ -131,35 +52,6 @@ var lazy = (c) => async (props) => {
131
52
  return async () => getCapability(props);
132
53
  };
133
54
  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
- });
143
- });
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];
157
- });
158
- });
159
- this._registry = registry;
160
- this.activate = activate;
161
- this.reset = reset;
162
- }
163
55
  /**
164
56
  * @internal
165
57
  */
@@ -179,7 +71,7 @@ var PluginContext = class {
179
71
  count: current.length
180
72
  }, {
181
73
  F: __dxlog_file,
182
- L: 161,
74
+ L: 166,
183
75
  S: this,
184
76
  C: (f, a) => f(...a)
185
77
  });
@@ -200,7 +92,7 @@ var PluginContext = class {
200
92
  count: current.length
201
93
  }, {
202
94
  F: __dxlog_file,
203
- L: 180,
95
+ L: 185,
204
96
  S: this,
205
97
  C: (f, a) => f(...a)
206
98
  });
@@ -209,7 +101,7 @@ var PluginContext = class {
209
101
  id: interfaceDef.identifier
210
102
  }, {
211
103
  F: __dxlog_file,
212
- L: 182,
104
+ L: 187,
213
105
  S: this,
214
106
  C: (f, a) => f(...a)
215
107
  });
@@ -274,6 +166,38 @@ var PluginContext = class {
274
166
  async resetPromise(event) {
275
167
  return this.reset(event).pipe(Effect.runPromise);
276
168
  }
169
+ constructor({ registry, activate, reset }) {
170
+ _define_property(this, "_registry", void 0);
171
+ _define_property(this, "_capabilityImpls", Rx.family(() => {
172
+ return Rx.make([]).pipe(Rx.keepAlive);
173
+ }));
174
+ _define_property(this, "_capabilities", Rx.family((id) => {
175
+ return Rx.make((get) => {
176
+ const current = get(this._capabilityImpls(id));
177
+ return current.map((c) => c.implementation);
178
+ });
179
+ }));
180
+ _define_property(this, "_capability", Rx.family((id) => {
181
+ return Rx.make((get) => {
182
+ const current = get(this._capabilities(id));
183
+ invariant(current.length > 0, `No capability found for ${id}`, {
184
+ F: __dxlog_file,
185
+ L: 122,
186
+ S: this,
187
+ A: [
188
+ "current.length > 0",
189
+ "`No capability found for ${id}`"
190
+ ]
191
+ });
192
+ return current[0];
193
+ });
194
+ }));
195
+ _define_property(this, "activate", void 0);
196
+ _define_property(this, "reset", void 0);
197
+ this._registry = registry;
198
+ this.activate = activate;
199
+ this.reset = reset;
200
+ }
277
201
  };
278
202
 
279
203
  // src/core/events.ts
@@ -301,38 +225,28 @@ var getEvents = (events) => "type" in events ? events.events : [
301
225
  // src/core/manager.ts
302
226
  import { Registry } from "@effect-rx/rx-react";
303
227
  import { untracked } from "@preact/signals-core";
304
- import { Array as A, Effect as Effect2, Either, Match, pipe } from "effect";
228
+ import { Array, Duration, Effect as Effect2, Fiber, HashSet, Match, Ref, pipe } from "effect";
305
229
  import { Event } from "@dxos/async";
306
230
  import { live } from "@dxos/live-object";
307
231
  import { log as log2 } from "@dxos/log";
232
+ function _define_property2(obj, key, value) {
233
+ if (key in obj) {
234
+ Object.defineProperty(obj, key, {
235
+ value,
236
+ enumerable: true,
237
+ configurable: true,
238
+ writable: true
239
+ });
240
+ } else {
241
+ obj[key] = value;
242
+ }
243
+ return obj;
244
+ }
308
245
  var __dxlog_file2 = "/__w/dxos/dxos/packages/sdk/app-framework/src/core/manager.ts";
309
246
  var isPromise = (value) => {
310
247
  return value !== null && typeof value === "object" && "then" in value;
311
248
  };
312
249
  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();
316
- this.registry = registry ?? Registry.make();
317
- this.context = new PluginContext({
318
- registry: this.registry,
319
- activate: (event) => this._activate(event),
320
- reset: (id) => this._reset(id)
321
- });
322
- this._pluginLoader = pluginLoader;
323
- this._state = live({
324
- plugins,
325
- core,
326
- enabled,
327
- modules: [],
328
- active: [],
329
- pendingReset: [],
330
- eventsFired: []
331
- });
332
- plugins.forEach((plugin) => this._addPlugin(plugin));
333
- core.forEach((id) => this.enable(id));
334
- enabled.forEach((id) => this.enable(id));
335
- }
336
250
  /**
337
251
  * Plugins that are currently registered.
338
252
  *
@@ -399,7 +313,7 @@ var PluginManager = class {
399
313
  id
400
314
  }, {
401
315
  F: __dxlog_file2,
402
- L: 154,
316
+ L: 157,
403
317
  S: this,
404
318
  C: (f, a) => f(...a)
405
319
  });
@@ -418,7 +332,7 @@ var PluginManager = class {
418
332
  id
419
333
  }, {
420
334
  F: __dxlog_file2,
421
- L: 167,
335
+ L: 170,
422
336
  S: this,
423
337
  C: (f, a) => f(...a)
424
338
  });
@@ -439,7 +353,7 @@ var PluginManager = class {
439
353
  ]
440
354
  }, {
441
355
  F: __dxlog_file2,
442
- L: 182,
356
+ L: 185,
443
357
  S: this,
444
358
  C: (f, a) => f(...a)
445
359
  });
@@ -459,7 +373,7 @@ var PluginManager = class {
459
373
  id
460
374
  }, {
461
375
  F: __dxlog_file2,
462
- L: 200,
376
+ L: 203,
463
377
  S: this,
464
378
  C: (f, a) => f(...a)
465
379
  });
@@ -481,7 +395,7 @@ var PluginManager = class {
481
395
  id
482
396
  }, {
483
397
  F: __dxlog_file2,
484
- L: 217,
398
+ L: 220,
485
399
  S: this,
486
400
  C: (f, a) => f(...a)
487
401
  });
@@ -533,7 +447,7 @@ var PluginManager = class {
533
447
  id: plugin.meta.id
534
448
  }, {
535
449
  F: __dxlog_file2,
536
- L: 270,
450
+ L: 273,
537
451
  S: this,
538
452
  C: (f, a) => f(...a)
539
453
  });
@@ -548,7 +462,7 @@ var PluginManager = class {
548
462
  id
549
463
  }, {
550
464
  F: __dxlog_file2,
551
- L: 279,
465
+ L: 283,
552
466
  S: this,
553
467
  C: (f, a) => f(...a)
554
468
  });
@@ -564,7 +478,7 @@ var PluginManager = class {
564
478
  id: module.id
565
479
  }, {
566
480
  F: __dxlog_file2,
567
- L: 289,
481
+ L: 293,
568
482
  S: this,
569
483
  C: (f, a) => f(...a)
570
484
  });
@@ -579,7 +493,7 @@ var PluginManager = class {
579
493
  id
580
494
  }, {
581
495
  F: __dxlog_file2,
582
- L: 298,
496
+ L: 303,
583
497
  S: this,
584
498
  C: (f, a) => f(...a)
585
499
  });
@@ -607,13 +521,13 @@ var PluginManager = class {
607
521
  _setPendingResetByModule(module) {
608
522
  return untracked(() => {
609
523
  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));
524
+ const pendingReset = Array.fromIterable(new Set(activationEvents)).filter((event) => !this._state.pendingReset.includes(event));
611
525
  if (pendingReset.length > 0) {
612
526
  log2("pending reset", {
613
527
  events: pendingReset
614
528
  }, {
615
529
  F: __dxlog_file2,
616
- L: 336,
530
+ L: 341,
617
531
  S: this,
618
532
  C: (f, a) => f(...a)
619
533
  });
@@ -625,35 +539,40 @@ var PluginManager = class {
625
539
  * @internal
626
540
  */
627
541
  // TODO(wittjosiah): Improve error typing.
628
- _activate(event) {
542
+ _activate(event, params) {
629
543
  return Effect2.gen(this, function* () {
630
544
  const key = typeof event === "string" ? event : eventKey(event);
631
545
  log2("activating", {
632
- key
546
+ key,
547
+ ...params
633
548
  }, {
634
549
  F: __dxlog_file2,
635
- L: 349,
550
+ L: 357,
636
551
  S: this,
637
552
  C: (f, a) => f(...a)
638
553
  });
554
+ yield* Ref.update(this._activatingEvents, (activating) => Array.append(activating, key));
639
555
  const pendingIndex = this._state.pendingReset.findIndex((event2) => event2 === key);
640
556
  if (pendingIndex !== -1) {
641
557
  this._state.pendingReset.splice(pendingIndex, 1);
642
558
  }
559
+ const activatingEvents = yield* this._activatingEvents;
560
+ const activatingModules = yield* this._activatingModules;
643
561
  const modules = this._getInactiveModulesByEvent(key).filter((module) => {
644
562
  const allOf2 = isAllOf(module.activatesOn);
645
563
  if (!allOf2) {
646
564
  return true;
647
565
  }
648
566
  const events = module.activatesOn.events.filter((event2) => eventKey(event2) !== key);
649
- return events.every((event2) => this._state.eventsFired.includes(eventKey(event2)));
567
+ return events.every((event2) => this._state.eventsFired.includes(eventKey(event2)) || activatingEvents.includes(eventKey(event2))) && !activatingModules.includes(module.id);
650
568
  });
569
+ yield* Ref.update(this._activatingModules, (activating) => Array.appendAll(activating, modules.map((module) => module.id)));
651
570
  if (modules.length === 0) {
652
571
  log2("no modules to activate", {
653
572
  key
654
573
  }, {
655
574
  F: __dxlog_file2,
656
- L: 365,
575
+ L: 388,
657
576
  S: this,
658
577
  C: (f, a) => f(...a)
659
578
  });
@@ -667,7 +586,7 @@ var PluginManager = class {
667
586
  modules: modules.map((module) => module.id)
668
587
  }, {
669
588
  F: __dxlog_file2,
670
- L: 372,
589
+ L: 395,
671
590
  S: this,
672
591
  C: (f, a) => f(...a)
673
592
  });
@@ -675,29 +594,36 @@ var PluginManager = class {
675
594
  event: key,
676
595
  state: "activating"
677
596
  });
678
- const getCapabilities = yield* Effect2.all(modules.map(({ activate }) => Effect2.tryPromise({
679
- try: async () => activate(this.context),
680
- catch: (error) => error
681
- })), {
597
+ yield* pipe(modules, Array.flatMap((module) => module.activatesBefore ?? []), HashSet.fromIterable, HashSet.toValues, Array.filter((event2) => !activatingEvents.includes(eventKey(event2))), Array.map((event2) => this._activate(event2, {
598
+ before: key
599
+ })), Effect2.allWith({
682
600
  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)) {
601
+ }));
602
+ const getCapabilities = yield* pipe(modules, Array.map((mod) => this._loadModule(mod)), Effect2.allWith({
603
+ concurrency: "unbounded"
604
+ }), Effect2.catchAll((error) => {
694
605
  this.activation.emit({
695
606
  event: key,
696
607
  state: "error",
697
- error: result.left
608
+ error
698
609
  });
699
- yield* Effect2.fail(result.left);
700
- }
610
+ return Effect2.fail(error);
611
+ }));
612
+ yield* pipe(
613
+ modules,
614
+ Array.zip(getCapabilities),
615
+ Array.map(([module, capabilities]) => this._contributeCapabilities(module, capabilities)),
616
+ // TODO(wittjosiah): This currently can't be run in parallel.
617
+ // Running this with concurrency causes races with `allOf` activation events.
618
+ Effect2.all
619
+ );
620
+ yield* pipe(modules, Array.flatMap((module) => module.activatesAfter ?? []), HashSet.fromIterable, HashSet.toValues, Array.filter((event2) => !activatingEvents.includes(eventKey(event2))), Array.map((event2) => this._activate(event2, {
621
+ after: key
622
+ })), Effect2.allWith({
623
+ concurrency: "unbounded"
624
+ }));
625
+ yield* Ref.update(this._activatingEvents, (activating) => Array.filter(activating, (event2) => event2 !== key));
626
+ yield* Ref.update(this._activatingModules, (activating) => Array.filter(activating, (module) => !modules.map((module2) => module2.id).includes(module)));
701
627
  if (!this._state.eventsFired.includes(key)) {
702
628
  this._state.eventsFired.push(key);
703
629
  }
@@ -709,39 +635,15 @@ var PluginManager = class {
709
635
  key
710
636
  }, {
711
637
  F: __dxlog_file2,
712
- L: 406,
638
+ L: 451,
713
639
  S: this,
714
640
  C: (f, a) => f(...a)
715
641
  });
716
642
  return true;
717
643
  });
718
644
  }
719
- _activateModule(module, getCapabilities) {
645
+ _contributeCapabilities(module, capabilities) {
720
646
  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
647
  capabilities.forEach((capability) => {
746
648
  this.context.contributeCapability({
747
649
  module: module.id,
@@ -750,17 +652,6 @@ var PluginManager = class {
750
652
  });
751
653
  this._state.active.push(module.id);
752
654
  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
655
  });
765
656
  }
766
657
  _deactivate(id) {
@@ -783,10 +674,11 @@ var PluginManager = class {
783
674
  id
784
675
  }, {
785
676
  F: __dxlog_file2,
786
- L: 471,
677
+ L: 533,
787
678
  S: this,
788
679
  C: (f, a) => f(...a)
789
680
  });
681
+ this._moduleMemoMap.delete(id);
790
682
  const capabilities = this._capabilities.get(id);
791
683
  if (capabilities) {
792
684
  for (const capability of capabilities) {
@@ -807,7 +699,7 @@ var PluginManager = class {
807
699
  id
808
700
  }, {
809
701
  F: __dxlog_file2,
810
- L: 497,
702
+ L: 560,
811
703
  S: this,
812
704
  C: (f, a) => f(...a)
813
705
  });
@@ -821,7 +713,7 @@ var PluginManager = class {
821
713
  key
822
714
  }, {
823
715
  F: __dxlog_file2,
824
- L: 505,
716
+ L: 568,
825
717
  S: this,
826
718
  C: (f, a) => f(...a)
827
719
  });
@@ -836,11 +728,125 @@ var PluginManager = class {
836
728
  }
837
729
  });
838
730
  }
731
+ constructor({ pluginLoader, plugins = [], core = plugins.map(({ meta: meta2 }) => meta2.id), enabled = [], registry }) {
732
+ _define_property2(this, "activation", new Event());
733
+ _define_property2(this, "context", void 0);
734
+ _define_property2(this, "registry", void 0);
735
+ _define_property2(this, "_state", void 0);
736
+ _define_property2(this, "_pluginLoader", void 0);
737
+ _define_property2(this, "_capabilities", /* @__PURE__ */ new Map());
738
+ _define_property2(this, "_moduleMemoMap", /* @__PURE__ */ new Map());
739
+ _define_property2(this, "_activatingEvents", Effect2.runSync(Ref.make([])));
740
+ _define_property2(this, "_activatingModules", Effect2.runSync(Ref.make([])));
741
+ _define_property2(this, "_loadModule", (mod) => Effect2.tryPromise({
742
+ try: async () => {
743
+ const entry = this._moduleMemoMap.get(mod.id);
744
+ if (entry) {
745
+ return entry;
746
+ }
747
+ const promise = (async () => {
748
+ const start = performance.now();
749
+ let failed = false;
750
+ try {
751
+ log2("loading module", {
752
+ module: mod.id
753
+ }, {
754
+ F: __dxlog_file2,
755
+ L: 470,
756
+ S: this,
757
+ C: (f, a) => f(...a)
758
+ });
759
+ let activationResult = await mod.activate(this.context);
760
+ if (typeof activationResult === "function") {
761
+ activationResult = await activationResult();
762
+ }
763
+ return Array.isArray(activationResult) ? activationResult : [
764
+ activationResult
765
+ ];
766
+ } catch (error) {
767
+ failed = true;
768
+ throw error;
769
+ } finally {
770
+ performance.measure("activate-module", {
771
+ start,
772
+ end: performance.now(),
773
+ detail: {
774
+ module: mod.id
775
+ }
776
+ });
777
+ log2("loaded module", {
778
+ module: mod.id,
779
+ elapsed: performance.now() - start,
780
+ failed
781
+ }, {
782
+ F: __dxlog_file2,
783
+ L: 488,
784
+ S: this,
785
+ C: (f, a) => f(...a)
786
+ });
787
+ }
788
+ })();
789
+ this._moduleMemoMap.set(mod.id, promise);
790
+ return promise;
791
+ },
792
+ catch: (error) => error
793
+ }).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`, {
794
+ module: mod.id
795
+ }, {
796
+ F: __dxlog_file2,
797
+ L: 499,
798
+ S: this,
799
+ C: (f, a) => f(...a)
800
+ })))))));
801
+ this.registry = registry ?? Registry.make();
802
+ this.context = new PluginContext({
803
+ registry: this.registry,
804
+ activate: (event) => this._activate(event),
805
+ reset: (id) => this._reset(id)
806
+ });
807
+ this._pluginLoader = pluginLoader;
808
+ this._state = live({
809
+ plugins,
810
+ core,
811
+ enabled,
812
+ modules: [],
813
+ active: [],
814
+ eventsFired: [],
815
+ pendingReset: []
816
+ });
817
+ plugins.forEach((plugin) => this._addPlugin(plugin));
818
+ core.forEach((id) => this.enable(id));
819
+ enabled.forEach((id) => this.enable(id));
820
+ }
839
821
  };
822
+ var together = (togetherEffect) => (effect) => Effect2.gen(function* () {
823
+ const togetherFiber = yield* Effect2.fork(togetherEffect);
824
+ const result = yield* effect;
825
+ yield* Fiber.interrupt(togetherFiber);
826
+ return result;
827
+ });
840
828
 
841
829
  // src/core/plugin.ts
830
+ function _define_property3(obj, key, value) {
831
+ if (key in obj) {
832
+ Object.defineProperty(obj, key, {
833
+ value,
834
+ enumerable: true,
835
+ configurable: true,
836
+ writable: true
837
+ });
838
+ } else {
839
+ obj[key] = value;
840
+ }
841
+ return obj;
842
+ }
842
843
  var PluginModule = class {
843
844
  constructor(options) {
845
+ _define_property3(this, "id", void 0);
846
+ _define_property3(this, "activatesOn", void 0);
847
+ _define_property3(this, "activatesBefore", void 0);
848
+ _define_property3(this, "activatesAfter", void 0);
849
+ _define_property3(this, "activate", void 0);
844
850
  this.id = options.id;
845
851
  this.activatesOn = options.activatesOn;
846
852
  this.activatesBefore = options.activatesBefore;
@@ -850,13 +856,20 @@ var PluginModule = class {
850
856
  };
851
857
  var defineModule = (options) => new PluginModule(options);
852
858
  var Plugin = class {
853
- constructor(meta, modules) {
854
- this.meta = meta;
859
+ constructor(meta2, modules) {
860
+ _define_property3(this, "meta", void 0);
861
+ _define_property3(this, "modules", void 0);
862
+ this.meta = meta2;
855
863
  this.modules = modules;
856
864
  }
857
865
  };
858
- var definePlugin = (meta, modules) => {
859
- return new Plugin(meta, modules);
866
+ var definePlugin = (meta2, provider) => {
867
+ const factory = (args) => {
868
+ return new Plugin(meta2, provider(args));
869
+ };
870
+ return Object.assign(factory, {
871
+ meta: meta2
872
+ });
860
873
  };
861
874
 
862
875
  // src/common/capabilities.ts
@@ -877,8 +890,11 @@ var definePlugin = (meta, modules) => {
877
890
  Capabilities2.SettingsStore = defineCapability("dxos.org/app-framework/capability/settings-store");
878
891
  Capabilities2.Settings = defineCapability("dxos.org/app-framework/capability/settings");
879
892
  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");
893
+ Capabilities2.Toolkit = defineCapability("dxos.org/app-framework/capability/ai-toolkit");
894
+ Capabilities2.ToolkitHandler = defineCapability("dxos.org/app-framework/capability/ai-toolkit-handler");
895
+ Capabilities2.BlueprintDefinition = defineCapability("dxos.org/app-framework/capability/blueprint-definition");
896
+ Capabilities2.AiServiceLayer = defineCapability("dxos.org/app-framework/capability/ai-service-factory");
897
+ Capabilities2.AiModelResolver = defineCapability("dxos.org/app-framework/capability/ai-model-resolver");
882
898
  Capabilities2.Functions = defineCapability("dxos.org/app-framework/capability/functions");
883
899
  Capabilities2.FileUploader = defineCapability("dxos.org/app-framework/capability/file-uploader");
884
900
  Capabilities2.AnchorSort = defineCapability("dxos.org/app-framework/capability/anchor-sort");
@@ -886,22 +902,19 @@ var definePlugin = (meta, modules) => {
886
902
  var Capabilities;
887
903
 
888
904
  // src/common/collaboration.ts
889
- import { Schema as Schema3 } from "effect";
890
- import { Expando, Ref } from "@dxos/echo-schema";
905
+ import { Schema } from "effect";
906
+ import { DataType } from "@dxos/schema";
891
907
  (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."
908
+ class AcceptProposal extends Schema.TaggedClass()("collaboration/accept-proposal", {
909
+ input: Schema.Struct({
910
+ subject: Schema.Any,
911
+ anchor: Schema.String,
912
+ proposal: DataType.MessageBlock.Proposal
900
913
  }),
901
- output: Schema3.Void
914
+ output: Schema.Void
902
915
  }) {
903
916
  }
904
- CollaborationActions2.InsertContent = InsertContent;
917
+ CollaborationActions2.AcceptProposal = AcceptProposal;
905
918
  })(CollaborationActions || (CollaborationActions = {}));
906
919
  var CollaborationActions;
907
920
 
@@ -924,7 +937,7 @@ var CollaborationActions;
924
937
  var Events;
925
938
 
926
939
  // src/common/file.ts
927
- import { Schema as Schema4 } from "effect";
940
+ import { Schema as Schema2 } from "effect";
928
941
  var defaultFileTypes = {
929
942
  images: [
930
943
  "png",
@@ -944,23 +957,131 @@ var defaultFileTypes = {
944
957
  "md"
945
958
  ]
946
959
  };
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)
960
+ var FileInfoSchema = Schema2.Struct({
961
+ name: Schema2.String,
962
+ type: Schema2.String,
963
+ url: Schema2.optional(Schema2.String),
964
+ cid: Schema2.optional(Schema2.String)
952
965
  });
953
966
 
954
967
  // src/common/layout.ts
955
968
  import { Schema as Schema5 } from "effect";
956
969
 
957
- // src/plugin-intent/IntentPlugin.ts
958
- var IntentPlugin = () => definePlugin({
959
- id: INTENT_PLUGIN,
970
+ // src/plugin-intent/actions.ts
971
+ import { Schema as Schema4 } from "effect";
972
+
973
+ // src/plugin-intent/intent.ts
974
+ import { Schema as Schema3 } from "effect";
975
+ var createIntent = (schema, data = {}, params = {}) => {
976
+ const _ = Schema3.validateSync(schema.fields.input)(data);
977
+ const intent = {
978
+ ...params,
979
+ _schema: schema,
980
+ id: schema._tag,
981
+ data
982
+ };
983
+ return {
984
+ first: intent,
985
+ last: intent,
986
+ all: [
987
+ intent
988
+ ]
989
+ };
990
+ };
991
+ var chain = (schema, data = {}, params = {}) => (intent) => {
992
+ const intents = "all" in intent ? intent.all : [
993
+ intent
994
+ ];
995
+ const first = intents[0];
996
+ const last = {
997
+ ...params,
998
+ _schema: schema,
999
+ id: schema._tag,
1000
+ data
1001
+ };
1002
+ return {
1003
+ first,
1004
+ last,
1005
+ all: [
1006
+ ...intents,
1007
+ last
1008
+ ]
1009
+ };
1010
+ };
1011
+ var Label = Schema3.Union(Schema3.String, Schema3.mutable(Schema3.Tuple(Schema3.String, Schema3.mutable(Schema3.Struct({
1012
+ ns: Schema3.String,
1013
+ count: Schema3.optional(Schema3.Number),
1014
+ defaultValue: Schema3.optional(Schema3.String)
1015
+ })))));
1016
+
1017
+ // src/plugin-intent/meta.ts
1018
+ var meta = {
1019
+ id: "dxos.org/plugin/intent",
960
1020
  name: "Intent"
961
- }, [
1021
+ };
1022
+
1023
+ // src/plugin-intent/actions.ts
1024
+ (function(IntentAction2) {
1025
+ class Track extends Schema4.TaggedClass()(`${meta.id}/action/track`, {
1026
+ input: Schema4.Struct({
1027
+ intents: Schema4.Array(Schema4.String),
1028
+ error: Schema4.optional(Schema4.String)
1029
+ }),
1030
+ output: Schema4.Void
1031
+ }) {
1032
+ }
1033
+ IntentAction2.Track = Track;
1034
+ class ShowUndo extends Schema4.TaggedClass()(`${meta.id}/action/show-undo`, {
1035
+ input: Schema4.Struct({
1036
+ message: Label
1037
+ }),
1038
+ output: Schema4.Void
1039
+ }) {
1040
+ }
1041
+ IntentAction2.ShowUndo = ShowUndo;
1042
+ })(IntentAction || (IntentAction = {}));
1043
+ var IntentAction;
1044
+
1045
+ // src/plugin-intent/errors.ts
1046
+ function _define_property4(obj, key, value) {
1047
+ if (key in obj) {
1048
+ Object.defineProperty(obj, key, {
1049
+ value,
1050
+ enumerable: true,
1051
+ configurable: true,
1052
+ writable: true
1053
+ });
1054
+ } else {
1055
+ obj[key] = value;
1056
+ }
1057
+ return obj;
1058
+ }
1059
+ var BaseError = class extends Error {
1060
+ constructor(code, message, context) {
1061
+ super(message ?? code, {
1062
+ cause: context
1063
+ }), _define_property4(this, "code", void 0), _define_property4(this, "context", void 0), this.code = code, this.context = context;
1064
+ this.name = code;
1065
+ Object.setPrototypeOf(this, new.target.prototype);
1066
+ }
1067
+ };
1068
+ var NoResolversError = class extends BaseError {
1069
+ constructor(action) {
1070
+ super("NO_RESOLVERS", "No resolvers were found for the action", {
1071
+ action
1072
+ });
1073
+ }
1074
+ };
1075
+ var CycleDetectedError = class extends BaseError {
1076
+ constructor(context) {
1077
+ super("CYCLE_DETECTED", "Intent execution limit exceeded. This is likely due to an infinite loop within intent resolvers.", context);
1078
+ }
1079
+ };
1080
+
1081
+ // src/plugin-intent/IntentPlugin.ts
1082
+ var IntentPlugin = definePlugin(meta, () => [
962
1083
  defineModule({
963
- id: `${INTENT_PLUGIN}/module/dispatcher`,
1084
+ id: `${meta.id}/module/dispatcher`,
964
1085
  // TODO(wittjosiah): This will mean that startup needs to be reset when intents are added or removed.
965
1086
  // This is fine for now because it's how it worked prior to capabilities api anyways.
966
1087
  // In the future, the intent dispatcher should be able to be reset without resetting the entire app.
@@ -968,15 +1089,14 @@ var IntentPlugin = () => definePlugin({
968
1089
  activatesAfter: [
969
1090
  Events.DispatcherReady
970
1091
  ],
971
- activate: lazy(() => import("./intent-dispatcher-6CYNGPSW.mjs"))
1092
+ activate: lazy(() => import("./intent-dispatcher-SAPOKSLZ.mjs"))
972
1093
  })
973
1094
  ]);
974
1095
 
975
1096
  // src/common/layout.ts
976
1097
  var LAYOUT_PLUGIN = "dxos.org/plugin/layout";
977
- var LAYOUT_ACTION = `${LAYOUT_PLUGIN}/action`;
978
1098
  (function(LayoutAction2) {
979
- LayoutAction2.UPDATE_LAYOUT = `${LAYOUT_ACTION}/update-layout`;
1099
+ LayoutAction2.UPDATE_LAYOUT = `${LAYOUT_PLUGIN}/action/update-layout`;
980
1100
  class UpdateLayout extends Schema5.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
981
1101
  input: Schema5.Struct({
982
1102
  part: Schema5.String.annotations({
@@ -1338,7 +1458,7 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1338
1458
  const handleIntent = (intent) => Effect3.gen(function* () {
1339
1459
  const candidates = getResolvers().filter((resolver) => resolver.intent._tag === intent.id).filter((resolver) => !resolver.filter || resolver.filter(intent.data)).toSorted(byPosition);
1340
1460
  if (candidates.length === 0) {
1341
- yield* Effect3.fail(new NoResolversError(intent.id));
1461
+ return yield* Effect3.fail(new NoResolversError(intent.id));
1342
1462
  }
1343
1463
  const effect = candidates[0].resolve(intent.data, intent.undo ?? false);
1344
1464
  const result = Effect3.isEffect(effect) ? yield* effect : yield* Effect3.promise(async () => effect);
@@ -1350,7 +1470,7 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1350
1470
  const dispatch = (intentChain, depth = 0) => {
1351
1471
  return Effect3.gen(function* () {
1352
1472
  if (depth > executionLimit) {
1353
- yield* Effect3.fail(new CycleDetectedError());
1473
+ return yield* Effect3.fail(new CycleDetectedError());
1354
1474
  }
1355
1475
  const resultsRef = yield* Ref2.make([]);
1356
1476
  for (const intent of intentChain.all) {
@@ -1372,7 +1492,7 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1372
1492
  }
1373
1493
  }
1374
1494
  if (result2.error) {
1375
- yield* Effect3.fail(result2.error);
1495
+ return yield* Effect3.fail(result2.error);
1376
1496
  }
1377
1497
  }
1378
1498
  const results = yield* resultsRef.get;
@@ -1401,7 +1521,7 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1401
1521
  })).catch((error) => {
1402
1522
  log3.catch(error, void 0, {
1403
1523
  F: __dxlog_file3,
1404
- L: 270,
1524
+ L: 271,
1405
1525
  S: void 0,
1406
1526
  C: (f, a) => f(...a)
1407
1527
  });
@@ -1454,7 +1574,7 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1454
1574
  };
1455
1575
  var defaultEffect = () => Effect3.fail(new Error("Intent runtime not ready"));
1456
1576
  var defaultPromise = () => Effect3.runPromise(defaultEffect());
1457
- var intent_dispatcher_default = (context) => {
1577
+ var intent_dispatcher_default = ((context) => {
1458
1578
  const state = live2({
1459
1579
  dispatch: defaultEffect,
1460
1580
  dispatchPromise: defaultPromise,
@@ -1476,7 +1596,7 @@ var intent_dispatcher_default = (context) => {
1476
1596
  state.undo = undo;
1477
1597
  state.undoPromise = undoPromise;
1478
1598
  return contributes(Capabilities.IntentDispatcher, state);
1479
- };
1599
+ });
1480
1600
 
1481
1601
  export {
1482
1602
  defineCapability,
@@ -1503,19 +1623,18 @@ export {
1503
1623
  createIntent,
1504
1624
  chain,
1505
1625
  Label,
1506
- INTENT_PLUGIN,
1507
- INTENT_ACTION,
1508
1626
  IntentAction,
1627
+ BaseError,
1628
+ NoResolversError,
1629
+ CycleDetectedError,
1509
1630
  createResolver,
1510
1631
  createDispatcher,
1511
1632
  intent_dispatcher_default,
1512
1633
  IntentPlugin,
1513
- LAYOUT_PLUGIN,
1514
- LAYOUT_ACTION,
1515
1634
  LayoutAction,
1516
1635
  createSurface,
1517
1636
  ResourceKey,
1518
1637
  ResourceLanguage,
1519
1638
  Resource
1520
1639
  };
1521
- //# sourceMappingURL=chunk-ZEZ4FVEU.mjs.map
1640
+ //# sourceMappingURL=chunk-SOVTUUAY.mjs.map