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