@dxos/app-framework 0.8.4-main.c1de068 → 0.8.4-main.c4373fc

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 (211) 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-77MY7KAY.mjs} +31 -30
  6. package/dist/lib/browser/app-graph-builder-77MY7KAY.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-FO2PH7M3.mjs → chunk-4NFLRSTX.mjs} +189 -137
  8. package/dist/lib/browser/chunk-4NFLRSTX.mjs.map +7 -0
  9. package/dist/lib/browser/{chunk-FMN65HSW.mjs → chunk-OKF2PAWO.mjs} +408 -281
  10. package/dist/lib/browser/chunk-OKF2PAWO.mjs.map +7 -0
  11. package/dist/lib/browser/{chunk-ORWHM7CO.mjs → chunk-SCPE4ZO2.mjs} +11 -8
  12. package/dist/lib/browser/chunk-SCPE4ZO2.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-Y4LZNOBC.mjs} +2 -2
  16. package/dist/lib/browser/{intent-resolver-ZTNOSO3A.mjs → intent-resolver-XO5OYWVD.mjs} +7 -7
  17. package/dist/lib/browser/intent-resolver-XO5OYWVD.mjs.map +7 -0
  18. package/dist/lib/browser/meta.json +1 -1
  19. package/dist/lib/browser/{store-KML2R4IE.mjs → store-E3YSBPJQ.mjs} +4 -4
  20. package/dist/lib/browser/{store-KML2R4IE.mjs.map → store-E3YSBPJQ.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-WK7WBM6I.mjs} +31 -30
  25. package/dist/lib/node-esm/app-graph-builder-WK7WBM6I.mjs.map +7 -0
  26. package/dist/lib/node-esm/{chunk-ZEZ4FVEU.mjs → chunk-7DNZQ6H2.mjs} +408 -281
  27. package/dist/lib/node-esm/chunk-7DNZQ6H2.mjs.map +7 -0
  28. package/dist/lib/node-esm/{chunk-73HGSHKE.mjs → chunk-AHCD4UYO.mjs} +189 -137
  29. package/dist/lib/node-esm/chunk-AHCD4UYO.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 -28
  33. package/dist/lib/node-esm/index.mjs.map +3 -3
  34. package/dist/lib/node-esm/{intent-dispatcher-6CYNGPSW.mjs → intent-dispatcher-R4CCPBHO.mjs} +2 -2
  35. package/dist/lib/node-esm/{intent-resolver-W7Z7WFFM.mjs → intent-resolver-NVYY6BQA.mjs} +7 -7
  36. package/dist/lib/node-esm/intent-resolver-NVYY6BQA.mjs.map +7 -0
  37. package/dist/lib/node-esm/meta.json +1 -1
  38. package/dist/lib/node-esm/{store-QEXGXLWZ.mjs → store-QA5DGTOS.mjs} +4 -4
  39. package/dist/lib/node-esm/{store-QEXGXLWZ.mjs.map → store-QA5DGTOS.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 +85 -8
  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 +7 -13
  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/components/App.d.ts +10 -0
  59. package/dist/types/src/components/App.d.ts.map +1 -0
  60. package/dist/types/src/components/App.stories.d.ts +14 -0
  61. package/dist/types/src/components/App.stories.d.ts.map +1 -0
  62. package/dist/types/src/components/DefaultFallback.d.ts +8 -0
  63. package/dist/types/src/components/DefaultFallback.d.ts.map +1 -0
  64. package/dist/types/src/components/index.d.ts +2 -0
  65. package/dist/types/src/components/index.d.ts.map +1 -0
  66. package/dist/types/src/{App.d.ts → components/useApp.d.ts} +7 -6
  67. package/dist/types/src/components/useApp.d.ts.map +1 -0
  68. package/dist/types/src/components/useLoading.d.ts +19 -0
  69. package/dist/types/src/components/useLoading.d.ts.map +1 -0
  70. package/dist/types/src/core/capabilities.d.ts +5 -2
  71. package/dist/types/src/core/capabilities.d.ts.map +1 -1
  72. package/dist/types/src/core/manager.d.ts +6 -2
  73. package/dist/types/src/core/manager.d.ts.map +1 -1
  74. package/dist/types/src/core/plugin.d.ts +4 -1
  75. package/dist/types/src/core/plugin.d.ts.map +1 -1
  76. package/dist/types/src/index.d.ts +1 -1
  77. package/dist/types/src/index.d.ts.map +1 -1
  78. package/dist/types/src/playground/debug/Debug.d.ts +1 -1
  79. package/dist/types/src/playground/debug/plugin.d.ts +1 -1
  80. package/dist/types/src/playground/debug/plugin.d.ts.map +1 -1
  81. package/dist/types/src/playground/generator/Main.d.ts +1 -1
  82. package/dist/types/src/playground/generator/Toolbar.d.ts +1 -1
  83. package/dist/types/src/playground/generator/Toolbar.d.ts.map +1 -1
  84. package/dist/types/src/playground/generator/generator.d.ts +1 -1
  85. package/dist/types/src/playground/generator/generator.d.ts.map +1 -1
  86. package/dist/types/src/playground/generator/plugin.d.ts +1 -1
  87. package/dist/types/src/playground/generator/plugin.d.ts.map +1 -1
  88. package/dist/types/src/playground/layout/Layout.d.ts +2 -2
  89. package/dist/types/src/playground/layout/plugin.d.ts +1 -1
  90. package/dist/types/src/playground/layout/plugin.d.ts.map +1 -1
  91. package/dist/types/src/playground/logger/Toolbar.d.ts +1 -1
  92. package/dist/types/src/playground/logger/Toolbar.d.ts.map +1 -1
  93. package/dist/types/src/playground/logger/plugin.d.ts +1 -1
  94. package/dist/types/src/playground/logger/plugin.d.ts.map +1 -1
  95. package/dist/types/src/playground/logger/schema.d.ts +1 -1
  96. package/dist/types/src/playground/logger/schema.d.ts.map +1 -1
  97. package/dist/types/src/playground/playground.stories.d.ts +5 -4
  98. package/dist/types/src/playground/playground.stories.d.ts.map +1 -1
  99. package/dist/types/src/plugin-intent/IntentPlugin.d.ts +1 -1
  100. package/dist/types/src/plugin-intent/IntentPlugin.d.ts.map +1 -1
  101. package/dist/types/src/plugin-intent/actions.d.ts +5 -7
  102. package/dist/types/src/plugin-intent/actions.d.ts.map +1 -1
  103. package/dist/types/src/plugin-intent/errors.d.ts.map +1 -1
  104. package/dist/types/src/plugin-intent/index.d.ts +1 -0
  105. package/dist/types/src/plugin-intent/index.d.ts.map +1 -1
  106. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts +7 -7
  107. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts.map +1 -1
  108. package/dist/types/src/plugin-intent/intent.d.ts +1 -1
  109. package/dist/types/src/plugin-intent/intent.d.ts.map +1 -1
  110. package/dist/types/src/plugin-intent/meta.d.ts +3 -0
  111. package/dist/types/src/plugin-intent/meta.d.ts.map +1 -0
  112. package/dist/types/src/plugin-settings/SettingsPlugin.d.ts +1 -1
  113. package/dist/types/src/plugin-settings/SettingsPlugin.d.ts.map +1 -1
  114. package/dist/types/src/plugin-settings/actions.d.ts +5 -7
  115. package/dist/types/src/plugin-settings/actions.d.ts.map +1 -1
  116. package/dist/types/src/plugin-settings/app-graph-builder.d.ts +1 -1
  117. package/dist/types/src/plugin-settings/app-graph-builder.d.ts.map +1 -1
  118. package/dist/types/src/plugin-settings/intent-resolver.d.ts +1 -1
  119. package/dist/types/src/plugin-settings/intent-resolver.d.ts.map +1 -1
  120. package/dist/types/src/plugin-settings/meta.d.ts +3 -0
  121. package/dist/types/src/plugin-settings/meta.d.ts.map +1 -0
  122. package/dist/types/src/plugin-settings/store.d.ts +1 -1
  123. package/dist/types/src/plugin-settings/store.d.ts.map +1 -1
  124. package/dist/types/src/plugin-settings/translations.d.ts +2 -1
  125. package/dist/types/src/plugin-settings/translations.d.ts.map +1 -1
  126. package/dist/types/src/react/ErrorBoundary.d.ts +13 -14
  127. package/dist/types/src/react/ErrorBoundary.d.ts.map +1 -1
  128. package/dist/types/src/react/IntentContext.d.ts.map +1 -1
  129. package/dist/types/src/react/Surface.d.ts +2 -2
  130. package/dist/types/src/react/Surface.d.ts.map +1 -1
  131. package/dist/types/src/react/Surface.stories.d.ts +6 -5
  132. package/dist/types/src/react/Surface.stories.d.ts.map +1 -1
  133. package/dist/types/src/react/common.d.ts.map +1 -1
  134. package/dist/types/src/react/useCapabilities.d.ts.map +1 -1
  135. package/dist/types/src/testing/withPluginManager.d.ts +6 -6
  136. package/dist/types/src/testing/withPluginManager.d.ts.map +1 -1
  137. package/dist/types/src/testing/withPluginManager.stories.d.ts +9 -3
  138. package/dist/types/src/testing/withPluginManager.stories.d.ts.map +1 -1
  139. package/dist/types/tsconfig.tsbuildinfo +1 -1
  140. package/moon.yml +4 -0
  141. package/package.json +34 -29
  142. package/src/common/capabilities.ts +109 -10
  143. package/src/common/collaboration.ts +6 -9
  144. package/src/common/events.ts +3 -1
  145. package/src/common/file.ts +1 -1
  146. package/src/common/index.ts +1 -1
  147. package/src/common/layout.ts +3 -4
  148. package/src/common/surface.ts +15 -18
  149. package/src/common/translations.ts +1 -1
  150. package/src/components/App.stories.tsx +33 -0
  151. package/src/components/App.tsx +59 -0
  152. package/src/components/DefaultFallback.tsx +26 -0
  153. package/src/components/index.ts +5 -0
  154. package/src/{App.tsx → components/useApp.tsx} +24 -136
  155. package/src/components/useLoading.tsx +70 -0
  156. package/src/core/capabilities.test.ts +2 -2
  157. package/src/core/capabilities.ts +12 -7
  158. package/src/core/manager.test.ts +22 -21
  159. package/src/core/manager.ts +139 -54
  160. package/src/core/plugin.ts +8 -2
  161. package/src/helpers.test.ts +1 -1
  162. package/src/index.ts +1 -1
  163. package/src/playground/debug/Debug.tsx +1 -1
  164. package/src/playground/debug/plugin.ts +7 -8
  165. package/src/playground/generator/Toolbar.tsx +2 -1
  166. package/src/playground/generator/generator.ts +4 -4
  167. package/src/playground/generator/plugin.ts +12 -13
  168. package/src/playground/layout/plugin.ts +10 -9
  169. package/src/playground/logger/Toolbar.tsx +2 -1
  170. package/src/playground/logger/plugin.ts +30 -25
  171. package/src/playground/logger/schema.ts +1 -1
  172. package/src/playground/playground.stories.tsx +20 -16
  173. package/src/plugin-intent/IntentPlugin.ts +13 -13
  174. package/src/plugin-intent/actions.ts +4 -6
  175. package/src/plugin-intent/errors.ts +1 -0
  176. package/src/plugin-intent/index.ts +1 -0
  177. package/src/plugin-intent/intent-dispatcher.test.ts +10 -3
  178. package/src/plugin-intent/intent-dispatcher.ts +16 -12
  179. package/src/plugin-intent/intent.ts +1 -1
  180. package/src/plugin-intent/meta.ts +10 -0
  181. package/src/plugin-settings/SettingsPlugin.ts +27 -28
  182. package/src/plugin-settings/actions.ts +9 -13
  183. package/src/plugin-settings/app-graph-builder.ts +20 -17
  184. package/src/plugin-settings/intent-resolver.ts +5 -4
  185. package/src/plugin-settings/meta.ts +10 -0
  186. package/src/plugin-settings/store.ts +1 -1
  187. package/src/plugin-settings/translations.ts +3 -3
  188. package/src/react/ErrorBoundary.tsx +26 -15
  189. package/src/react/IntentContext.tsx +3 -2
  190. package/src/react/Surface.stories.tsx +23 -18
  191. package/src/react/Surface.tsx +14 -5
  192. package/src/react/common.ts +2 -1
  193. package/src/react/useCapabilities.ts +2 -1
  194. package/src/testing/withPluginManager.stories.tsx +9 -5
  195. package/src/testing/withPluginManager.tsx +25 -29
  196. package/tsconfig.json +2 -9
  197. package/vitest.config.ts +8 -6
  198. package/.swc/plugins/v7_linux_x86_64_13.0.0/f45bdff002284d9e8f9ef3f0be909de12da36c049cbcf261ac78fc00abb09a2d +0 -0
  199. package/dist/lib/browser/app-graph-builder-LYF7EKNN.mjs.map +0 -7
  200. package/dist/lib/browser/chunk-FMN65HSW.mjs.map +0 -7
  201. package/dist/lib/browser/chunk-FO2PH7M3.mjs.map +0 -7
  202. package/dist/lib/browser/chunk-ORWHM7CO.mjs.map +0 -7
  203. package/dist/lib/browser/intent-resolver-ZTNOSO3A.mjs.map +0 -7
  204. package/dist/lib/node-esm/app-graph-builder-SAOWGJDK.mjs.map +0 -7
  205. package/dist/lib/node-esm/chunk-73HGSHKE.mjs.map +0 -7
  206. package/dist/lib/node-esm/chunk-UMZQERLE.mjs.map +0 -7
  207. package/dist/lib/node-esm/chunk-ZEZ4FVEU.mjs.map +0 -7
  208. package/dist/lib/node-esm/intent-resolver-W7Z7WFFM.mjs.map +0 -7
  209. package/dist/types/src/App.d.ts.map +0 -1
  210. /package/dist/lib/browser/{intent-dispatcher-LSYQZSEB.mjs.map → intent-dispatcher-Y4LZNOBC.mjs.map} +0 -0
  211. /package/dist/lib/node-esm/{intent-dispatcher-6CYNGPSW.mjs.map → intent-dispatcher-R4CCPBHO.mjs.map} +0 -0
@@ -1,109 +1,31 @@
1
1
  // src/plugin-intent/intent-dispatcher.ts
2
- import { Effect as Effect3, Option, pipe as pipe2, Ref as Ref2 } from "effect";
2
+ import * as Effect3 from "effect/Effect";
3
+ import * as Function2 from "effect/Function";
4
+ import * as Option from "effect/Option";
5
+ import * as Ref2 from "effect/Ref";
3
6
  import { live as live2 } from "@dxos/live-object";
4
7
  import { log as log3 } from "@dxos/log";
5
8
  import { byPosition } from "@dxos/util";
6
9
 
7
- // src/plugin-intent/actions.ts
8
- import { Schema as Schema2 } from "effect";
9
-
10
- // src/plugin-intent/intent.ts
11
- import { Schema } from "effect";
12
- var createIntent = (schema, data = {}, params = {}) => {
13
- const _ = Schema.validateSync(schema.fields.input)(data);
14
- const intent = {
15
- ...params,
16
- _schema: schema,
17
- id: schema._tag,
18
- data
19
- };
20
- return {
21
- first: intent,
22
- last: intent,
23
- all: [
24
- intent
25
- ]
26
- };
27
- };
28
- var chain = (schema, data = {}, params = {}) => (intent) => {
29
- const intents = "all" in intent ? intent.all : [
30
- intent
31
- ];
32
- const first = intents[0];
33
- const last = {
34
- ...params,
35
- _schema: schema,
36
- id: schema._tag,
37
- data
38
- };
39
- return {
40
- first,
41
- last,
42
- all: [
43
- ...intents,
44
- last
45
- ]
46
- };
47
- };
48
- var Label = Schema.Union(Schema.String, Schema.mutable(Schema.Tuple(Schema.String, Schema.mutable(Schema.Struct({
49
- ns: Schema.String,
50
- count: Schema.optional(Schema.Number),
51
- defaultValue: Schema.optional(Schema.String)
52
- })))));
53
-
54
- // src/plugin-intent/actions.ts
55
- var INTENT_PLUGIN = "dxos.org/plugin/intent";
56
- var INTENT_ACTION = `${INTENT_PLUGIN}/action`;
57
- (function(IntentAction2) {
58
- class Track extends Schema2.TaggedClass()(`${INTENT_ACTION}/track`, {
59
- input: Schema2.Struct({
60
- intents: Schema2.Array(Schema2.String),
61
- error: Schema2.optional(Schema2.String)
62
- }),
63
- output: Schema2.Void
64
- }) {
65
- }
66
- IntentAction2.Track = Track;
67
- class ShowUndo extends Schema2.TaggedClass()(`${INTENT_ACTION}/show-undo`, {
68
- input: Schema2.Struct({
69
- message: Label
70
- }),
71
- output: Schema2.Void
72
- }) {
73
- }
74
- IntentAction2.ShowUndo = ShowUndo;
75
- })(IntentAction || (IntentAction = {}));
76
- var IntentAction;
77
-
78
- // src/plugin-intent/errors.ts
79
- var BaseError = class extends Error {
80
- constructor(code, message, context) {
81
- super(message ?? code, {
82
- cause: context
83
- }), this.code = code, this.context = context;
84
- this.name = code;
85
- Object.setPrototypeOf(this, new.target.prototype);
86
- }
87
- };
88
- var NoResolversError = class extends BaseError {
89
- constructor(action) {
90
- super("NO_RESOLVERS", "No resolvers were found for the action", {
91
- action
92
- });
93
- }
94
- };
95
- var CycleDetectedError = class extends BaseError {
96
- constructor(context) {
97
- super("CYCLE_DETECTED", "Intent execution limit exceeded. This is likely due to an infinite loop within intent resolvers.", context);
98
- }
99
- };
100
-
101
10
  // src/core/capabilities.ts
102
11
  import { Rx } from "@effect-rx/rx-react";
103
- import { Effect } from "effect";
12
+ import * as Effect from "effect/Effect";
104
13
  import { Trigger } from "@dxos/async";
105
14
  import { invariant } from "@dxos/invariant";
106
15
  import { log } from "@dxos/log";
16
+ function _define_property(obj, key, value2) {
17
+ if (key in obj) {
18
+ Object.defineProperty(obj, key, {
19
+ value: value2,
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true
23
+ });
24
+ } else {
25
+ obj[key] = value2;
26
+ }
27
+ return obj;
28
+ }
107
29
  var __dxlog_file = "/__w/dxos/dxos/packages/sdk/app-framework/src/core/capabilities.ts";
108
30
  var InterfaceDefTypeId = Symbol.for("InterfaceDefTypeId");
109
31
  var defineCapability = (identifier) => {
@@ -113,6 +35,8 @@ var defineCapability = (identifier) => {
113
35
  };
114
36
  var CapabilityImpl = class {
115
37
  constructor(moduleId, implementation) {
38
+ _define_property(this, "moduleId", void 0);
39
+ _define_property(this, "implementation", void 0);
116
40
  this.moduleId = moduleId;
117
41
  this.implementation = implementation;
118
42
  }
@@ -129,35 +53,6 @@ var lazy = (c) => async (props) => {
129
53
  return async () => getCapability(props);
130
54
  };
131
55
  var PluginContext = class {
132
- constructor({ registry, activate, reset }) {
133
- this._capabilityImpls = Rx.family(() => {
134
- return Rx.make([]).pipe(Rx.keepAlive);
135
- });
136
- this._capabilities = Rx.family((id) => {
137
- return Rx.make((get) => {
138
- const current = get(this._capabilityImpls(id));
139
- return current.map((c) => c.implementation);
140
- });
141
- });
142
- this._capability = Rx.family((id) => {
143
- return Rx.make((get) => {
144
- const current = get(this._capabilities(id));
145
- invariant(current.length > 0, `No capability found for ${id}`, {
146
- F: __dxlog_file,
147
- L: 117,
148
- S: this,
149
- A: [
150
- "current.length > 0",
151
- "`No capability found for ${id}`"
152
- ]
153
- });
154
- return current[0];
155
- });
156
- });
157
- this._registry = registry;
158
- this.activate = activate;
159
- this.reset = reset;
160
- }
161
56
  /**
162
57
  * @internal
163
58
  */
@@ -177,7 +72,7 @@ var PluginContext = class {
177
72
  count: current.length
178
73
  }, {
179
74
  F: __dxlog_file,
180
- L: 161,
75
+ L: 166,
181
76
  S: this,
182
77
  C: (f, a) => f(...a)
183
78
  });
@@ -198,7 +93,7 @@ var PluginContext = class {
198
93
  count: current.length
199
94
  }, {
200
95
  F: __dxlog_file,
201
- L: 180,
96
+ L: 185,
202
97
  S: this,
203
98
  C: (f, a) => f(...a)
204
99
  });
@@ -207,7 +102,7 @@ var PluginContext = class {
207
102
  id: interfaceDef.identifier
208
103
  }, {
209
104
  F: __dxlog_file,
210
- L: 182,
105
+ L: 187,
211
106
  S: this,
212
107
  C: (f, a) => f(...a)
213
108
  });
@@ -272,6 +167,38 @@ var PluginContext = class {
272
167
  async resetPromise(event) {
273
168
  return this.reset(event).pipe(Effect.runPromise);
274
169
  }
170
+ constructor({ registry, activate, reset }) {
171
+ _define_property(this, "_registry", void 0);
172
+ _define_property(this, "_capabilityImpls", Rx.family(() => {
173
+ return Rx.make([]).pipe(Rx.keepAlive);
174
+ }));
175
+ _define_property(this, "_capabilities", Rx.family((id) => {
176
+ return Rx.make((get) => {
177
+ const current = get(this._capabilityImpls(id));
178
+ return current.map((c) => c.implementation);
179
+ });
180
+ }));
181
+ _define_property(this, "_capability", Rx.family((id) => {
182
+ return Rx.make((get) => {
183
+ const current = get(this._capabilities(id));
184
+ invariant(current.length > 0, `No capability found for ${id}`, {
185
+ F: __dxlog_file,
186
+ L: 122,
187
+ S: this,
188
+ A: [
189
+ "current.length > 0",
190
+ "`No capability found for ${id}`"
191
+ ]
192
+ });
193
+ return current[0];
194
+ });
195
+ }));
196
+ _define_property(this, "activate", void 0);
197
+ _define_property(this, "reset", void 0);
198
+ this._registry = registry;
199
+ this.activate = activate;
200
+ this.reset = reset;
201
+ }
275
202
  };
276
203
 
277
204
  // src/core/events.ts
@@ -299,38 +226,35 @@ var getEvents = (events) => "type" in events ? events.events : [
299
226
  // src/core/manager.ts
300
227
  import { Registry } from "@effect-rx/rx-react";
301
228
  import { untracked } from "@preact/signals-core";
302
- import { Array as A, Effect as Effect2, Either, Match, pipe } from "effect";
229
+ import * as Array from "effect/Array";
230
+ import * as Duration from "effect/Duration";
231
+ import * as Effect2 from "effect/Effect";
232
+ import * as Fiber from "effect/Fiber";
233
+ import * as Function from "effect/Function";
234
+ import * as HashSet from "effect/HashSet";
235
+ import * as Match from "effect/Match";
236
+ import * as Ref from "effect/Ref";
303
237
  import { Event } from "@dxos/async";
304
238
  import { live } from "@dxos/live-object";
305
239
  import { log as log2 } from "@dxos/log";
240
+ function _define_property2(obj, key, value2) {
241
+ if (key in obj) {
242
+ Object.defineProperty(obj, key, {
243
+ value: value2,
244
+ enumerable: true,
245
+ configurable: true,
246
+ writable: true
247
+ });
248
+ } else {
249
+ obj[key] = value2;
250
+ }
251
+ return obj;
252
+ }
306
253
  var __dxlog_file2 = "/__w/dxos/dxos/packages/sdk/app-framework/src/core/manager.ts";
307
- var isPromise = (value) => {
308
- return value !== null && typeof value === "object" && "then" in value;
254
+ var isPromise = (value2) => {
255
+ return value2 !== null && typeof value2 === "object" && "then" in value2;
309
256
  };
310
257
  var PluginManager = class {
311
- constructor({ pluginLoader, plugins = [], core = plugins.map(({ meta }) => meta.id), enabled = [], registry }) {
312
- this.activation = new Event();
313
- this._capabilities = /* @__PURE__ */ new Map();
314
- this.registry = registry ?? Registry.make();
315
- this.context = new PluginContext({
316
- registry: this.registry,
317
- activate: (event) => this._activate(event),
318
- reset: (id) => this._reset(id)
319
- });
320
- this._pluginLoader = pluginLoader;
321
- this._state = live({
322
- plugins,
323
- core,
324
- enabled,
325
- modules: [],
326
- active: [],
327
- pendingReset: [],
328
- eventsFired: []
329
- });
330
- plugins.forEach((plugin) => this._addPlugin(plugin));
331
- core.forEach((id) => this.enable(id));
332
- enabled.forEach((id) => this.enable(id));
333
- }
334
258
  /**
335
259
  * Plugins that are currently registered.
336
260
  *
@@ -397,7 +321,7 @@ var PluginManager = class {
397
321
  id
398
322
  }, {
399
323
  F: __dxlog_file2,
400
- L: 154,
324
+ L: 164,
401
325
  S: this,
402
326
  C: (f, a) => f(...a)
403
327
  });
@@ -416,7 +340,7 @@ var PluginManager = class {
416
340
  id
417
341
  }, {
418
342
  F: __dxlog_file2,
419
- L: 167,
343
+ L: 177,
420
344
  S: this,
421
345
  C: (f, a) => f(...a)
422
346
  });
@@ -437,7 +361,7 @@ var PluginManager = class {
437
361
  ]
438
362
  }, {
439
363
  F: __dxlog_file2,
440
- L: 182,
364
+ L: 192,
441
365
  S: this,
442
366
  C: (f, a) => f(...a)
443
367
  });
@@ -457,7 +381,7 @@ var PluginManager = class {
457
381
  id
458
382
  }, {
459
383
  F: __dxlog_file2,
460
- L: 200,
384
+ L: 210,
461
385
  S: this,
462
386
  C: (f, a) => f(...a)
463
387
  });
@@ -479,7 +403,7 @@ var PluginManager = class {
479
403
  id
480
404
  }, {
481
405
  F: __dxlog_file2,
482
- L: 217,
406
+ L: 227,
483
407
  S: this,
484
408
  C: (f, a) => f(...a)
485
409
  });
@@ -531,7 +455,7 @@ var PluginManager = class {
531
455
  id: plugin.meta.id
532
456
  }, {
533
457
  F: __dxlog_file2,
534
- L: 270,
458
+ L: 280,
535
459
  S: this,
536
460
  C: (f, a) => f(...a)
537
461
  });
@@ -546,7 +470,7 @@ var PluginManager = class {
546
470
  id
547
471
  }, {
548
472
  F: __dxlog_file2,
549
- L: 279,
473
+ L: 290,
550
474
  S: this,
551
475
  C: (f, a) => f(...a)
552
476
  });
@@ -562,7 +486,7 @@ var PluginManager = class {
562
486
  id: module.id
563
487
  }, {
564
488
  F: __dxlog_file2,
565
- L: 289,
489
+ L: 300,
566
490
  S: this,
567
491
  C: (f, a) => f(...a)
568
492
  });
@@ -577,7 +501,7 @@ var PluginManager = class {
577
501
  id
578
502
  }, {
579
503
  F: __dxlog_file2,
580
- L: 298,
504
+ L: 310,
581
505
  S: this,
582
506
  C: (f, a) => f(...a)
583
507
  });
@@ -605,13 +529,13 @@ var PluginManager = class {
605
529
  _setPendingResetByModule(module) {
606
530
  return untracked(() => {
607
531
  const activationEvents = getEvents(module.activatesOn).map(eventKey).filter((key) => this._state.eventsFired.includes(key));
608
- const pendingReset = Array.from(new Set(activationEvents)).filter((event) => !this._state.pendingReset.includes(event));
532
+ const pendingReset = Array.fromIterable(new Set(activationEvents)).filter((event) => !this._state.pendingReset.includes(event));
609
533
  if (pendingReset.length > 0) {
610
534
  log2("pending reset", {
611
535
  events: pendingReset
612
536
  }, {
613
537
  F: __dxlog_file2,
614
- L: 336,
538
+ L: 348,
615
539
  S: this,
616
540
  C: (f, a) => f(...a)
617
541
  });
@@ -623,35 +547,40 @@ var PluginManager = class {
623
547
  * @internal
624
548
  */
625
549
  // TODO(wittjosiah): Improve error typing.
626
- _activate(event) {
550
+ _activate(event, params) {
627
551
  return Effect2.gen(this, function* () {
628
552
  const key = typeof event === "string" ? event : eventKey(event);
629
553
  log2("activating", {
630
- key
554
+ key,
555
+ ...params
631
556
  }, {
632
557
  F: __dxlog_file2,
633
- L: 349,
558
+ L: 364,
634
559
  S: this,
635
560
  C: (f, a) => f(...a)
636
561
  });
562
+ yield* Ref.update(this._activatingEvents, (activating) => Array.append(activating, key));
637
563
  const pendingIndex = this._state.pendingReset.findIndex((event2) => event2 === key);
638
564
  if (pendingIndex !== -1) {
639
565
  this._state.pendingReset.splice(pendingIndex, 1);
640
566
  }
567
+ const activatingEvents = yield* this._activatingEvents;
568
+ const activatingModules = yield* this._activatingModules;
641
569
  const modules = this._getInactiveModulesByEvent(key).filter((module) => {
642
570
  const allOf2 = isAllOf(module.activatesOn);
643
571
  if (!allOf2) {
644
572
  return true;
645
573
  }
646
574
  const events = module.activatesOn.events.filter((event2) => eventKey(event2) !== key);
647
- return events.every((event2) => this._state.eventsFired.includes(eventKey(event2)));
575
+ return events.every((event2) => this._state.eventsFired.includes(eventKey(event2)) || activatingEvents.includes(eventKey(event2))) && !activatingModules.includes(module.id);
648
576
  });
577
+ yield* Ref.update(this._activatingModules, (activating) => Array.appendAll(activating, modules.map((module) => module.id)));
649
578
  if (modules.length === 0) {
650
579
  log2("no modules to activate", {
651
580
  key
652
581
  }, {
653
582
  F: __dxlog_file2,
654
- L: 365,
583
+ L: 395,
655
584
  S: this,
656
585
  C: (f, a) => f(...a)
657
586
  });
@@ -665,7 +594,7 @@ var PluginManager = class {
665
594
  modules: modules.map((module) => module.id)
666
595
  }, {
667
596
  F: __dxlog_file2,
668
- L: 372,
597
+ L: 402,
669
598
  S: this,
670
599
  C: (f, a) => f(...a)
671
600
  });
@@ -673,29 +602,34 @@ var PluginManager = class {
673
602
  event: key,
674
603
  state: "activating"
675
604
  });
676
- const getCapabilities = yield* Effect2.all(modules.map(({ activate }) => Effect2.tryPromise({
677
- try: async () => activate(this.context),
678
- catch: (error) => error
679
- })), {
605
+ 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, {
606
+ before: key
607
+ })), Effect2.allWith({
680
608
  concurrency: "unbounded"
681
- });
682
- const result = yield* pipe(
683
- modules,
684
- A.zip(getCapabilities),
685
- A.map(([module, getCapabilities2]) => this._activateModule(module, getCapabilities2)),
686
- // TODO(wittjosiah): This currently can't be run in parallel.
687
- // Running this with concurrency causes races with `allOf` activation events.
688
- Effect2.all,
689
- Effect2.either
690
- );
691
- if (Either.isLeft(result)) {
609
+ }));
610
+ const getCapabilities = yield* Function.pipe(modules, Array.map((mod) => this._loadModule(mod)), Effect2.allWith({
611
+ concurrency: "unbounded"
612
+ }), Effect2.catchAll((error) => {
692
613
  this.activation.emit({
693
614
  event: key,
694
615
  state: "error",
695
- error: result.left
616
+ error
696
617
  });
697
- yield* Effect2.fail(result.left);
698
- }
618
+ return Effect2.fail(error);
619
+ }));
620
+ yield* Function.pipe(
621
+ modules,
622
+ Array.zip(getCapabilities),
623
+ Array.map(([module, capabilities]) => this._contributeCapabilities(module, capabilities)),
624
+ Effect2.all
625
+ );
626
+ 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, {
627
+ after: key
628
+ })), Effect2.allWith({
629
+ concurrency: "unbounded"
630
+ }));
631
+ yield* Ref.update(this._activatingEvents, (activating) => Array.filter(activating, (event2) => event2 !== key));
632
+ yield* Ref.update(this._activatingModules, (activating) => Array.filter(activating, (module) => !modules.map((module2) => module2.id).includes(module)));
699
633
  if (!this._state.eventsFired.includes(key)) {
700
634
  this._state.eventsFired.push(key);
701
635
  }
@@ -707,39 +641,15 @@ var PluginManager = class {
707
641
  key
708
642
  }, {
709
643
  F: __dxlog_file2,
710
- L: 406,
644
+ L: 458,
711
645
  S: this,
712
646
  C: (f, a) => f(...a)
713
647
  });
714
648
  return true;
715
649
  });
716
650
  }
717
- _activateModule(module, getCapabilities) {
651
+ _contributeCapabilities(module, capabilities) {
718
652
  return Effect2.gen(this, function* () {
719
- yield* Effect2.all(module.activatesBefore?.map((event) => this._activate(event)) ?? [], {
720
- concurrency: "unbounded"
721
- });
722
- log2("activating module...", {
723
- module: module.id
724
- }, {
725
- F: __dxlog_file2,
726
- L: 421,
727
- S: this,
728
- C: (f, a) => f(...a)
729
- });
730
- const maybeCapabilities = typeof getCapabilities === "function" ? getCapabilities() : getCapabilities;
731
- const resolvedCapabilities = yield* Match.value(maybeCapabilities).pipe(
732
- // TODO(wittjosiah): Activate with an effect?
733
- // Match.when(Effect.isEffect, (effect) => effect),
734
- Match.when(isPromise, (promise) => Effect2.tryPromise({
735
- try: () => promise,
736
- catch: (error) => error
737
- })),
738
- Match.orElse((program) => Effect2.succeed(program))
739
- );
740
- const capabilities = Match.value(resolvedCapabilities).pipe(Match.when(Array.isArray, (array) => array), Match.orElse((value) => [
741
- value
742
- ]));
743
653
  capabilities.forEach((capability) => {
744
654
  this.context.contributeCapability({
745
655
  module: module.id,
@@ -748,17 +658,6 @@ var PluginManager = class {
748
658
  });
749
659
  this._state.active.push(module.id);
750
660
  this._capabilities.set(module.id, capabilities);
751
- log2("activated module", {
752
- module: module.id
753
- }, {
754
- F: __dxlog_file2,
755
- L: 444,
756
- S: this,
757
- C: (f, a) => f(...a)
758
- });
759
- yield* Effect2.all(module.activatesAfter?.map((event) => this._activate(event)) ?? [], {
760
- concurrency: "unbounded"
761
- });
762
661
  });
763
662
  }
764
663
  _deactivate(id) {
@@ -781,17 +680,18 @@ var PluginManager = class {
781
680
  id
782
681
  }, {
783
682
  F: __dxlog_file2,
784
- L: 471,
683
+ L: 540,
785
684
  S: this,
786
685
  C: (f, a) => f(...a)
787
686
  });
687
+ this._moduleMemoMap.delete(id);
788
688
  const capabilities = this._capabilities.get(id);
789
689
  if (capabilities) {
790
690
  for (const capability of capabilities) {
791
691
  this.context.removeCapability(capability.interface, capability.implementation);
792
692
  const program = capability.deactivate?.();
793
- yield* Match.value(program).pipe(Match.when(Effect2.isEffect, (effect) => effect), Match.when(isPromise, (promise) => Effect2.tryPromise({
794
- try: () => promise,
693
+ yield* Match.value(program).pipe(Match.when(Effect2.isEffect, (effect) => effect), Match.when(isPromise, (promise2) => Effect2.tryPromise({
694
+ try: () => promise2,
795
695
  catch: (error) => error
796
696
  })), Match.orElse((program2) => Effect2.succeed(program2)));
797
697
  }
@@ -805,7 +705,7 @@ var PluginManager = class {
805
705
  id
806
706
  }, {
807
707
  F: __dxlog_file2,
808
- L: 497,
708
+ L: 567,
809
709
  S: this,
810
710
  C: (f, a) => f(...a)
811
711
  });
@@ -819,7 +719,7 @@ var PluginManager = class {
819
719
  key
820
720
  }, {
821
721
  F: __dxlog_file2,
822
- L: 505,
722
+ L: 575,
823
723
  S: this,
824
724
  C: (f, a) => f(...a)
825
725
  });
@@ -834,11 +734,125 @@ var PluginManager = class {
834
734
  }
835
735
  });
836
736
  }
737
+ constructor({ pluginLoader, plugins = [], core = plugins.map(({ meta: meta2 }) => meta2.id), enabled = [], registry }) {
738
+ _define_property2(this, "activation", new Event());
739
+ _define_property2(this, "context", void 0);
740
+ _define_property2(this, "registry", void 0);
741
+ _define_property2(this, "_state", void 0);
742
+ _define_property2(this, "_pluginLoader", void 0);
743
+ _define_property2(this, "_capabilities", /* @__PURE__ */ new Map());
744
+ _define_property2(this, "_moduleMemoMap", /* @__PURE__ */ new Map());
745
+ _define_property2(this, "_activatingEvents", Effect2.runSync(Ref.make([])));
746
+ _define_property2(this, "_activatingModules", Effect2.runSync(Ref.make([])));
747
+ _define_property2(this, "_loadModule", (mod) => Effect2.tryPromise({
748
+ try: async () => {
749
+ const entry = this._moduleMemoMap.get(mod.id);
750
+ if (entry) {
751
+ return entry;
752
+ }
753
+ const promise2 = (async () => {
754
+ const start = performance.now();
755
+ let failed = false;
756
+ try {
757
+ log2("loading module", {
758
+ module: mod.id
759
+ }, {
760
+ F: __dxlog_file2,
761
+ L: 477,
762
+ S: this,
763
+ C: (f, a) => f(...a)
764
+ });
765
+ let activationResult = await mod.activate(this.context);
766
+ if (typeof activationResult === "function") {
767
+ activationResult = await activationResult();
768
+ }
769
+ return Array.isArray(activationResult) ? activationResult : [
770
+ activationResult
771
+ ];
772
+ } catch (error) {
773
+ failed = true;
774
+ throw error;
775
+ } finally {
776
+ performance.measure("activate-module", {
777
+ start,
778
+ end: performance.now(),
779
+ detail: {
780
+ module: mod.id
781
+ }
782
+ });
783
+ log2("loaded module", {
784
+ module: mod.id,
785
+ elapsed: performance.now() - start,
786
+ failed
787
+ }, {
788
+ F: __dxlog_file2,
789
+ L: 495,
790
+ S: this,
791
+ C: (f, a) => f(...a)
792
+ });
793
+ }
794
+ })();
795
+ this._moduleMemoMap.set(mod.id, promise2);
796
+ return promise2;
797
+ },
798
+ catch: (error) => error
799
+ }).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`, {
800
+ module: mod.id
801
+ }, {
802
+ F: __dxlog_file2,
803
+ L: 506,
804
+ S: this,
805
+ C: (f, a) => f(...a)
806
+ })))))));
807
+ this.registry = registry ?? Registry.make();
808
+ this.context = new PluginContext({
809
+ registry: this.registry,
810
+ activate: (event) => this._activate(event),
811
+ reset: (id) => this._reset(id)
812
+ });
813
+ this._pluginLoader = pluginLoader;
814
+ this._state = live({
815
+ plugins,
816
+ core,
817
+ enabled,
818
+ modules: [],
819
+ active: [],
820
+ eventsFired: [],
821
+ pendingReset: []
822
+ });
823
+ plugins.forEach((plugin) => this._addPlugin(plugin));
824
+ core.forEach((id) => this.enable(id));
825
+ enabled.forEach((id) => this.enable(id));
826
+ }
837
827
  };
828
+ var together = (togetherEffect) => (effect) => Effect2.gen(function* () {
829
+ const togetherFiber = yield* Effect2.fork(togetherEffect);
830
+ const result = yield* effect;
831
+ yield* Fiber.interrupt(togetherFiber);
832
+ return result;
833
+ });
838
834
 
839
835
  // src/core/plugin.ts
836
+ function _define_property3(obj, key, value2) {
837
+ if (key in obj) {
838
+ Object.defineProperty(obj, key, {
839
+ value: value2,
840
+ enumerable: true,
841
+ configurable: true,
842
+ writable: true
843
+ });
844
+ } else {
845
+ obj[key] = value2;
846
+ }
847
+ return obj;
848
+ }
840
849
  var PluginModule = class {
841
850
  constructor(options) {
851
+ _define_property3(this, "id", void 0);
852
+ _define_property3(this, "activatesOn", void 0);
853
+ _define_property3(this, "activatesBefore", void 0);
854
+ _define_property3(this, "activatesAfter", void 0);
855
+ _define_property3(this, "activate", void 0);
842
856
  this.id = options.id;
843
857
  this.activatesOn = options.activatesOn;
844
858
  this.activatesBefore = options.activatesBefore;
@@ -848,13 +862,20 @@ var PluginModule = class {
848
862
  };
849
863
  var defineModule = (options) => new PluginModule(options);
850
864
  var Plugin = class {
851
- constructor(meta, modules) {
852
- this.meta = meta;
865
+ constructor(meta2, modules) {
866
+ _define_property3(this, "meta", void 0);
867
+ _define_property3(this, "modules", void 0);
868
+ this.meta = meta2;
853
869
  this.modules = modules;
854
870
  }
855
871
  };
856
- var definePlugin = (meta, modules) => {
857
- return new Plugin(meta, modules);
872
+ var definePlugin = (meta2, provider) => {
873
+ const factory = (args) => {
874
+ return new Plugin(meta2, provider(args));
875
+ };
876
+ return Object.assign(factory, {
877
+ meta: meta2
878
+ });
858
879
  };
859
880
 
860
881
  // src/common/capabilities.ts
@@ -875,8 +896,11 @@ var definePlugin = (meta, modules) => {
875
896
  Capabilities2.SettingsStore = defineCapability("dxos.org/app-framework/capability/settings-store");
876
897
  Capabilities2.Settings = defineCapability("dxos.org/app-framework/capability/settings");
877
898
  Capabilities2.Metadata = defineCapability("dxos.org/app-framework/capability/metadata");
878
- Capabilities2.Tools = defineCapability("dxos.org/app-framework/capability/tools");
879
- Capabilities2.ArtifactDefinition = defineCapability("dxos.org/app-framework/capability/artifact-definition");
899
+ Capabilities2.Toolkit = defineCapability("dxos.org/app-framework/capability/ai-toolkit");
900
+ Capabilities2.ToolkitHandler = defineCapability("dxos.org/app-framework/capability/ai-toolkit-handler");
901
+ Capabilities2.BlueprintDefinition = defineCapability("dxos.org/app-framework/capability/blueprint-definition");
902
+ Capabilities2.AiServiceLayer = defineCapability("dxos.org/app-framework/capability/ai-service-factory");
903
+ Capabilities2.AiModelResolver = defineCapability("dxos.org/app-framework/capability/ai-model-resolver");
880
904
  Capabilities2.Functions = defineCapability("dxos.org/app-framework/capability/functions");
881
905
  Capabilities2.FileUploader = defineCapability("dxos.org/app-framework/capability/file-uploader");
882
906
  Capabilities2.AnchorSort = defineCapability("dxos.org/app-framework/capability/anchor-sort");
@@ -884,22 +908,19 @@ var definePlugin = (meta, modules) => {
884
908
  var Capabilities;
885
909
 
886
910
  // src/common/collaboration.ts
887
- import { Schema as Schema3 } from "effect";
888
- import { Expando, Ref } from "@dxos/echo-schema";
911
+ import * as Schema from "effect/Schema";
912
+ import { DataType } from "@dxos/schema";
889
913
  (function(CollaborationActions2) {
890
- class InsertContent extends Schema3.TaggedClass()("assistant/intent-content", {
891
- input: Schema3.Struct({
892
- target: Expando,
893
- object: Ref(Expando),
894
- at: Schema3.optional(Schema3.String),
895
- label: Schema3.String.pipe(Schema3.optional)
896
- }).annotations({
897
- description: "Enables plugins to inject content blocks or references into a related entity."
914
+ class AcceptProposal extends Schema.TaggedClass()("collaboration/accept-proposal", {
915
+ input: Schema.Struct({
916
+ subject: Schema.Any,
917
+ anchor: Schema.String,
918
+ proposal: DataType.MessageBlock.Proposal
898
919
  }),
899
- output: Schema3.Void
920
+ output: Schema.Void
900
921
  }) {
901
922
  }
902
- CollaborationActions2.InsertContent = InsertContent;
923
+ CollaborationActions2.AcceptProposal = AcceptProposal;
903
924
  })(CollaborationActions || (CollaborationActions = {}));
904
925
  var CollaborationActions;
905
926
 
@@ -922,7 +943,7 @@ var CollaborationActions;
922
943
  var Events;
923
944
 
924
945
  // src/common/file.ts
925
- import { Schema as Schema4 } from "effect";
946
+ import * as Schema2 from "effect/Schema";
926
947
  var defaultFileTypes = {
927
948
  images: [
928
949
  "png",
@@ -942,23 +963,131 @@ var defaultFileTypes = {
942
963
  "md"
943
964
  ]
944
965
  };
945
- var FileInfoSchema = Schema4.Struct({
946
- name: Schema4.String,
947
- type: Schema4.String,
948
- url: Schema4.optional(Schema4.String),
949
- cid: Schema4.optional(Schema4.String)
966
+ var FileInfoSchema = Schema2.Struct({
967
+ name: Schema2.String,
968
+ type: Schema2.String,
969
+ url: Schema2.optional(Schema2.String),
970
+ cid: Schema2.optional(Schema2.String)
950
971
  });
951
972
 
952
973
  // src/common/layout.ts
953
- import { Schema as Schema5 } from "effect";
974
+ import * as Schema5 from "effect/Schema";
954
975
 
955
- // src/plugin-intent/IntentPlugin.ts
956
- var IntentPlugin = () => definePlugin({
957
- id: INTENT_PLUGIN,
976
+ // src/plugin-intent/actions.ts
977
+ import * as Schema4 from "effect/Schema";
978
+
979
+ // src/plugin-intent/intent.ts
980
+ import * as Schema3 from "effect/Schema";
981
+ var createIntent = (schema, data = {}, params = {}) => {
982
+ const _ = Schema3.validateSync(schema.fields.input)(data);
983
+ const intent = {
984
+ ...params,
985
+ _schema: schema,
986
+ id: schema._tag,
987
+ data
988
+ };
989
+ return {
990
+ first: intent,
991
+ last: intent,
992
+ all: [
993
+ intent
994
+ ]
995
+ };
996
+ };
997
+ var chain = (schema, data = {}, params = {}) => (intent) => {
998
+ const intents = "all" in intent ? intent.all : [
999
+ intent
1000
+ ];
1001
+ const first = intents[0];
1002
+ const last = {
1003
+ ...params,
1004
+ _schema: schema,
1005
+ id: schema._tag,
1006
+ data
1007
+ };
1008
+ return {
1009
+ first,
1010
+ last,
1011
+ all: [
1012
+ ...intents,
1013
+ last
1014
+ ]
1015
+ };
1016
+ };
1017
+ var Label = Schema3.Union(Schema3.String, Schema3.mutable(Schema3.Tuple(Schema3.String, Schema3.mutable(Schema3.Struct({
1018
+ ns: Schema3.String,
1019
+ count: Schema3.optional(Schema3.Number),
1020
+ defaultValue: Schema3.optional(Schema3.String)
1021
+ })))));
1022
+
1023
+ // src/plugin-intent/meta.ts
1024
+ var meta = {
1025
+ id: "dxos.org/plugin/intent",
958
1026
  name: "Intent"
959
- }, [
1027
+ };
1028
+
1029
+ // src/plugin-intent/actions.ts
1030
+ (function(IntentAction2) {
1031
+ class Track extends Schema4.TaggedClass()(`${meta.id}/action/track`, {
1032
+ input: Schema4.Struct({
1033
+ intents: Schema4.Array(Schema4.String),
1034
+ error: Schema4.optional(Schema4.String)
1035
+ }),
1036
+ output: Schema4.Void
1037
+ }) {
1038
+ }
1039
+ IntentAction2.Track = Track;
1040
+ class ShowUndo extends Schema4.TaggedClass()(`${meta.id}/action/show-undo`, {
1041
+ input: Schema4.Struct({
1042
+ message: Label
1043
+ }),
1044
+ output: Schema4.Void
1045
+ }) {
1046
+ }
1047
+ IntentAction2.ShowUndo = ShowUndo;
1048
+ })(IntentAction || (IntentAction = {}));
1049
+ var IntentAction;
1050
+
1051
+ // src/plugin-intent/errors.ts
1052
+ function _define_property4(obj, key, value2) {
1053
+ if (key in obj) {
1054
+ Object.defineProperty(obj, key, {
1055
+ value: value2,
1056
+ enumerable: true,
1057
+ configurable: true,
1058
+ writable: true
1059
+ });
1060
+ } else {
1061
+ obj[key] = value2;
1062
+ }
1063
+ return obj;
1064
+ }
1065
+ var BaseError = class extends Error {
1066
+ constructor(code, message, context) {
1067
+ super(message ?? code, {
1068
+ cause: context
1069
+ }), _define_property4(this, "code", void 0), _define_property4(this, "context", void 0), this.code = code, this.context = context;
1070
+ this.name = code;
1071
+ Object.setPrototypeOf(this, new.target.prototype);
1072
+ }
1073
+ };
1074
+ var NoResolversError = class extends BaseError {
1075
+ constructor(action) {
1076
+ super("NO_RESOLVERS", "No resolvers were found for the action", {
1077
+ action
1078
+ });
1079
+ }
1080
+ };
1081
+ var CycleDetectedError = class extends BaseError {
1082
+ constructor(context) {
1083
+ super("CYCLE_DETECTED", "Intent execution limit exceeded. This is likely due to an infinite loop within intent resolvers.", context);
1084
+ }
1085
+ };
1086
+
1087
+ // src/plugin-intent/IntentPlugin.ts
1088
+ var IntentPlugin = definePlugin(meta, () => [
960
1089
  defineModule({
961
- id: `${INTENT_PLUGIN}/module/dispatcher`,
1090
+ id: `${meta.id}/module/dispatcher`,
962
1091
  // TODO(wittjosiah): This will mean that startup needs to be reset when intents are added or removed.
963
1092
  // This is fine for now because it's how it worked prior to capabilities api anyways.
964
1093
  // In the future, the intent dispatcher should be able to be reset without resetting the entire app.
@@ -966,15 +1095,14 @@ var IntentPlugin = () => definePlugin({
966
1095
  activatesAfter: [
967
1096
  Events.DispatcherReady
968
1097
  ],
969
- activate: lazy(() => import("./intent-dispatcher-LSYQZSEB.mjs"))
1098
+ activate: lazy(() => import("./intent-dispatcher-Y4LZNOBC.mjs"))
970
1099
  })
971
1100
  ]);
972
1101
 
973
1102
  // src/common/layout.ts
974
1103
  var LAYOUT_PLUGIN = "dxos.org/plugin/layout";
975
- var LAYOUT_ACTION = `${LAYOUT_PLUGIN}/action`;
976
1104
  (function(LayoutAction2) {
977
- LayoutAction2.UPDATE_LAYOUT = `${LAYOUT_ACTION}/update-layout`;
1105
+ LayoutAction2.UPDATE_LAYOUT = `${LAYOUT_PLUGIN}/action/update-layout`;
978
1106
  class UpdateLayout extends Schema5.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
979
1107
  input: Schema5.Struct({
980
1108
  part: Schema5.String.annotations({
@@ -1311,7 +1439,7 @@ var LayoutAction;
1311
1439
  var createSurface = (definition) => definition;
1312
1440
 
1313
1441
  // src/common/translations.ts
1314
- import { Schema as Schema6 } from "effect";
1442
+ import * as Schema6 from "effect/Schema";
1315
1443
  var ResourceKey = Schema6.Union(Schema6.String, Schema6.Record({
1316
1444
  key: Schema6.String,
1317
1445
  value: Schema6.Any
@@ -1336,7 +1464,7 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1336
1464
  const handleIntent = (intent) => Effect3.gen(function* () {
1337
1465
  const candidates = getResolvers().filter((resolver) => resolver.intent._tag === intent.id).filter((resolver) => !resolver.filter || resolver.filter(intent.data)).toSorted(byPosition);
1338
1466
  if (candidates.length === 0) {
1339
- yield* Effect3.fail(new NoResolversError(intent.id));
1467
+ return yield* Effect3.fail(new NoResolversError(intent.id));
1340
1468
  }
1341
1469
  const effect = candidates[0].resolve(intent.data, intent.undo ?? false);
1342
1470
  const result = Effect3.isEffect(effect) ? yield* effect : yield* Effect3.promise(async () => effect);
@@ -1348,7 +1476,7 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1348
1476
  const dispatch = (intentChain, depth = 0) => {
1349
1477
  return Effect3.gen(function* () {
1350
1478
  if (depth > executionLimit) {
1351
- yield* Effect3.fail(new CycleDetectedError());
1479
+ return yield* Effect3.fail(new CycleDetectedError());
1352
1480
  }
1353
1481
  const resultsRef = yield* Ref2.make([]);
1354
1482
  for (const intent of intentChain.all) {
@@ -1370,7 +1498,7 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1370
1498
  }
1371
1499
  }
1372
1500
  if (result2.error) {
1373
- yield* Effect3.fail(result2.error);
1501
+ return yield* Effect3.fail(result2.error);
1374
1502
  }
1375
1503
  }
1376
1504
  const results = yield* resultsRef.get;
@@ -1386,7 +1514,7 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1386
1514
  return next;
1387
1515
  });
1388
1516
  if (result.undoable && isUndoable(results)) {
1389
- yield* pipe2(dispatch(createIntent(IntentAction.ShowUndo, {
1517
+ yield* Function2.pipe(dispatch(createIntent(IntentAction.ShowUndo, {
1390
1518
  message: result.undoable.message
1391
1519
  })), Effect3.catchSome((err) => err instanceof NoResolversError ? Option.some(Effect3.succeed(void 0)) : Option.none()));
1392
1520
  }
@@ -1399,7 +1527,7 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1399
1527
  })).catch((error) => {
1400
1528
  log3.catch(error, void 0, {
1401
1529
  F: __dxlog_file3,
1402
- L: 270,
1530
+ L: 274,
1403
1531
  S: void 0,
1404
1532
  C: (f, a) => f(...a)
1405
1533
  });
@@ -1414,7 +1542,7 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1414
1542
  const last = history.findLastIndex(isUndoable);
1415
1543
  const result = last !== -1 ? history[last] : void 0;
1416
1544
  if (result) {
1417
- const all = result.map(({ _intent, undoable }) => {
1545
+ const all2 = result.map(({ _intent, undoable }) => {
1418
1546
  const data = _intent.data;
1419
1547
  const undoData = undoable?.data ?? {};
1420
1548
  return {
@@ -1427,9 +1555,9 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1427
1555
  };
1428
1556
  });
1429
1557
  const intent = {
1430
- first: all[0],
1431
- last: all.at(-1),
1432
- all
1558
+ first: all2[0],
1559
+ last: all2.at(-1),
1560
+ all: all2
1433
1561
  };
1434
1562
  yield* Ref2.update(historyRef, (h) => h.filter((_, index) => index !== last));
1435
1563
  return yield* dispatch(intent);
@@ -1452,7 +1580,7 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1452
1580
  };
1453
1581
  var defaultEffect = () => Effect3.fail(new Error("Intent runtime not ready"));
1454
1582
  var defaultPromise = () => Effect3.runPromise(defaultEffect());
1455
- var intent_dispatcher_default = (context) => {
1583
+ var intent_dispatcher_default = ((context) => {
1456
1584
  const state = live2({
1457
1585
  dispatch: defaultEffect,
1458
1586
  dispatchPromise: defaultPromise,
@@ -1474,7 +1602,7 @@ var intent_dispatcher_default = (context) => {
1474
1602
  state.undo = undo;
1475
1603
  state.undoPromise = undoPromise;
1476
1604
  return contributes(Capabilities.IntentDispatcher, state);
1477
- };
1605
+ });
1478
1606
 
1479
1607
  export {
1480
1608
  defineCapability,
@@ -1501,19 +1629,18 @@ export {
1501
1629
  createIntent,
1502
1630
  chain,
1503
1631
  Label,
1504
- INTENT_PLUGIN,
1505
- INTENT_ACTION,
1506
1632
  IntentAction,
1633
+ BaseError,
1634
+ NoResolversError,
1635
+ CycleDetectedError,
1507
1636
  createResolver,
1508
1637
  createDispatcher,
1509
1638
  intent_dispatcher_default,
1510
1639
  IntentPlugin,
1511
- LAYOUT_PLUGIN,
1512
- LAYOUT_ACTION,
1513
1640
  LayoutAction,
1514
1641
  createSurface,
1515
1642
  ResourceKey,
1516
1643
  ResourceLanguage,
1517
1644
  Resource
1518
1645
  };
1519
- //# sourceMappingURL=chunk-FMN65HSW.mjs.map
1646
+ //# sourceMappingURL=chunk-OKF2PAWO.mjs.map