@dxos/app-framework 0.7.5-main.9d2a38b → 0.7.5-main.e94eead

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 (205) hide show
  1. package/dist/lib/browser/app-graph-builder-S4MYSHQA.mjs +137 -0
  2. package/dist/lib/browser/app-graph-builder-S4MYSHQA.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-GNLU3GAU.mjs → chunk-BCMEJONP.mjs} +660 -823
  4. package/dist/lib/browser/chunk-BCMEJONP.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-QS4J6O47.mjs +285 -0
  6. package/dist/lib/browser/chunk-QS4J6O47.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-SRZH2PQ2.mjs +32 -0
  8. package/dist/lib/browser/chunk-SRZH2PQ2.mjs.map +7 -0
  9. package/dist/lib/browser/index.mjs +57 -74
  10. package/dist/lib/browser/index.mjs.map +4 -4
  11. package/dist/lib/browser/intent-dispatcher-GFBH7T2J.mjs +11 -0
  12. package/dist/lib/browser/intent-dispatcher-GFBH7T2J.mjs.map +7 -0
  13. package/dist/lib/browser/intent-resolver-KAFM7CQH.mjs +39 -0
  14. package/dist/lib/browser/intent-resolver-KAFM7CQH.mjs.map +7 -0
  15. package/dist/lib/browser/meta.json +1 -1
  16. package/dist/lib/browser/store-L3VRR7II.mjs +29 -0
  17. package/dist/lib/browser/store-L3VRR7II.mjs.map +7 -0
  18. package/dist/lib/browser/testing/index.mjs +13 -3
  19. package/dist/lib/browser/testing/index.mjs.map +3 -3
  20. package/dist/lib/browser/worker.mjs +77 -0
  21. package/dist/lib/browser/worker.mjs.map +7 -0
  22. package/dist/lib/node/app-graph-builder-VMHWFCTP.cjs +146 -0
  23. package/dist/lib/node/app-graph-builder-VMHWFCTP.cjs.map +7 -0
  24. package/dist/lib/node/chunk-7Y6KJ3OK.cjs +1466 -0
  25. package/dist/lib/node/chunk-7Y6KJ3OK.cjs.map +7 -0
  26. package/dist/lib/node/chunk-B65NJEIJ.cjs +308 -0
  27. package/dist/lib/node/chunk-B65NJEIJ.cjs.map +7 -0
  28. package/dist/lib/node/chunk-VCIHQZSN.cjs +58 -0
  29. package/dist/lib/node/chunk-VCIHQZSN.cjs.map +7 -0
  30. package/dist/lib/node/index.cjs +106 -118
  31. package/dist/lib/node/index.cjs.map +4 -4
  32. package/dist/lib/node/intent-dispatcher-PRCC4KZT.cjs +32 -0
  33. package/dist/lib/node/intent-dispatcher-PRCC4KZT.cjs.map +7 -0
  34. package/dist/lib/node/intent-resolver-OZDKCHPW.cjs +46 -0
  35. package/dist/lib/node/intent-resolver-OZDKCHPW.cjs.map +7 -0
  36. package/dist/lib/node/meta.json +1 -1
  37. package/dist/lib/node/store-BVUKNVKL.cjs +44 -0
  38. package/dist/lib/node/store-BVUKNVKL.cjs.map +7 -0
  39. package/dist/lib/node/testing/index.cjs +18 -8
  40. package/dist/lib/node/testing/index.cjs.map +3 -3
  41. package/dist/lib/node/worker.cjs +99 -0
  42. package/dist/lib/node/worker.cjs.map +7 -0
  43. package/dist/lib/node-esm/app-graph-builder-XHI5IIXQ.mjs +138 -0
  44. package/dist/lib/node-esm/app-graph-builder-XHI5IIXQ.mjs.map +7 -0
  45. package/dist/lib/node-esm/chunk-CBT75GCX.mjs +34 -0
  46. package/dist/lib/node-esm/chunk-CBT75GCX.mjs.map +7 -0
  47. package/dist/lib/node-esm/chunk-JDAHZRYQ.mjs +286 -0
  48. package/dist/lib/node-esm/chunk-JDAHZRYQ.mjs.map +7 -0
  49. package/dist/lib/node-esm/{chunk-KPMTPXQI.mjs → chunk-TVIR2PHY.mjs} +660 -823
  50. package/dist/lib/node-esm/chunk-TVIR2PHY.mjs.map +7 -0
  51. package/dist/lib/node-esm/index.mjs +57 -74
  52. package/dist/lib/node-esm/index.mjs.map +4 -4
  53. package/dist/lib/node-esm/intent-dispatcher-LGACN32C.mjs +12 -0
  54. package/dist/lib/node-esm/intent-dispatcher-LGACN32C.mjs.map +7 -0
  55. package/dist/lib/node-esm/intent-resolver-RBNG76ZX.mjs +40 -0
  56. package/dist/lib/node-esm/intent-resolver-RBNG76ZX.mjs.map +7 -0
  57. package/dist/lib/node-esm/meta.json +1 -1
  58. package/dist/lib/node-esm/store-PHTOEREN.mjs +30 -0
  59. package/dist/lib/node-esm/store-PHTOEREN.mjs.map +7 -0
  60. package/dist/lib/node-esm/testing/index.mjs +13 -3
  61. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  62. package/dist/lib/node-esm/worker.mjs +78 -0
  63. package/dist/lib/node-esm/worker.mjs.map +7 -0
  64. package/dist/types/src/App.d.ts +2 -2
  65. package/dist/types/src/App.d.ts.map +1 -1
  66. package/dist/types/src/common/capabilities.d.ts +88 -124
  67. package/dist/types/src/common/capabilities.d.ts.map +1 -1
  68. package/dist/types/src/common/events.d.ts +22 -11
  69. package/dist/types/src/common/events.d.ts.map +1 -1
  70. package/dist/types/src/common/file.d.ts +1 -1
  71. package/dist/types/src/common/file.d.ts.map +1 -1
  72. package/dist/types/src/common/graph.d.ts +2 -2
  73. package/dist/types/src/common/graph.d.ts.map +1 -1
  74. package/dist/types/src/common/index.d.ts +0 -1
  75. package/dist/types/src/common/index.d.ts.map +1 -1
  76. package/dist/types/src/common/layout.d.ts +218 -121
  77. package/dist/types/src/common/layout.d.ts.map +1 -1
  78. package/dist/types/src/common/surface.d.ts +3 -3
  79. package/dist/types/src/common/surface.d.ts.map +1 -1
  80. package/dist/types/src/common/translations.d.ts +7 -7
  81. package/dist/types/src/common/translations.d.ts.map +1 -1
  82. package/dist/types/src/core/capabilities.d.ts +6 -2
  83. package/dist/types/src/core/capabilities.d.ts.map +1 -1
  84. package/dist/types/src/core/manager.d.ts +2 -9
  85. package/dist/types/src/core/manager.d.ts.map +1 -1
  86. package/dist/types/src/core/plugin.d.ts +5 -2
  87. package/dist/types/src/core/plugin.d.ts.map +1 -1
  88. package/dist/types/src/playground/debug/Debug.d.ts +2 -3
  89. package/dist/types/src/playground/debug/Debug.d.ts.map +1 -1
  90. package/dist/types/src/playground/debug/plugin.d.ts +1 -1
  91. package/dist/types/src/playground/debug/plugin.d.ts.map +1 -1
  92. package/dist/types/src/playground/generator/Main.d.ts +2 -3
  93. package/dist/types/src/playground/generator/Main.d.ts.map +1 -1
  94. package/dist/types/src/playground/generator/Toolbar.d.ts +2 -3
  95. package/dist/types/src/playground/generator/Toolbar.d.ts.map +1 -1
  96. package/dist/types/src/playground/generator/generator.d.ts +5 -3
  97. package/dist/types/src/playground/generator/generator.d.ts.map +1 -1
  98. package/dist/types/src/playground/generator/plugin.d.ts +1 -1
  99. package/dist/types/src/playground/generator/plugin.d.ts.map +1 -1
  100. package/dist/types/src/playground/layout/Layout.d.ts +2 -2
  101. package/dist/types/src/playground/layout/Layout.d.ts.map +1 -1
  102. package/dist/types/src/playground/layout/plugin.d.ts +1 -1
  103. package/dist/types/src/playground/layout/plugin.d.ts.map +1 -1
  104. package/dist/types/src/playground/logger/Toolbar.d.ts +2 -3
  105. package/dist/types/src/playground/logger/Toolbar.d.ts.map +1 -1
  106. package/dist/types/src/playground/logger/plugin.d.ts +1 -1
  107. package/dist/types/src/playground/logger/plugin.d.ts.map +1 -1
  108. package/dist/types/src/playground/logger/schema.d.ts +1 -1
  109. package/dist/types/src/playground/logger/schema.d.ts.map +1 -1
  110. package/dist/types/src/playground/playground.stories.d.ts +2 -3
  111. package/dist/types/src/playground/playground.stories.d.ts.map +1 -1
  112. package/dist/types/src/plugin-intent/IntentPlugin.d.ts +1 -1
  113. package/dist/types/src/plugin-intent/IntentPlugin.d.ts.map +1 -1
  114. package/dist/types/src/plugin-intent/actions.d.ts +1 -1
  115. package/dist/types/src/plugin-intent/actions.d.ts.map +1 -1
  116. package/dist/types/src/plugin-intent/index.d.ts +0 -1
  117. package/dist/types/src/plugin-intent/index.d.ts.map +1 -1
  118. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts +27 -20
  119. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts.map +1 -1
  120. package/dist/types/src/plugin-intent/intent.d.ts +3 -3
  121. package/dist/types/src/plugin-intent/intent.d.ts.map +1 -1
  122. package/dist/types/src/plugin-settings/SettingsPlugin.d.ts +1 -1
  123. package/dist/types/src/plugin-settings/SettingsPlugin.d.ts.map +1 -1
  124. package/dist/types/src/plugin-settings/actions.d.ts +11 -1
  125. package/dist/types/src/plugin-settings/actions.d.ts.map +1 -1
  126. package/dist/types/src/plugin-settings/app-graph-builder.d.ts +197 -0
  127. package/dist/types/src/plugin-settings/app-graph-builder.d.ts.map +1 -0
  128. package/dist/types/src/plugin-settings/intent-resolver.d.ts +4 -0
  129. package/dist/types/src/plugin-settings/intent-resolver.d.ts.map +1 -0
  130. package/dist/types/src/plugin-settings/store.d.ts +5 -0
  131. package/dist/types/src/plugin-settings/store.d.ts.map +1 -0
  132. package/dist/types/src/plugin-settings/translations.d.ts +11 -0
  133. package/dist/types/src/plugin-settings/translations.d.ts.map +1 -0
  134. package/dist/types/src/react/ErrorBoundary.d.ts +1 -1
  135. package/dist/types/src/{plugin-intent → react}/IntentContext.d.ts +1 -1
  136. package/dist/types/src/react/IntentContext.d.ts.map +1 -0
  137. package/dist/types/src/react/Surface.d.ts.map +1 -1
  138. package/dist/types/src/react/Surface.stories.d.ts +15 -0
  139. package/dist/types/src/react/Surface.stories.d.ts.map +1 -0
  140. package/dist/types/src/react/common.d.ts +13 -0
  141. package/dist/types/src/react/common.d.ts.map +1 -0
  142. package/dist/types/src/react/index.d.ts +2 -0
  143. package/dist/types/src/react/index.d.ts.map +1 -1
  144. package/dist/types/src/react/useCapabilities.d.ts.map +1 -1
  145. package/dist/types/src/react/useIntentResolver.d.ts +3 -0
  146. package/dist/types/src/react/useIntentResolver.d.ts.map +1 -0
  147. package/dist/types/src/testing/withPluginManager.d.ts +6 -4
  148. package/dist/types/src/testing/withPluginManager.d.ts.map +1 -1
  149. package/dist/types/src/worker.d.ts +4 -0
  150. package/dist/types/src/worker.d.ts.map +1 -0
  151. package/package.json +29 -21
  152. package/project.json +4 -3
  153. package/src/App.tsx +17 -15
  154. package/src/common/capabilities.ts +30 -11
  155. package/src/common/events.ts +16 -2
  156. package/src/common/file.ts +1 -1
  157. package/src/common/graph.ts +2 -2
  158. package/src/common/index.ts +0 -1
  159. package/src/common/layout.ts +207 -126
  160. package/src/common/surface.ts +2 -2
  161. package/src/common/translations.ts +7 -8
  162. package/src/core/capabilities.ts +16 -7
  163. package/src/core/manager.test.ts +22 -73
  164. package/src/core/manager.ts +105 -91
  165. package/src/core/plugin.ts +6 -3
  166. package/src/playground/debug/plugin.ts +1 -1
  167. package/src/playground/generator/Toolbar.tsx +11 -11
  168. package/src/playground/generator/generator.ts +25 -0
  169. package/src/playground/generator/plugin.ts +6 -1
  170. package/src/playground/layout/plugin.ts +1 -1
  171. package/src/playground/logger/Toolbar.tsx +2 -1
  172. package/src/playground/logger/plugin.ts +7 -4
  173. package/src/playground/logger/schema.ts +1 -1
  174. package/src/plugin-intent/IntentPlugin.tsx +3 -43
  175. package/src/plugin-intent/actions.ts +1 -1
  176. package/src/plugin-intent/errors.ts +1 -1
  177. package/src/plugin-intent/index.ts +0 -1
  178. package/src/plugin-intent/intent-dispatcher.test.ts +48 -29
  179. package/src/plugin-intent/intent-dispatcher.ts +81 -42
  180. package/src/plugin-intent/intent.ts +5 -5
  181. package/src/plugin-settings/SettingsPlugin.ts +19 -13
  182. package/src/plugin-settings/actions.ts +11 -1
  183. package/src/plugin-settings/app-graph-builder.ts +122 -0
  184. package/src/plugin-settings/intent-resolver.ts +34 -0
  185. package/src/plugin-settings/store.ts +30 -0
  186. package/src/plugin-settings/translations.ts +17 -0
  187. package/src/{plugin-intent → react}/IntentContext.tsx +2 -2
  188. package/src/react/Surface.stories.tsx +96 -0
  189. package/src/react/Surface.tsx +11 -8
  190. package/src/react/common.ts +12 -0
  191. package/src/react/index.ts +2 -0
  192. package/src/react/useCapabilities.ts +1 -0
  193. package/src/react/useIntentResolver.ts +22 -0
  194. package/src/testing/withPluginManager.tsx +28 -4
  195. package/src/worker.ts +11 -0
  196. package/tsconfig.json +7 -13
  197. package/dist/lib/browser/chunk-GNLU3GAU.mjs.map +0 -7
  198. package/dist/lib/node/chunk-FBA4BB3J.cjs +0 -1639
  199. package/dist/lib/node/chunk-FBA4BB3J.cjs.map +0 -7
  200. package/dist/lib/node-esm/chunk-KPMTPXQI.mjs.map +0 -7
  201. package/dist/types/src/common/navigation.d.ts +0 -241
  202. package/dist/types/src/common/navigation.d.ts.map +0 -1
  203. package/dist/types/src/plugin-intent/IntentContext.d.ts.map +0 -1
  204. package/src/common/navigation.ts +0 -199
  205. /package/{.eslintrc.js → .eslintrc.cjs} +0 -0
@@ -0,0 +1,1466 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var chunk_7Y6KJ3OK_exports = {};
30
+ __export(chunk_7Y6KJ3OK_exports, {
31
+ Capabilities: () => Capabilities,
32
+ Events: () => Events,
33
+ FileInfoSchema: () => FileInfoSchema,
34
+ INTENT_ACTION: () => INTENT_ACTION,
35
+ INTENT_PLUGIN: () => INTENT_PLUGIN,
36
+ IntentAction: () => IntentAction,
37
+ IntentPlugin: () => IntentPlugin,
38
+ LAYOUT_ACTION: () => LAYOUT_ACTION,
39
+ LAYOUT_PLUGIN: () => LAYOUT_PLUGIN,
40
+ Label: () => Label,
41
+ LayoutAction: () => LayoutAction,
42
+ Plugin: () => Plugin,
43
+ PluginManager: () => PluginManager,
44
+ PluginModule: () => PluginModule,
45
+ PluginsContext: () => PluginsContext,
46
+ Resource: () => Resource,
47
+ ResourceKey: () => ResourceKey,
48
+ ResourceLanguage: () => ResourceLanguage,
49
+ allOf: () => allOf,
50
+ chain: () => chain,
51
+ contributes: () => contributes,
52
+ createDispatcher: () => createDispatcher,
53
+ createIntent: () => createIntent,
54
+ createResolver: () => createResolver,
55
+ createSurface: () => createSurface,
56
+ defaultFileTypes: () => defaultFileTypes,
57
+ defineCapability: () => defineCapability,
58
+ defineEvent: () => defineEvent,
59
+ defineModule: () => defineModule,
60
+ definePlugin: () => definePlugin,
61
+ eventKey: () => eventKey,
62
+ getEvents: () => getEvents,
63
+ intent_dispatcher_default: () => intent_dispatcher_default,
64
+ isAllOf: () => isAllOf,
65
+ isOneOf: () => isOneOf,
66
+ lazy: () => lazy,
67
+ oneOf: () => oneOf
68
+ });
69
+ module.exports = __toCommonJS(chunk_7Y6KJ3OK_exports);
70
+ var import_effect = require("effect");
71
+ var import_live_object = require("@dxos/live-object");
72
+ var import_log = require("@dxos/log");
73
+ var import_util = require("@dxos/util");
74
+ var import_schema = require("@effect/schema");
75
+ var import_schema2 = require("@effect/schema");
76
+ var import_signals_core = require("@preact/signals-core");
77
+ var import_async = require("@dxos/async");
78
+ var import_invariant = require("@dxos/invariant");
79
+ var import_live_object2 = require("@dxos/live-object");
80
+ var import_log2 = require("@dxos/log");
81
+ var import_signals_core2 = require("@preact/signals-core");
82
+ var import_effect2 = require("effect");
83
+ var import_async2 = require("@dxos/async");
84
+ var import_live_object3 = require("@dxos/live-object");
85
+ var import_log3 = require("@dxos/log");
86
+ var import_schema3 = require("@effect/schema");
87
+ var import_schema4 = require("@effect/schema");
88
+ var import_schema5 = require("@effect/schema");
89
+ var createIntent = (schema, data = {}, params = {}) => {
90
+ const _ = import_schema2.Schema.validateSync(schema.fields.input)(data);
91
+ const intent = {
92
+ ...params,
93
+ _schema: schema,
94
+ id: schema._tag,
95
+ data
96
+ };
97
+ return {
98
+ first: intent,
99
+ last: intent,
100
+ all: [
101
+ intent
102
+ ]
103
+ };
104
+ };
105
+ var chain = (schema, data = {}, params = {}) => (intent) => {
106
+ const intents = "all" in intent ? intent.all : [
107
+ intent
108
+ ];
109
+ const first = intents[0];
110
+ const last = {
111
+ ...params,
112
+ _schema: schema,
113
+ id: schema._tag,
114
+ data
115
+ };
116
+ return {
117
+ first,
118
+ last,
119
+ all: [
120
+ ...intents,
121
+ last
122
+ ]
123
+ };
124
+ };
125
+ var Label = import_schema2.Schema.Union(import_schema2.Schema.String, import_schema2.Schema.mutable(import_schema2.Schema.Tuple(import_schema2.Schema.String, import_schema2.Schema.mutable(import_schema2.Schema.Struct({
126
+ ns: import_schema2.Schema.String,
127
+ count: import_schema2.Schema.optional(import_schema2.Schema.Number)
128
+ })))));
129
+ var INTENT_PLUGIN = "dxos.org/plugin/intent";
130
+ var INTENT_ACTION = `${INTENT_PLUGIN}/action`;
131
+ var IntentAction;
132
+ (function(IntentAction2) {
133
+ class ShowUndo extends import_schema.Schema.TaggedClass()(`${INTENT_ACTION}/show-undo`, {
134
+ input: import_schema.Schema.Struct({
135
+ message: Label
136
+ }),
137
+ output: import_schema.Schema.Void
138
+ }) {
139
+ }
140
+ IntentAction2.ShowUndo = ShowUndo;
141
+ })(IntentAction || (IntentAction = {}));
142
+ var BaseError = class extends Error {
143
+ constructor(code, message, context) {
144
+ super(message ?? code, {
145
+ cause: context
146
+ });
147
+ this.code = code;
148
+ this.context = context;
149
+ this.name = code;
150
+ Object.setPrototypeOf(this, new.target.prototype);
151
+ }
152
+ };
153
+ var NoResolversError = class extends BaseError {
154
+ constructor(action) {
155
+ super("NO_RESOLVERS", "No resolvers were found for the action", {
156
+ action
157
+ });
158
+ }
159
+ };
160
+ var CycleDetectedError = class extends BaseError {
161
+ constructor(context) {
162
+ super("CYCLE_DETECTED", "Intent execution limit exceeded. This is likely due to an infinite loop within intent resolvers.", context);
163
+ }
164
+ };
165
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/core/capabilities.ts";
166
+ var InterfaceDefTypeId = Symbol.for("InterfaceDefTypeId");
167
+ var defineCapability = (identifier) => {
168
+ return {
169
+ identifier
170
+ };
171
+ };
172
+ var CapabilityImpl = class {
173
+ constructor(moduleId, implementation) {
174
+ this.moduleId = moduleId;
175
+ this.implementation = implementation;
176
+ }
177
+ };
178
+ var contributes = (interfaceDef, implementation, deactivate) => {
179
+ return {
180
+ interface: interfaceDef,
181
+ implementation,
182
+ deactivate
183
+ };
184
+ };
185
+ var lazy = (c) => async (props) => {
186
+ const { default: getCapability } = await c();
187
+ return async () => getCapability(props);
188
+ };
189
+ var PluginsContext = class {
190
+ constructor({ activate, reset }) {
191
+ this._definedCapabilities = /* @__PURE__ */ new Map();
192
+ this.activate = activate;
193
+ this.reset = reset;
194
+ }
195
+ /**
196
+ * @internal
197
+ */
198
+ contributeCapability({ module: moduleId, interface: interfaceDef, implementation }) {
199
+ let current = this._definedCapabilities.get(interfaceDef.identifier);
200
+ if (!current) {
201
+ const object = (0, import_live_object2.create)({
202
+ value: []
203
+ });
204
+ current = (0, import_signals_core.untracked)(() => object.value);
205
+ this._definedCapabilities.set(interfaceDef.identifier, current);
206
+ }
207
+ current.push(new CapabilityImpl(moduleId, implementation));
208
+ (0, import_log2.log)("capability contributed", {
209
+ id: interfaceDef.identifier,
210
+ moduleId,
211
+ count: (0, import_signals_core.untracked)(() => current.length)
212
+ }, {
213
+ F: __dxlog_file,
214
+ L: 142,
215
+ S: this,
216
+ C: (f, a) => f(...a)
217
+ });
218
+ }
219
+ /**
220
+ * @internal
221
+ */
222
+ removeCapability(interfaceDef, implementation) {
223
+ const current = this._definedCapabilities.get(interfaceDef.identifier);
224
+ if (!current) {
225
+ return;
226
+ }
227
+ const index = current.findIndex((i) => i.implementation === implementation);
228
+ if (index !== -1) {
229
+ current.splice(index, 1);
230
+ (0, import_log2.log)("capability removed", {
231
+ id: interfaceDef.identifier,
232
+ count: (0, import_signals_core.untracked)(() => current.length)
233
+ }, {
234
+ F: __dxlog_file,
235
+ L: 161,
236
+ S: this,
237
+ C: (f, a) => f(...a)
238
+ });
239
+ } else {
240
+ import_log2.log.warn("capability not removed", {
241
+ id: interfaceDef.identifier
242
+ }, {
243
+ F: __dxlog_file,
244
+ L: 163,
245
+ S: this,
246
+ C: (f, a) => f(...a)
247
+ });
248
+ }
249
+ }
250
+ /**
251
+ * Requests capabilities from the plugin context.
252
+ * @returns An array of capabilities.
253
+ * @reactive
254
+ */
255
+ requestCapabilities(interfaceDef, filter) {
256
+ let current = this._definedCapabilities.get(interfaceDef.identifier);
257
+ if (!current) {
258
+ const object = (0, import_live_object2.create)({
259
+ value: []
260
+ });
261
+ current = (0, import_signals_core.untracked)(() => object.value);
262
+ this._definedCapabilities.set(interfaceDef.identifier, current);
263
+ }
264
+ const capabilities = filter ? current.filter((c) => filter(c.implementation, c.moduleId)) : current;
265
+ return capabilities.map((c) => c.implementation);
266
+ }
267
+ /**
268
+ * Requests a single capability from the plugin context.
269
+ * @returns The capability.
270
+ * @throws If no capability is found.
271
+ * @reactive
272
+ */
273
+ requestCapability(interfaceDef, filter) {
274
+ const capability = this.requestCapabilities(interfaceDef, filter)[0];
275
+ (0, import_invariant.invariant)(capability, `No capability found for ${interfaceDef.identifier}`, {
276
+ F: __dxlog_file,
277
+ L: 199,
278
+ S: this,
279
+ A: [
280
+ "capability",
281
+ "`No capability found for ${interfaceDef.identifier}`"
282
+ ]
283
+ });
284
+ return capability;
285
+ }
286
+ /**
287
+ * Waits for a capability to be contributed.
288
+ * @returns The capability.
289
+ */
290
+ async waitForCapability(interfaceDef, filter) {
291
+ const trigger = new import_async.Trigger();
292
+ const unsubscribe = (0, import_signals_core.effect)(() => {
293
+ const capabilities = this.requestCapabilities(interfaceDef, filter);
294
+ if (capabilities[0]) {
295
+ trigger.wake(capabilities[0]);
296
+ }
297
+ });
298
+ const capability = await trigger.wait();
299
+ unsubscribe();
300
+ return capability;
301
+ }
302
+ };
303
+ var defineEvent = (id, specifier) => {
304
+ return {
305
+ id,
306
+ specifier
307
+ };
308
+ };
309
+ var eventKey = (event) => event.specifier ? `${event.id}:${event.specifier}` : event.id;
310
+ var oneOf = (...events) => ({
311
+ type: "one-of",
312
+ events
313
+ });
314
+ var allOf = (...events) => ({
315
+ type: "all-of",
316
+ events
317
+ });
318
+ var isOneOf = (events) => "type" in events && events.type === "one-of";
319
+ var isAllOf = (events) => "type" in events && events.type === "all-of";
320
+ var getEvents = (events) => "type" in events ? events.events : [
321
+ events
322
+ ];
323
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/core/manager.ts";
324
+ var isPromise = (value) => {
325
+ return value !== null && typeof value === "object" && "then" in value;
326
+ };
327
+ var PluginManager = class {
328
+ constructor({ pluginLoader, plugins = [], core = plugins.map(({ meta }) => meta.id), enabled = [] }) {
329
+ this.activation = new import_async2.Event();
330
+ this.context = new PluginsContext({
331
+ activate: (event) => this.activate(event),
332
+ reset: (id) => this.reset(id)
333
+ });
334
+ this._capabilities = /* @__PURE__ */ new Map();
335
+ this._pluginLoader = pluginLoader;
336
+ this._state = (0, import_live_object3.create)({
337
+ plugins,
338
+ core,
339
+ enabled,
340
+ modules: [],
341
+ active: [],
342
+ pendingReset: [],
343
+ eventsFired: []
344
+ });
345
+ plugins.forEach((plugin) => this._addPlugin(plugin));
346
+ core.forEach((id) => this.enable(id));
347
+ enabled.forEach((id) => this.enable(id));
348
+ }
349
+ /**
350
+ * Plugins that are currently registered.
351
+ *
352
+ * @reactive
353
+ */
354
+ get plugins() {
355
+ return this._state.plugins;
356
+ }
357
+ /**
358
+ * Ids of plugins that are core and cannot be removed.
359
+ *
360
+ * @reactive
361
+ */
362
+ get core() {
363
+ return this._state.core;
364
+ }
365
+ /**
366
+ * Ids of plugins that are currently enabled.
367
+ *
368
+ * @reactive
369
+ */
370
+ get enabled() {
371
+ return this._state.enabled;
372
+ }
373
+ /**
374
+ * Modules of plugins which are currently enabled.
375
+ *
376
+ * @reactive
377
+ */
378
+ get modules() {
379
+ return this._state.modules;
380
+ }
381
+ /**
382
+ * Ids of modules which are currently active.
383
+ *
384
+ * @reactive
385
+ */
386
+ get active() {
387
+ return this._state.active;
388
+ }
389
+ /**
390
+ * Ids of events which have been fired.
391
+ *
392
+ * @reactive
393
+ */
394
+ get eventsFired() {
395
+ return this._state.eventsFired;
396
+ }
397
+ /**
398
+ * Ids of modules which are pending reset.
399
+ *
400
+ * @reactive
401
+ */
402
+ get pendingReset() {
403
+ return this._state.pendingReset;
404
+ }
405
+ /**
406
+ * Adds a plugin to the manager via the plugin loader.
407
+ * @param id The id of the plugin.
408
+ */
409
+ async add(id) {
410
+ return (0, import_signals_core2.untracked)(async () => {
411
+ (0, import_log3.log)("add plugin", {
412
+ id
413
+ }, {
414
+ F: __dxlog_file2,
415
+ L: 146,
416
+ S: this,
417
+ C: (f, a) => f(...a)
418
+ });
419
+ const plugin = await this._pluginLoader(id);
420
+ this._addPlugin(plugin);
421
+ return this.enable(id);
422
+ });
423
+ }
424
+ /**
425
+ * Enables a plugin.
426
+ * @param id The id of the plugin.
427
+ */
428
+ enable(id) {
429
+ return (0, import_signals_core2.untracked)(async () => {
430
+ (0, import_log3.log)("enable plugin", {
431
+ id
432
+ }, {
433
+ F: __dxlog_file2,
434
+ L: 159,
435
+ S: this,
436
+ C: (f, a) => f(...a)
437
+ });
438
+ const plugin = this._getPlugin(id);
439
+ if (!plugin) {
440
+ return false;
441
+ }
442
+ if (!this._state.enabled.includes(id)) {
443
+ this._state.enabled.push(id);
444
+ }
445
+ plugin.modules.forEach((module2) => {
446
+ this._addModule(module2);
447
+ this._setPendingResetByModule(module2);
448
+ });
449
+ (0, import_log3.log)("pending reset", {
450
+ events: [
451
+ ...this.pendingReset
452
+ ]
453
+ }, {
454
+ F: __dxlog_file2,
455
+ L: 174,
456
+ S: this,
457
+ C: (f, a) => f(...a)
458
+ });
459
+ await import_effect2.Effect.runPromise(import_effect2.Effect.all(this.pendingReset.map((event) => this._activate(event)), {
460
+ concurrency: "unbounded"
461
+ }));
462
+ return true;
463
+ });
464
+ }
465
+ /**
466
+ * Removes a plugin from the manager.
467
+ * @param id The id of the plugin.
468
+ */
469
+ remove(id) {
470
+ return (0, import_signals_core2.untracked)(() => {
471
+ (0, import_log3.log)("remove plugin", {
472
+ id
473
+ }, {
474
+ F: __dxlog_file2,
475
+ L: 192,
476
+ S: this,
477
+ C: (f, a) => f(...a)
478
+ });
479
+ const result = this.disable(id);
480
+ if (!result) {
481
+ return false;
482
+ }
483
+ this._removePlugin(id);
484
+ return true;
485
+ });
486
+ }
487
+ /**
488
+ * Disables a plugin.
489
+ * @param id The id of the plugin.
490
+ */
491
+ disable(id) {
492
+ return (0, import_signals_core2.untracked)(async () => {
493
+ (0, import_log3.log)("disable plugin", {
494
+ id
495
+ }, {
496
+ F: __dxlog_file2,
497
+ L: 209,
498
+ S: this,
499
+ C: (f, a) => f(...a)
500
+ });
501
+ if (this._state.core.includes(id)) {
502
+ return false;
503
+ }
504
+ const plugin = this._getPlugin(id);
505
+ if (!plugin) {
506
+ return false;
507
+ }
508
+ const enabledIndex = this._state.enabled.findIndex((enabled) => enabled === id);
509
+ if (enabledIndex !== -1) {
510
+ this._state.enabled.splice(enabledIndex, 1);
511
+ await import_effect2.Effect.runPromise(this._deactivate(id));
512
+ plugin.modules.forEach((module2) => {
513
+ this._removeModule(module2.id);
514
+ });
515
+ }
516
+ return true;
517
+ });
518
+ }
519
+ /**
520
+ * Activates plugins based on the activation event.
521
+ * @param event The activation event.
522
+ * @returns Whether the activation was successful.
523
+ */
524
+ activate(event) {
525
+ return (0, import_signals_core2.untracked)(() => import_effect2.Effect.runPromise(this._activate(event)));
526
+ }
527
+ /**
528
+ * Deactivates all of the modules for a plugin.
529
+ * @param id The id of the plugin.
530
+ * @returns Whether the deactivation was successful.
531
+ */
532
+ deactivate(id) {
533
+ return (0, import_signals_core2.untracked)(() => import_effect2.Effect.runPromise(this._deactivate(id)));
534
+ }
535
+ /**
536
+ * Re-activates the modules that were activated by the event.
537
+ * @param event The activation event.
538
+ * @returns Whether the reset was successful.
539
+ */
540
+ reset(event) {
541
+ return (0, import_signals_core2.untracked)(() => import_effect2.Effect.runPromise(this._reset(event)));
542
+ }
543
+ _addPlugin(plugin) {
544
+ (0, import_signals_core2.untracked)(() => {
545
+ (0, import_log3.log)("add plugin", {
546
+ id: plugin.meta.id
547
+ }, {
548
+ F: __dxlog_file2,
549
+ L: 262,
550
+ S: this,
551
+ C: (f, a) => f(...a)
552
+ });
553
+ if (!this._state.plugins.includes(plugin)) {
554
+ this._state.plugins.push(plugin);
555
+ }
556
+ });
557
+ }
558
+ _removePlugin(id) {
559
+ (0, import_signals_core2.untracked)(() => {
560
+ (0, import_log3.log)("remove plugin", {
561
+ id
562
+ }, {
563
+ F: __dxlog_file2,
564
+ L: 271,
565
+ S: this,
566
+ C: (f, a) => f(...a)
567
+ });
568
+ const pluginIndex = this._state.plugins.findIndex((plugin) => plugin.meta.id === id);
569
+ if (pluginIndex !== -1) {
570
+ this._state.plugins.splice(pluginIndex, 1);
571
+ }
572
+ });
573
+ }
574
+ _addModule(module2) {
575
+ (0, import_signals_core2.untracked)(() => {
576
+ (0, import_log3.log)("add module", {
577
+ id: module2.id
578
+ }, {
579
+ F: __dxlog_file2,
580
+ L: 281,
581
+ S: this,
582
+ C: (f, a) => f(...a)
583
+ });
584
+ if (!this._state.modules.includes(module2)) {
585
+ this._state.modules.push(module2);
586
+ }
587
+ });
588
+ }
589
+ _removeModule(id) {
590
+ (0, import_signals_core2.untracked)(() => {
591
+ (0, import_log3.log)("remove module", {
592
+ id
593
+ }, {
594
+ F: __dxlog_file2,
595
+ L: 290,
596
+ S: this,
597
+ C: (f, a) => f(...a)
598
+ });
599
+ const moduleIndex = this._state.modules.findIndex((module2) => module2.id === id);
600
+ if (moduleIndex !== -1) {
601
+ this._state.modules.splice(moduleIndex, 1);
602
+ }
603
+ });
604
+ }
605
+ _getPlugin(id) {
606
+ return this._state.plugins.find((plugin) => plugin.meta.id === id);
607
+ }
608
+ _getActiveModules() {
609
+ return this._state.modules.filter((module2) => this._state.active.includes(module2.id));
610
+ }
611
+ _getInactiveModules() {
612
+ return this._state.modules.filter((module2) => !this._state.active.includes(module2.id));
613
+ }
614
+ _getActiveModulesByEvent(key) {
615
+ return this._getActiveModules().filter((module2) => getEvents(module2.activatesOn).map(eventKey).includes(key));
616
+ }
617
+ _getInactiveModulesByEvent(key) {
618
+ return this._getInactiveModules().filter((module2) => getEvents(module2.activatesOn).map(eventKey).includes(key));
619
+ }
620
+ _setPendingResetByModule(module2) {
621
+ return (0, import_signals_core2.untracked)(() => {
622
+ const activationEvents = getEvents(module2.activatesOn).map(eventKey).filter((key) => this._state.eventsFired.includes(key));
623
+ const pendingReset = Array.from(new Set(activationEvents)).filter((event) => !this._state.pendingReset.includes(event));
624
+ if (pendingReset.length > 0) {
625
+ (0, import_log3.log)("pending reset", {
626
+ events: pendingReset
627
+ }, {
628
+ F: __dxlog_file2,
629
+ L: 328,
630
+ S: this,
631
+ C: (f, a) => f(...a)
632
+ });
633
+ this._state.pendingReset.push(...pendingReset);
634
+ }
635
+ });
636
+ }
637
+ /**
638
+ * @internal
639
+ */
640
+ // TODO(wittjosiah): Improve error typing.
641
+ _activate(event) {
642
+ return import_effect2.Effect.gen(this, function* () {
643
+ const key = typeof event === "string" ? event : eventKey(event);
644
+ (0, import_log3.log)("activating", {
645
+ key
646
+ }, {
647
+ F: __dxlog_file2,
648
+ L: 341,
649
+ S: this,
650
+ C: (f, a) => f(...a)
651
+ });
652
+ const pendingIndex = this._state.pendingReset.findIndex((event2) => event2 === key);
653
+ if (pendingIndex !== -1) {
654
+ this._state.pendingReset.splice(pendingIndex, 1);
655
+ }
656
+ const modules = this._getInactiveModulesByEvent(key).filter((module2) => {
657
+ const allOf2 = isAllOf(module2.activatesOn);
658
+ if (!allOf2) {
659
+ return true;
660
+ }
661
+ const events = module2.activatesOn.events.filter((event2) => eventKey(event2) !== key);
662
+ return events.every((event2) => this._state.eventsFired.includes(eventKey(event2)));
663
+ });
664
+ if (modules.length === 0) {
665
+ (0, import_log3.log)("no modules to activate", {
666
+ key
667
+ }, {
668
+ F: __dxlog_file2,
669
+ L: 357,
670
+ S: this,
671
+ C: (f, a) => f(...a)
672
+ });
673
+ if (!this._state.eventsFired.includes(key)) {
674
+ this._state.eventsFired.push(key);
675
+ }
676
+ return false;
677
+ }
678
+ (0, import_log3.log)("activating modules", {
679
+ key,
680
+ modules: modules.map((module2) => module2.id)
681
+ }, {
682
+ F: __dxlog_file2,
683
+ L: 364,
684
+ S: this,
685
+ C: (f, a) => f(...a)
686
+ });
687
+ this.activation.emit({
688
+ event: key,
689
+ state: "activating"
690
+ });
691
+ const getCapabilities = yield* import_effect2.Effect.all(modules.map(({ activate }) => import_effect2.Effect.tryPromise({
692
+ try: async () => activate(this.context),
693
+ catch: (error) => error
694
+ })), {
695
+ concurrency: "unbounded"
696
+ });
697
+ const result = yield* (0, import_effect2.pipe)(
698
+ modules,
699
+ import_effect2.Array.zip(getCapabilities),
700
+ import_effect2.Array.map(([module2, getCapabilities2]) => this._activateModule(module2, getCapabilities2)),
701
+ // TODO(wittjosiah): This currently can't be run in parallel.
702
+ // Running this with concurrency causes races with `allOf` activation events.
703
+ import_effect2.Effect.all,
704
+ import_effect2.Effect.either
705
+ );
706
+ if (import_effect2.Either.isLeft(result)) {
707
+ this.activation.emit({
708
+ event: key,
709
+ state: "error",
710
+ error: result.left
711
+ });
712
+ yield* import_effect2.Effect.fail(result.left);
713
+ }
714
+ if (!this._state.eventsFired.includes(key)) {
715
+ this._state.eventsFired.push(key);
716
+ }
717
+ this.activation.emit({
718
+ event: key,
719
+ state: "activated"
720
+ });
721
+ (0, import_log3.log)("activated", {
722
+ key
723
+ }, {
724
+ F: __dxlog_file2,
725
+ L: 398,
726
+ S: this,
727
+ C: (f, a) => f(...a)
728
+ });
729
+ return true;
730
+ });
731
+ }
732
+ _activateModule(module2, getCapabilities) {
733
+ return import_effect2.Effect.gen(this, function* () {
734
+ yield* import_effect2.Effect.all(module2.activatesBefore?.map((event) => this._activate(event)) ?? [], {
735
+ concurrency: "unbounded"
736
+ });
737
+ (0, import_log3.log)("activating module...", {
738
+ module: module2.id
739
+ }, {
740
+ F: __dxlog_file2,
741
+ L: 413,
742
+ S: this,
743
+ C: (f, a) => f(...a)
744
+ });
745
+ const maybeCapabilities = typeof getCapabilities === "function" ? getCapabilities() : getCapabilities;
746
+ const resolvedCapabilities = yield* import_effect2.Match.value(maybeCapabilities).pipe(
747
+ // TODO(wittjosiah): Activate with an effect?
748
+ // Match.when(Effect.isEffect, (effect) => effect),
749
+ import_effect2.Match.when(isPromise, (promise) => import_effect2.Effect.tryPromise({
750
+ try: () => promise,
751
+ catch: (error) => error
752
+ })),
753
+ import_effect2.Match.orElse((program) => import_effect2.Effect.succeed(program))
754
+ );
755
+ const capabilities = import_effect2.Match.value(resolvedCapabilities).pipe(import_effect2.Match.when(Array.isArray, (array) => array), import_effect2.Match.orElse((value) => [
756
+ value
757
+ ]));
758
+ capabilities.forEach((capability) => {
759
+ this.context.contributeCapability({
760
+ module: module2.id,
761
+ ...capability
762
+ });
763
+ });
764
+ this._state.active.push(module2.id);
765
+ this._capabilities.set(module2.id, capabilities);
766
+ (0, import_log3.log)("activated module", {
767
+ module: module2.id
768
+ }, {
769
+ F: __dxlog_file2,
770
+ L: 436,
771
+ S: this,
772
+ C: (f, a) => f(...a)
773
+ });
774
+ yield* import_effect2.Effect.all(module2.activatesAfter?.map((event) => this._activate(event)) ?? [], {
775
+ concurrency: "unbounded"
776
+ });
777
+ });
778
+ }
779
+ _deactivate(id) {
780
+ return import_effect2.Effect.gen(this, function* () {
781
+ const plugin = this._getPlugin(id);
782
+ if (!plugin) {
783
+ return false;
784
+ }
785
+ const modules = plugin.modules;
786
+ const results = yield* import_effect2.Effect.all(modules.map((module2) => this._deactivateModule(module2)), {
787
+ concurrency: "unbounded"
788
+ });
789
+ return results.every((result) => result);
790
+ });
791
+ }
792
+ _deactivateModule(module2) {
793
+ return import_effect2.Effect.gen(this, function* () {
794
+ const id = module2.id;
795
+ (0, import_log3.log)("deactivating", {
796
+ id
797
+ }, {
798
+ F: __dxlog_file2,
799
+ L: 463,
800
+ S: this,
801
+ C: (f, a) => f(...a)
802
+ });
803
+ const capabilities = this._capabilities.get(id);
804
+ if (capabilities) {
805
+ for (const capability of capabilities) {
806
+ this.context.removeCapability(capability.interface, capability.implementation);
807
+ const program = capability.deactivate?.();
808
+ yield* import_effect2.Match.value(program).pipe(import_effect2.Match.when(import_effect2.Effect.isEffect, (effect2) => effect2), import_effect2.Match.when(isPromise, (promise) => import_effect2.Effect.tryPromise({
809
+ try: () => promise,
810
+ catch: (error) => error
811
+ })), import_effect2.Match.orElse((program2) => import_effect2.Effect.succeed(program2)));
812
+ }
813
+ this._capabilities.delete(id);
814
+ }
815
+ const activeIndex = this._state.active.findIndex((event) => event === id);
816
+ if (activeIndex !== -1) {
817
+ this._state.active.splice(activeIndex, 1);
818
+ }
819
+ (0, import_log3.log)("deactivated", {
820
+ id
821
+ }, {
822
+ F: __dxlog_file2,
823
+ L: 489,
824
+ S: this,
825
+ C: (f, a) => f(...a)
826
+ });
827
+ return true;
828
+ });
829
+ }
830
+ _reset(event) {
831
+ return import_effect2.Effect.gen(this, function* () {
832
+ const key = typeof event === "string" ? event : eventKey(event);
833
+ (0, import_log3.log)("reset", {
834
+ key
835
+ }, {
836
+ F: __dxlog_file2,
837
+ L: 497,
838
+ S: this,
839
+ C: (f, a) => f(...a)
840
+ });
841
+ const modules = this._getActiveModulesByEvent(key);
842
+ const results = yield* import_effect2.Effect.all(modules.map((module2) => this._deactivateModule(module2)), {
843
+ concurrency: "unbounded"
844
+ });
845
+ if (results.every((result) => result)) {
846
+ return yield* this._activate(key);
847
+ } else {
848
+ return false;
849
+ }
850
+ });
851
+ }
852
+ };
853
+ var PluginModule = class {
854
+ constructor(options) {
855
+ this.id = options.id;
856
+ this.activatesOn = options.activatesOn;
857
+ this.activatesBefore = options.activatesBefore;
858
+ this.activatesAfter = options.activatesAfter;
859
+ this.activate = options.activate;
860
+ }
861
+ };
862
+ var defineModule = (options) => new PluginModule(options);
863
+ var Plugin = class {
864
+ constructor(meta, modules) {
865
+ this.meta = meta;
866
+ this.modules = modules;
867
+ }
868
+ };
869
+ var definePlugin = (meta, modules) => {
870
+ return new Plugin(meta, modules);
871
+ };
872
+ var Capabilities;
873
+ (function(Capabilities2) {
874
+ Capabilities2.PluginManager = defineCapability("dxos.org/app-framework/capability/plugin-manager");
875
+ Capabilities2.Null = defineCapability("dxos.org/app-framework/capability/null");
876
+ Capabilities2.ReactContext = defineCapability("dxos.org/app-framework/capability/react-context");
877
+ Capabilities2.ReactRoot = defineCapability("dxos.org/app-framework/capability/react-root");
878
+ Capabilities2.ReactSurface = defineCapability("dxos.org/app-framework/common/react-surface");
879
+ Capabilities2.IntentResolver = defineCapability("dxos.org/app-framework/capability/intent-resolver");
880
+ Capabilities2.IntentDispatcher = defineCapability("dxos.org/app-framework/capability/intent-dispatcher");
881
+ Capabilities2.Layout = defineCapability("dxos.org/app-framework/capability/layout");
882
+ Capabilities2.Translations = defineCapability("dxos.org/app-framework/capability/translations");
883
+ Capabilities2.AppGraph = defineCapability("dxos.org/app-framework/capability/app-graph");
884
+ Capabilities2.AppGraphBuilder = defineCapability("dxos.org/app-framework/capability/app-graph-builder");
885
+ Capabilities2.AppGraphSerializer = defineCapability("dxos.org/app-framework/capability/app-graph-serializer");
886
+ Capabilities2.SettingsStore = defineCapability("dxos.org/app-framework/capability/settings-store");
887
+ Capabilities2.Settings = defineCapability("dxos.org/app-framework/capability/settings");
888
+ Capabilities2.Metadata = defineCapability("dxos.org/app-framework/capability/metadata");
889
+ Capabilities2.Tools = defineCapability("dxos.org/app-framework/capability/tools");
890
+ Capabilities2.ArtifactDefinition = defineCapability("dxos.org/app-framework/capability/artifact-definition");
891
+ Capabilities2.FileUploader = defineCapability("dxos.org/app-framework/capability/file-uploader");
892
+ })(Capabilities || (Capabilities = {}));
893
+ var Events;
894
+ (function(Events2) {
895
+ Events2.Startup = defineEvent("dxos.org/app-framework/event/startup");
896
+ Events2.SetupReactSurface = defineEvent("dxos.org/app-framework/event/setup-react-surface");
897
+ Events2.SetupMetadata = defineEvent("dxos.org/app-framework/event/setup-metadata");
898
+ Events2.SetupIntentResolver = defineEvent("dxos.org/app-framework/event/setup-intent-resolver");
899
+ Events2.SetupSettings = defineEvent("dxos.org/app-framework/event/setup-settings");
900
+ Events2.SetupAppGraph = defineEvent("dxos.org/app-framework/event/setup-graph");
901
+ Events2.SetupTranslations = defineEvent("dxos.org/app-framework/event/setup-translations");
902
+ Events2.SetupArtifactDefinition = defineEvent("dxos.org/app-framework/event/setup-artifact-definition");
903
+ Events2.DispatcherReady = defineEvent("dxos.org/app-framework/event/dispatcher-ready");
904
+ Events2.SettingsReady = defineEvent("dxos.org/app-framework/event/settings-ready");
905
+ Events2.AppGraphReady = defineEvent("dxos.org/app-framework/event/graph-ready");
906
+ Events2.createStateEvent = (specifier) => defineEvent("dxos.org/app-framework/event/state", specifier);
907
+ Events2.LayoutReady = Events2.createStateEvent(Capabilities.Layout.identifier);
908
+ })(Events || (Events = {}));
909
+ var defaultFileTypes = {
910
+ images: [
911
+ "png",
912
+ "jpg",
913
+ "jpeg",
914
+ "gif"
915
+ ],
916
+ media: [
917
+ "mp3",
918
+ "mp4",
919
+ "mov",
920
+ "avi"
921
+ ],
922
+ text: [
923
+ "pdf",
924
+ "txt",
925
+ "md"
926
+ ]
927
+ };
928
+ var FileInfoSchema = import_schema3.Schema.Struct({
929
+ name: import_schema3.Schema.String,
930
+ type: import_schema3.Schema.String,
931
+ url: import_schema3.Schema.optional(import_schema3.Schema.String),
932
+ cid: import_schema3.Schema.optional(import_schema3.Schema.String)
933
+ });
934
+ var IntentPlugin = () => definePlugin({
935
+ id: INTENT_PLUGIN
936
+ }, [
937
+ defineModule({
938
+ id: `${INTENT_PLUGIN}/module/dispatcher`,
939
+ // TODO(wittjosiah): This will mean that startup needs to be reset when intents are added or removed.
940
+ // This is fine for now because it's how it worked prior to capabilities api anyways.
941
+ // In the future, the intent dispatcher should be able to be reset without resetting the entire app.
942
+ activatesOn: Events.Startup,
943
+ activatesAfter: [
944
+ Events.DispatcherReady
945
+ ],
946
+ activate: lazy(() => import("./intent-dispatcher-PRCC4KZT.cjs"))
947
+ })
948
+ ]);
949
+ var LAYOUT_PLUGIN = "dxos.org/plugin/layout";
950
+ var LAYOUT_ACTION = `${LAYOUT_PLUGIN}/action`;
951
+ var LayoutAction;
952
+ (function(LayoutAction2) {
953
+ LayoutAction2.UPDATE_LAYOUT = `${LAYOUT_ACTION}/update-layout`;
954
+ class UpdateLayout extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
955
+ input: import_schema4.Schema.Struct({
956
+ part: import_schema4.Schema.String.annotations({
957
+ description: "The part of the layout to mutate."
958
+ }),
959
+ subject: import_schema4.Schema.optional(import_schema4.Schema.Any.annotations({
960
+ description: "The subject of the layout update."
961
+ })),
962
+ options: import_schema4.Schema.optional(import_schema4.Schema.Record({
963
+ key: import_schema4.Schema.String,
964
+ value: import_schema4.Schema.Any
965
+ }).annotations({
966
+ description: "Additional options for the layout action."
967
+ }))
968
+ }),
969
+ output: import_schema4.Schema.Void
970
+ }) {
971
+ }
972
+ LayoutAction2.UpdateLayout = UpdateLayout;
973
+ class SetLayoutMode extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
974
+ input: import_schema4.Schema.Struct({
975
+ part: import_schema4.Schema.Literal("mode").annotations({
976
+ description: "Setting the layout mode."
977
+ }),
978
+ subject: import_schema4.Schema.optional(import_schema4.Schema.String.annotations({
979
+ description: "Item which is the subject of the new layout mode."
980
+ })),
981
+ options: import_schema4.Schema.Union(import_schema4.Schema.Struct({
982
+ mode: import_schema4.Schema.String.annotations({
983
+ description: "The new layout mode."
984
+ })
985
+ }), import_schema4.Schema.Struct({
986
+ revert: import_schema4.Schema.Boolean.annotations({
987
+ description: "Revert to the previous layout mode."
988
+ })
989
+ }))
990
+ }),
991
+ output: import_schema4.Schema.Void
992
+ }) {
993
+ }
994
+ LayoutAction2.SetLayoutMode = SetLayoutMode;
995
+ class UpdateSidebar extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
996
+ input: import_schema4.Schema.Struct({
997
+ part: import_schema4.Schema.Literal("sidebar").annotations({
998
+ description: "Updating the sidebar."
999
+ }),
1000
+ subject: import_schema4.Schema.optional(import_schema4.Schema.String.annotations({
1001
+ description: "URI of the component to display in the sidebar."
1002
+ })),
1003
+ options: import_schema4.Schema.optional(import_schema4.Schema.Struct({
1004
+ state: import_schema4.Schema.Literal("closed", "collapsed", "expanded").annotations({
1005
+ description: "Whether the sidebar is closed, collapsed, or expanded."
1006
+ })
1007
+ }))
1008
+ }),
1009
+ output: import_schema4.Schema.Void
1010
+ }) {
1011
+ }
1012
+ LayoutAction2.UpdateSidebar = UpdateSidebar;
1013
+ class UpdateComplementary extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1014
+ input: import_schema4.Schema.Struct({
1015
+ part: import_schema4.Schema.Literal("complementary").annotations({
1016
+ description: "Updating the complementary sidebar."
1017
+ }),
1018
+ subject: import_schema4.Schema.optional(import_schema4.Schema.String.annotations({
1019
+ description: "URI of the component to display in the complementary area."
1020
+ })),
1021
+ options: import_schema4.Schema.optional(import_schema4.Schema.Struct({
1022
+ state: import_schema4.Schema.Literal("closed", "collapsed", "expanded").annotations({
1023
+ description: "Whether the complementary sidebar is closed, collapsed, or expanded."
1024
+ })
1025
+ }))
1026
+ }),
1027
+ output: import_schema4.Schema.Void
1028
+ }) {
1029
+ }
1030
+ LayoutAction2.UpdateComplementary = UpdateComplementary;
1031
+ class UpdateDialog extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1032
+ input: import_schema4.Schema.Struct({
1033
+ part: import_schema4.Schema.Literal("dialog").annotations({
1034
+ description: "Updating the dialog."
1035
+ }),
1036
+ subject: import_schema4.Schema.optional(import_schema4.Schema.String.annotations({
1037
+ description: "URI of the component to display in the dialog."
1038
+ })),
1039
+ options: import_schema4.Schema.Struct({
1040
+ state: import_schema4.Schema.optional(import_schema4.Schema.Boolean.annotations({
1041
+ description: "Whether the dialog is open or closed."
1042
+ })),
1043
+ blockAlign: import_schema4.Schema.optional(import_schema4.Schema.Literal("start", "center", "end").annotations({
1044
+ description: "The alignment of the dialog."
1045
+ })),
1046
+ type: import_schema4.Schema.optional(import_schema4.Schema.Literal("default", "alert").annotations({
1047
+ description: "The type of dialog."
1048
+ })),
1049
+ props: import_schema4.Schema.optional(import_schema4.Schema.Record({
1050
+ key: import_schema4.Schema.String,
1051
+ value: import_schema4.Schema.Any
1052
+ }).annotations({
1053
+ description: "Additional props for the dialog."
1054
+ }))
1055
+ })
1056
+ }),
1057
+ output: import_schema4.Schema.Void
1058
+ }) {
1059
+ }
1060
+ LayoutAction2.UpdateDialog = UpdateDialog;
1061
+ class UpdatePopover extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1062
+ input: import_schema4.Schema.Struct({
1063
+ part: import_schema4.Schema.Literal("popover").annotations({
1064
+ description: "Updating the popover."
1065
+ }),
1066
+ subject: import_schema4.Schema.optional(import_schema4.Schema.String.annotations({
1067
+ description: "URI of the component to display in the popover."
1068
+ })),
1069
+ options: import_schema4.Schema.Struct({
1070
+ anchorId: import_schema4.Schema.String.annotations({
1071
+ description: "The id of the element to anchor the popover to."
1072
+ }),
1073
+ side: import_schema4.Schema.optional(import_schema4.Schema.Literal("top", "right", "bottom", "left").annotations({
1074
+ description: "The side of the anchor."
1075
+ })),
1076
+ state: import_schema4.Schema.optional(import_schema4.Schema.Boolean.annotations({
1077
+ description: "Whether the popover is open or closed."
1078
+ })),
1079
+ props: import_schema4.Schema.optional(import_schema4.Schema.Record({
1080
+ key: import_schema4.Schema.String,
1081
+ value: import_schema4.Schema.Any
1082
+ }).annotations({
1083
+ description: "Additional props for the popover."
1084
+ }))
1085
+ })
1086
+ }),
1087
+ output: import_schema4.Schema.Void
1088
+ }) {
1089
+ }
1090
+ LayoutAction2.UpdatePopover = UpdatePopover;
1091
+ LayoutAction2.Toast = import_schema4.Schema.Struct({
1092
+ id: import_schema4.Schema.String.annotations({
1093
+ description: "The id of the toast."
1094
+ }),
1095
+ title: import_schema4.Schema.optional(Label.annotations({
1096
+ description: "The title of the toast."
1097
+ })),
1098
+ description: import_schema4.Schema.optional(Label.annotations({
1099
+ description: "The description of the toast."
1100
+ })),
1101
+ icon: import_schema4.Schema.optional(import_schema4.Schema.String.annotations({
1102
+ description: "The icon of the toast."
1103
+ })),
1104
+ duration: import_schema4.Schema.optional(import_schema4.Schema.Number.annotations({
1105
+ description: "The duration of the toast."
1106
+ })),
1107
+ closeLabel: import_schema4.Schema.optional(Label.annotations({
1108
+ description: "The label of the close button."
1109
+ })),
1110
+ actionLabel: import_schema4.Schema.optional(Label.annotations({
1111
+ description: "The label of the action button."
1112
+ })),
1113
+ actionAlt: import_schema4.Schema.optional(Label.annotations({
1114
+ description: "The alt text of the action button."
1115
+ })),
1116
+ onAction: import_schema4.Schema.optional(import_schema4.Schema.Any.annotations({
1117
+ description: "The action to perform when the action button is clicked."
1118
+ }))
1119
+ });
1120
+ class AddToast extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1121
+ input: import_schema4.Schema.Struct({
1122
+ part: import_schema4.Schema.Literal("toast").annotations({
1123
+ description: "Adding a toast."
1124
+ }),
1125
+ subject: LayoutAction2.Toast.annotations({
1126
+ description: "The toast to add."
1127
+ })
1128
+ }),
1129
+ output: import_schema4.Schema.Void
1130
+ }) {
1131
+ }
1132
+ LayoutAction2.AddToast = AddToast;
1133
+ class SwitchWorkspace extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1134
+ input: import_schema4.Schema.Struct({
1135
+ part: import_schema4.Schema.Literal("workspace").annotations({
1136
+ description: "Switching the workspace."
1137
+ }),
1138
+ subject: import_schema4.Schema.String.annotations({
1139
+ description: "The id of the workspace to switch to."
1140
+ })
1141
+ }),
1142
+ output: import_schema4.Schema.Void
1143
+ }) {
1144
+ }
1145
+ LayoutAction2.SwitchWorkspace = SwitchWorkspace;
1146
+ class RevertWorkspace extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1147
+ input: import_schema4.Schema.Struct({
1148
+ part: import_schema4.Schema.Literal("workspace").annotations({
1149
+ description: "Switching the workspace."
1150
+ }),
1151
+ options: import_schema4.Schema.Struct({
1152
+ revert: import_schema4.Schema.Literal(true).annotations({
1153
+ description: "Revert to the previous workspace."
1154
+ })
1155
+ })
1156
+ }),
1157
+ output: import_schema4.Schema.Void
1158
+ }) {
1159
+ }
1160
+ LayoutAction2.RevertWorkspace = RevertWorkspace;
1161
+ class Open extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1162
+ input: import_schema4.Schema.Struct({
1163
+ part: import_schema4.Schema.Literal("main").annotations({
1164
+ description: "Opening an item in the main content area."
1165
+ }),
1166
+ subject: import_schema4.Schema.Array(import_schema4.Schema.String.annotations({
1167
+ description: "Ids of the items to open."
1168
+ })),
1169
+ options: import_schema4.Schema.optional(import_schema4.Schema.Struct({
1170
+ state: import_schema4.Schema.optional(import_schema4.Schema.Literal(true).annotations({
1171
+ description: "The items are being added."
1172
+ })),
1173
+ key: import_schema4.Schema.optional(import_schema4.Schema.String.annotations({
1174
+ description: "If provided, will replace item with a matching key (id prefix)."
1175
+ })),
1176
+ scrollIntoView: import_schema4.Schema.optional(import_schema4.Schema.Boolean.annotations({
1177
+ description: "Scroll the items into view."
1178
+ })),
1179
+ pivotId: import_schema4.Schema.optional(import_schema4.Schema.String.annotations({
1180
+ description: "The id of the item to place new items next to."
1181
+ })),
1182
+ positioning: import_schema4.Schema.optional(import_schema4.Schema.Union(import_schema4.Schema.Literal("start").annotations({
1183
+ description: "The items are being added before the pivot item."
1184
+ }), import_schema4.Schema.Literal("end").annotations({
1185
+ description: "The items are being added after the pivot item."
1186
+ })))
1187
+ }))
1188
+ }),
1189
+ output: import_schema4.Schema.Void
1190
+ }) {
1191
+ }
1192
+ LayoutAction2.Open = Open;
1193
+ class Set2 extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1194
+ input: import_schema4.Schema.Struct({
1195
+ part: import_schema4.Schema.Literal("main").annotations({
1196
+ description: "Setting items in the main content area."
1197
+ }),
1198
+ subject: import_schema4.Schema.Array(import_schema4.Schema.String.annotations({
1199
+ description: "Ids of the items to set."
1200
+ })),
1201
+ options: import_schema4.Schema.Struct({
1202
+ override: import_schema4.Schema.Literal(true).annotations({
1203
+ description: "Override the current items in the main content area."
1204
+ })
1205
+ })
1206
+ }),
1207
+ output: import_schema4.Schema.Void
1208
+ }) {
1209
+ }
1210
+ LayoutAction2.Set = Set2;
1211
+ class Close extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1212
+ input: import_schema4.Schema.Struct({
1213
+ part: import_schema4.Schema.Literal("main").annotations({
1214
+ description: "Closing items in the main content area."
1215
+ }),
1216
+ subject: import_schema4.Schema.Array(import_schema4.Schema.String.annotations({
1217
+ description: "Ids of the items to close."
1218
+ })),
1219
+ options: import_schema4.Schema.Struct({
1220
+ state: import_schema4.Schema.Literal(false).annotations({
1221
+ description: "The items are being removed."
1222
+ })
1223
+ })
1224
+ }),
1225
+ output: import_schema4.Schema.Void
1226
+ }) {
1227
+ }
1228
+ LayoutAction2.Close = Close;
1229
+ class ScrollIntoView extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1230
+ input: import_schema4.Schema.Struct({
1231
+ part: import_schema4.Schema.Literal("current").annotations({
1232
+ description: "Setting the current item"
1233
+ }),
1234
+ subject: import_schema4.Schema.optional(import_schema4.Schema.String.annotations({
1235
+ description: "The id of the item to set as current."
1236
+ })),
1237
+ options: import_schema4.Schema.optional(import_schema4.Schema.Record({
1238
+ key: import_schema4.Schema.String,
1239
+ value: import_schema4.Schema.Any
1240
+ }).annotations({
1241
+ description: "Additional options for the scroll into view."
1242
+ }))
1243
+ }),
1244
+ output: import_schema4.Schema.Void
1245
+ }) {
1246
+ }
1247
+ LayoutAction2.ScrollIntoView = ScrollIntoView;
1248
+ class Expose extends import_schema4.Schema.TaggedClass()(LayoutAction2.UPDATE_LAYOUT, {
1249
+ input: import_schema4.Schema.Struct({
1250
+ part: import_schema4.Schema.Literal("navigation").annotations({
1251
+ description: "Exposing an item in the navigation area."
1252
+ }),
1253
+ subject: import_schema4.Schema.String.annotations({
1254
+ description: "The id of the item to expose."
1255
+ })
1256
+ }),
1257
+ output: import_schema4.Schema.Void
1258
+ }) {
1259
+ }
1260
+ LayoutAction2.Expose = Expose;
1261
+ })(LayoutAction || (LayoutAction = {}));
1262
+ var createSurface = (definition) => definition;
1263
+ var ResourceKey = import_schema5.Schema.Union(import_schema5.Schema.String, import_schema5.Schema.Record({
1264
+ key: import_schema5.Schema.String,
1265
+ value: import_schema5.Schema.Any
1266
+ }));
1267
+ var ResourceLanguage = import_schema5.Schema.Record({
1268
+ key: import_schema5.Schema.String,
1269
+ value: ResourceKey
1270
+ });
1271
+ var Resource = import_schema5.Schema.Record({
1272
+ key: import_schema5.Schema.String,
1273
+ value: ResourceLanguage
1274
+ });
1275
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugin-intent/intent-dispatcher.ts";
1276
+ var EXECUTION_LIMIT = 100;
1277
+ var HISTORY_LIMIT = 100;
1278
+ var createResolver = (resolver) => resolver;
1279
+ var isUndoable = (historyEntry) => historyEntry.length > 0 && historyEntry.every(({ undoable }) => !!undoable);
1280
+ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, historyLimit = HISTORY_LIMIT } = {}) => {
1281
+ const historyRef = import_effect.Effect.runSync(import_effect.Ref.make([]));
1282
+ const handleIntent = (intent) => import_effect.Effect.gen(function* () {
1283
+ const candidates = getResolvers(intent.module).filter((r) => r.intent._tag === intent.id).filter((r) => !r.filter || r.filter(intent.data)).toSorted(import_util.byPosition);
1284
+ if (candidates.length === 0) {
1285
+ yield* import_effect.Effect.fail(new NoResolversError(intent.id));
1286
+ }
1287
+ const effect2 = candidates[0].resolve(intent.data, intent.undo ?? false);
1288
+ const result = import_effect.Effect.isEffect(effect2) ? yield* effect2 : yield* import_effect.Effect.promise(async () => effect2);
1289
+ return {
1290
+ _intent: intent,
1291
+ ...result
1292
+ };
1293
+ });
1294
+ const dispatch = (intentChain, depth = 0) => {
1295
+ return import_effect.Effect.gen(function* () {
1296
+ if (depth > executionLimit) {
1297
+ yield* import_effect.Effect.fail(new CycleDetectedError());
1298
+ }
1299
+ const resultsRef = yield* import_effect.Ref.make([]);
1300
+ for (const intent of intentChain.all) {
1301
+ const { data: prev } = (yield* resultsRef.get)[0] ?? {};
1302
+ const result2 = yield* handleIntent({
1303
+ ...intent,
1304
+ data: {
1305
+ ...intent.data,
1306
+ ...prev
1307
+ }
1308
+ });
1309
+ yield* import_effect.Ref.update(resultsRef, (results2) => [
1310
+ result2,
1311
+ ...results2
1312
+ ]);
1313
+ if (result2.intents) {
1314
+ for (const intent2 of result2.intents) {
1315
+ yield* dispatch(intent2, depth + 1);
1316
+ }
1317
+ }
1318
+ if (result2.error) {
1319
+ yield* import_effect.Effect.fail(result2.error);
1320
+ }
1321
+ }
1322
+ const results = yield* resultsRef.get;
1323
+ const result = results[0];
1324
+ yield* import_effect.Ref.update(historyRef, (history) => {
1325
+ const next = [
1326
+ ...history,
1327
+ results
1328
+ ];
1329
+ if (next.length > historyLimit) {
1330
+ next.splice(0, next.length - historyLimit);
1331
+ }
1332
+ return next;
1333
+ });
1334
+ if (result.undoable && isUndoable(results)) {
1335
+ yield* (0, import_effect.pipe)(dispatch(createIntent(IntentAction.ShowUndo, {
1336
+ message: result.undoable.message
1337
+ })), import_effect.Effect.catchSome((err) => err instanceof NoResolversError ? import_effect.Option.some(import_effect.Effect.succeed(void 0)) : import_effect.Option.none()));
1338
+ }
1339
+ return result.data;
1340
+ });
1341
+ };
1342
+ const dispatchPromise = (intentChain) => {
1343
+ return import_effect.Effect.runPromise(dispatch(intentChain)).then((data) => ({
1344
+ data
1345
+ })).catch((error) => {
1346
+ import_log.log.catch(error, void 0, {
1347
+ F: __dxlog_file3,
1348
+ L: 241,
1349
+ S: void 0,
1350
+ C: (f, a) => f(...a)
1351
+ });
1352
+ return {
1353
+ error
1354
+ };
1355
+ });
1356
+ };
1357
+ const undo = () => {
1358
+ return import_effect.Effect.gen(function* () {
1359
+ const history = yield* historyRef.get;
1360
+ const last = history.findLastIndex(isUndoable);
1361
+ const result = last !== -1 ? history[last] : void 0;
1362
+ if (result) {
1363
+ const all = result.map(({ _intent, undoable }) => {
1364
+ const data = _intent.data;
1365
+ const undoData = undoable?.data ?? {};
1366
+ return {
1367
+ ..._intent,
1368
+ data: {
1369
+ ...data,
1370
+ ...undoData
1371
+ },
1372
+ undo: true
1373
+ };
1374
+ });
1375
+ const intent = {
1376
+ first: all[0],
1377
+ last: all.at(-1),
1378
+ all
1379
+ };
1380
+ yield* import_effect.Ref.update(historyRef, (h) => h.filter((_, index) => index !== last));
1381
+ return yield* dispatch(intent);
1382
+ }
1383
+ });
1384
+ };
1385
+ const undoPromise = () => {
1386
+ return import_effect.Effect.runPromise(undo()).then((data) => ({
1387
+ data
1388
+ })).catch((error) => ({
1389
+ error
1390
+ }));
1391
+ };
1392
+ return {
1393
+ dispatch,
1394
+ dispatchPromise,
1395
+ undo,
1396
+ undoPromise
1397
+ };
1398
+ };
1399
+ var defaultEffect = () => import_effect.Effect.fail(new Error("Intent runtime not ready"));
1400
+ var defaultPromise = () => import_effect.Effect.runPromise(defaultEffect());
1401
+ var intent_dispatcher_default = (context) => {
1402
+ const state = (0, import_live_object.create)({
1403
+ dispatch: defaultEffect,
1404
+ dispatchPromise: defaultPromise,
1405
+ undo: defaultEffect,
1406
+ undoPromise: defaultPromise
1407
+ });
1408
+ const { dispatch, dispatchPromise, undo, undoPromise } = createDispatcher((module2) => context.requestCapabilities(Capabilities.IntentResolver, (c, moduleId) => {
1409
+ return module2 ? moduleId === module2 : true;
1410
+ }).flat());
1411
+ const manager = context.requestCapability(Capabilities.PluginManager);
1412
+ state.dispatch = (intentChain, depth) => {
1413
+ return import_effect.Effect.gen(function* () {
1414
+ yield* manager._activate(Events.SetupIntentResolver);
1415
+ return yield* dispatch(intentChain, depth);
1416
+ });
1417
+ };
1418
+ state.dispatchPromise = async (intentChain) => {
1419
+ await manager.activate(Events.SetupIntentResolver);
1420
+ return await dispatchPromise(intentChain);
1421
+ };
1422
+ state.undo = undo;
1423
+ state.undoPromise = undoPromise;
1424
+ return contributes(Capabilities.IntentDispatcher, state);
1425
+ };
1426
+ // Annotate the CommonJS export names for ESM import in node:
1427
+ 0 && (module.exports = {
1428
+ Capabilities,
1429
+ Events,
1430
+ FileInfoSchema,
1431
+ INTENT_ACTION,
1432
+ INTENT_PLUGIN,
1433
+ IntentAction,
1434
+ IntentPlugin,
1435
+ LAYOUT_ACTION,
1436
+ LAYOUT_PLUGIN,
1437
+ Label,
1438
+ LayoutAction,
1439
+ Plugin,
1440
+ PluginManager,
1441
+ PluginModule,
1442
+ PluginsContext,
1443
+ Resource,
1444
+ ResourceKey,
1445
+ ResourceLanguage,
1446
+ allOf,
1447
+ chain,
1448
+ contributes,
1449
+ createDispatcher,
1450
+ createIntent,
1451
+ createResolver,
1452
+ createSurface,
1453
+ defaultFileTypes,
1454
+ defineCapability,
1455
+ defineEvent,
1456
+ defineModule,
1457
+ definePlugin,
1458
+ eventKey,
1459
+ getEvents,
1460
+ intent_dispatcher_default,
1461
+ isAllOf,
1462
+ isOneOf,
1463
+ lazy,
1464
+ oneOf
1465
+ });
1466
+ //# sourceMappingURL=chunk-7Y6KJ3OK.cjs.map