@dxos/app-framework 0.8.4-main.b97322e → 0.8.4-main.f5c0578

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 (113) hide show
  1. package/.swc/plugins/v7_linux_x86_64_13.0.0/c614d7475354583212fbd7669acbae95b9832c305bf51bdaabe2e6de05abb6bf +0 -0
  2. package/dist/lib/browser/{app-graph-builder-LYF7EKNN.mjs → app-graph-builder-MOVKFH3J.mjs} +3 -3
  3. package/dist/lib/browser/app-graph-builder-MOVKFH3J.mjs.map +7 -0
  4. package/dist/lib/browser/{chunk-FMN65HSW.mjs → chunk-NKCIDYDI.mjs} +302 -223
  5. package/dist/lib/browser/chunk-NKCIDYDI.mjs.map +7 -0
  6. package/dist/lib/browser/{chunk-FO2PH7M3.mjs → chunk-OSBZFKMO.mjs} +35 -22
  7. package/dist/lib/browser/chunk-OSBZFKMO.mjs.map +7 -0
  8. package/dist/lib/browser/index.mjs +5 -5
  9. package/dist/lib/browser/index.mjs.map +2 -2
  10. package/dist/lib/browser/{intent-dispatcher-LSYQZSEB.mjs → intent-dispatcher-FTTJLVGN.mjs} +2 -2
  11. package/dist/lib/browser/{intent-resolver-ZTNOSO3A.mjs → intent-resolver-ZCGEAG3E.mjs} +2 -2
  12. package/dist/lib/browser/intent-resolver-ZCGEAG3E.mjs.map +7 -0
  13. package/dist/lib/browser/meta.json +1 -1
  14. package/dist/lib/browser/{store-KML2R4IE.mjs → store-3QB6Q2BC.mjs} +2 -2
  15. package/dist/lib/browser/{store-KML2R4IE.mjs.map → store-3QB6Q2BC.mjs.map} +1 -1
  16. package/dist/lib/browser/testing/index.mjs +2 -2
  17. package/dist/lib/browser/testing/index.mjs.map +2 -2
  18. package/dist/lib/browser/worker.mjs +1 -1
  19. package/dist/lib/node-esm/{app-graph-builder-SAOWGJDK.mjs → app-graph-builder-ODE4B5GT.mjs} +3 -3
  20. package/dist/lib/node-esm/app-graph-builder-ODE4B5GT.mjs.map +7 -0
  21. package/dist/lib/node-esm/{chunk-73HGSHKE.mjs → chunk-WU3QN5B6.mjs} +35 -22
  22. package/dist/lib/node-esm/chunk-WU3QN5B6.mjs.map +7 -0
  23. package/dist/lib/node-esm/{chunk-ZEZ4FVEU.mjs → chunk-YEN7NKTF.mjs} +302 -223
  24. package/dist/lib/node-esm/chunk-YEN7NKTF.mjs.map +7 -0
  25. package/dist/lib/node-esm/index.mjs +5 -5
  26. package/dist/lib/node-esm/index.mjs.map +2 -2
  27. package/dist/lib/node-esm/{intent-dispatcher-6CYNGPSW.mjs → intent-dispatcher-YQIQ55LJ.mjs} +2 -2
  28. package/dist/lib/node-esm/{intent-resolver-W7Z7WFFM.mjs → intent-resolver-KG27L7EQ.mjs} +2 -2
  29. package/dist/lib/node-esm/intent-resolver-KG27L7EQ.mjs.map +7 -0
  30. package/dist/lib/node-esm/meta.json +1 -1
  31. package/dist/lib/node-esm/{store-QEXGXLWZ.mjs → store-TIJAVO3D.mjs} +2 -2
  32. package/dist/lib/node-esm/{store-QEXGXLWZ.mjs.map → store-TIJAVO3D.mjs.map} +1 -1
  33. package/dist/lib/node-esm/testing/index.mjs +2 -2
  34. package/dist/lib/node-esm/testing/index.mjs.map +2 -2
  35. package/dist/lib/node-esm/worker.mjs +1 -1
  36. package/dist/types/src/App.d.ts +1 -1
  37. package/dist/types/src/App.d.ts.map +1 -1
  38. package/dist/types/src/common/capabilities.d.ts +79 -6
  39. package/dist/types/src/common/capabilities.d.ts.map +1 -1
  40. package/dist/types/src/common/events.d.ts.map +1 -1
  41. package/dist/types/src/common/index.d.ts +1 -1
  42. package/dist/types/src/common/index.d.ts.map +1 -1
  43. package/dist/types/src/common/surface.d.ts +1 -1
  44. package/dist/types/src/common/surface.d.ts.map +1 -1
  45. package/dist/types/src/core/capabilities.d.ts.map +1 -1
  46. package/dist/types/src/core/manager.d.ts +6 -2
  47. package/dist/types/src/core/manager.d.ts.map +1 -1
  48. package/dist/types/src/playground/generator/Toolbar.d.ts.map +1 -1
  49. package/dist/types/src/playground/generator/generator.d.ts.map +1 -1
  50. package/dist/types/src/playground/logger/Toolbar.d.ts.map +1 -1
  51. package/dist/types/src/playground/logger/plugin.d.ts.map +1 -1
  52. package/dist/types/src/playground/playground.stories.d.ts.map +1 -1
  53. package/dist/types/src/plugin-intent/IntentPlugin.d.ts.map +1 -1
  54. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts +2 -2
  55. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts.map +1 -1
  56. package/dist/types/src/plugin-settings/SettingsPlugin.d.ts.map +1 -1
  57. package/dist/types/src/plugin-settings/app-graph-builder.d.ts.map +1 -1
  58. package/dist/types/src/plugin-settings/intent-resolver.d.ts.map +1 -1
  59. package/dist/types/src/plugin-settings/store.d.ts.map +1 -1
  60. package/dist/types/src/react/ErrorBoundary.d.ts +13 -14
  61. package/dist/types/src/react/ErrorBoundary.d.ts.map +1 -1
  62. package/dist/types/src/react/IntentContext.d.ts.map +1 -1
  63. package/dist/types/src/react/Surface.d.ts.map +1 -1
  64. package/dist/types/src/react/Surface.stories.d.ts.map +1 -1
  65. package/dist/types/src/react/common.d.ts.map +1 -1
  66. package/dist/types/src/react/useCapabilities.d.ts.map +1 -1
  67. package/dist/types/src/testing/withPluginManager.d.ts +2 -0
  68. package/dist/types/src/testing/withPluginManager.d.ts.map +1 -1
  69. package/dist/types/src/testing/withPluginManager.stories.d.ts.map +1 -1
  70. package/dist/types/tsconfig.tsbuildinfo +1 -1
  71. package/package.json +28 -24
  72. package/src/App.tsx +11 -3
  73. package/src/common/capabilities.ts +96 -8
  74. package/src/common/events.ts +3 -1
  75. package/src/common/index.ts +1 -1
  76. package/src/common/surface.ts +1 -1
  77. package/src/core/capabilities.test.ts +1 -1
  78. package/src/core/capabilities.ts +1 -0
  79. package/src/core/manager.test.ts +4 -3
  80. package/src/core/manager.ts +132 -54
  81. package/src/helpers.test.ts +1 -1
  82. package/src/playground/generator/Toolbar.tsx +2 -1
  83. package/src/playground/generator/generator.ts +2 -2
  84. package/src/playground/layout/plugin.ts +1 -1
  85. package/src/playground/logger/Toolbar.tsx +2 -1
  86. package/src/playground/logger/plugin.ts +3 -2
  87. package/src/playground/playground.stories.tsx +4 -3
  88. package/src/plugin-intent/IntentPlugin.ts +2 -1
  89. package/src/plugin-intent/intent-dispatcher.test.ts +1 -1
  90. package/src/plugin-intent/intent-dispatcher.ts +6 -5
  91. package/src/plugin-settings/SettingsPlugin.ts +3 -2
  92. package/src/plugin-settings/app-graph-builder.ts +4 -3
  93. package/src/plugin-settings/intent-resolver.ts +3 -2
  94. package/src/plugin-settings/store.ts +1 -1
  95. package/src/react/ErrorBoundary.tsx +24 -15
  96. package/src/react/IntentContext.tsx +3 -2
  97. package/src/react/Surface.stories.tsx +3 -2
  98. package/src/react/Surface.tsx +4 -3
  99. package/src/react/common.ts +2 -1
  100. package/src/react/useCapabilities.ts +2 -1
  101. package/src/testing/withPluginManager.stories.tsx +3 -2
  102. package/src/testing/withPluginManager.tsx +8 -5
  103. package/.swc/plugins/v7_linux_x86_64_13.0.0/f45bdff002284d9e8f9ef3f0be909de12da36c049cbcf261ac78fc00abb09a2d +0 -0
  104. package/dist/lib/browser/app-graph-builder-LYF7EKNN.mjs.map +0 -7
  105. package/dist/lib/browser/chunk-FMN65HSW.mjs.map +0 -7
  106. package/dist/lib/browser/chunk-FO2PH7M3.mjs.map +0 -7
  107. package/dist/lib/browser/intent-resolver-ZTNOSO3A.mjs.map +0 -7
  108. package/dist/lib/node-esm/app-graph-builder-SAOWGJDK.mjs.map +0 -7
  109. package/dist/lib/node-esm/chunk-73HGSHKE.mjs.map +0 -7
  110. package/dist/lib/node-esm/chunk-ZEZ4FVEU.mjs.map +0 -7
  111. package/dist/lib/node-esm/intent-resolver-W7Z7WFFM.mjs.map +0 -7
  112. /package/dist/lib/browser/{intent-dispatcher-LSYQZSEB.mjs.map → intent-dispatcher-FTTJLVGN.mjs.map} +0 -0
  113. /package/dist/lib/node-esm/{intent-dispatcher-6CYNGPSW.mjs.map → intent-dispatcher-YQIQ55LJ.mjs.map} +0 -0
@@ -1,105 +1,11 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
2
 
3
3
  // src/plugin-intent/intent-dispatcher.ts
4
- import { Effect as Effect3, Option, pipe as pipe2, Ref as Ref2 } from "effect";
4
+ import { Effect as Effect3, Option, Ref as Ref3, pipe as pipe2 } from "effect";
5
5
  import { live as live2 } from "@dxos/live-object";
6
6
  import { log as log3 } from "@dxos/log";
7
7
  import { byPosition } from "@dxos/util";
8
8
 
9
- // src/plugin-intent/actions.ts
10
- import { Schema as Schema2 } from "effect";
11
-
12
- // src/plugin-intent/intent.ts
13
- import { Schema } from "effect";
14
- var createIntent = (schema, data = {}, params = {}) => {
15
- const _ = Schema.validateSync(schema.fields.input)(data);
16
- const intent = {
17
- ...params,
18
- _schema: schema,
19
- id: schema._tag,
20
- data
21
- };
22
- return {
23
- first: intent,
24
- last: intent,
25
- all: [
26
- intent
27
- ]
28
- };
29
- };
30
- var chain = (schema, data = {}, params = {}) => (intent) => {
31
- const intents = "all" in intent ? intent.all : [
32
- intent
33
- ];
34
- const first = intents[0];
35
- const last = {
36
- ...params,
37
- _schema: schema,
38
- id: schema._tag,
39
- data
40
- };
41
- return {
42
- first,
43
- last,
44
- all: [
45
- ...intents,
46
- last
47
- ]
48
- };
49
- };
50
- var Label = Schema.Union(Schema.String, Schema.mutable(Schema.Tuple(Schema.String, Schema.mutable(Schema.Struct({
51
- ns: Schema.String,
52
- count: Schema.optional(Schema.Number),
53
- defaultValue: Schema.optional(Schema.String)
54
- })))));
55
-
56
- // src/plugin-intent/actions.ts
57
- var INTENT_PLUGIN = "dxos.org/plugin/intent";
58
- var INTENT_ACTION = `${INTENT_PLUGIN}/action`;
59
- (function(IntentAction2) {
60
- class Track extends Schema2.TaggedClass()(`${INTENT_ACTION}/track`, {
61
- input: Schema2.Struct({
62
- intents: Schema2.Array(Schema2.String),
63
- error: Schema2.optional(Schema2.String)
64
- }),
65
- output: Schema2.Void
66
- }) {
67
- }
68
- IntentAction2.Track = Track;
69
- class ShowUndo extends Schema2.TaggedClass()(`${INTENT_ACTION}/show-undo`, {
70
- input: Schema2.Struct({
71
- message: Label
72
- }),
73
- output: Schema2.Void
74
- }) {
75
- }
76
- IntentAction2.ShowUndo = ShowUndo;
77
- })(IntentAction || (IntentAction = {}));
78
- var IntentAction;
79
-
80
- // src/plugin-intent/errors.ts
81
- var BaseError = class extends Error {
82
- constructor(code, message, context) {
83
- super(message ?? code, {
84
- cause: context
85
- }), this.code = code, this.context = context;
86
- this.name = code;
87
- Object.setPrototypeOf(this, new.target.prototype);
88
- }
89
- };
90
- var NoResolversError = class extends BaseError {
91
- constructor(action) {
92
- super("NO_RESOLVERS", "No resolvers were found for the action", {
93
- action
94
- });
95
- }
96
- };
97
- var CycleDetectedError = class extends BaseError {
98
- constructor(context) {
99
- super("CYCLE_DETECTED", "Intent execution limit exceeded. This is likely due to an infinite loop within intent resolvers.", context);
100
- }
101
- };
102
-
103
9
  // src/core/capabilities.ts
104
10
  import { Rx } from "@effect-rx/rx-react";
105
11
  import { Effect } from "effect";
@@ -114,6 +20,8 @@ var defineCapability = (identifier) => {
114
20
  };
115
21
  };
116
22
  var CapabilityImpl = class {
23
+ moduleId;
24
+ implementation;
117
25
  constructor(moduleId, implementation) {
118
26
  this.moduleId = moduleId;
119
27
  this.implementation = implementation;
@@ -131,31 +39,44 @@ var lazy = (c) => async (props) => {
131
39
  return async () => getCapability(props);
132
40
  };
133
41
  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
- });
42
+ _registry;
43
+ _capabilityImpls = Rx.family(() => {
44
+ return Rx.make([]).pipe(Rx.keepAlive);
45
+ });
46
+ _capabilities = Rx.family((id) => {
47
+ return Rx.make((get) => {
48
+ const current = get(this._capabilityImpls(id));
49
+ return current.map((c) => c.implementation);
143
50
  });
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];
51
+ });
52
+ _capability = Rx.family((id) => {
53
+ return Rx.make((get) => {
54
+ const current = get(this._capabilities(id));
55
+ invariant(current.length > 0, `No capability found for ${id}`, {
56
+ F: __dxlog_file,
57
+ L: 118,
58
+ S: this,
59
+ A: [
60
+ "current.length > 0",
61
+ "`No capability found for ${id}`"
62
+ ]
157
63
  });
64
+ return current[0];
158
65
  });
66
+ });
67
+ /**
68
+ * Activates plugins based on the activation event.
69
+ * @param event The activation event.
70
+ * @returns Whether the activation was successful.
71
+ */
72
+ activate;
73
+ /**
74
+ * Re-activates the modules that were activated by the event.
75
+ * @param event The activation event.
76
+ * @returns Whether the reset was successful.
77
+ */
78
+ reset;
79
+ constructor({ registry, activate, reset }) {
159
80
  this._registry = registry;
160
81
  this.activate = activate;
161
82
  this.reset = reset;
@@ -179,7 +100,7 @@ var PluginContext = class {
179
100
  count: current.length
180
101
  }, {
181
102
  F: __dxlog_file,
182
- L: 161,
103
+ L: 162,
183
104
  S: this,
184
105
  C: (f, a) => f(...a)
185
106
  });
@@ -200,7 +121,7 @@ var PluginContext = class {
200
121
  count: current.length
201
122
  }, {
202
123
  F: __dxlog_file,
203
- L: 180,
124
+ L: 181,
204
125
  S: this,
205
126
  C: (f, a) => f(...a)
206
127
  });
@@ -209,7 +130,7 @@ var PluginContext = class {
209
130
  id: interfaceDef.identifier
210
131
  }, {
211
132
  F: __dxlog_file,
212
- L: 182,
133
+ L: 183,
213
134
  S: this,
214
135
  C: (f, a) => f(...a)
215
136
  });
@@ -301,7 +222,7 @@ var getEvents = (events) => "type" in events ? events.events : [
301
222
  // src/core/manager.ts
302
223
  import { Registry } from "@effect-rx/rx-react";
303
224
  import { untracked } from "@preact/signals-core";
304
- import { Array as A, Effect as Effect2, Either, Match, pipe } from "effect";
225
+ import { Array, Duration, Effect as Effect2, Fiber, HashSet, Match, Ref, pipe } from "effect";
305
226
  import { Event } from "@dxos/async";
306
227
  import { live } from "@dxos/live-object";
307
228
  import { log as log2 } from "@dxos/log";
@@ -310,9 +231,17 @@ var isPromise = (value) => {
310
231
  return value !== null && typeof value === "object" && "then" in value;
311
232
  };
312
233
  var PluginManager = class {
234
+ activation = new Event();
235
+ context;
236
+ registry;
237
+ // TODO(wittjosiah): Replace with Rx.
238
+ _state;
239
+ _pluginLoader;
240
+ _capabilities = /* @__PURE__ */ new Map();
241
+ _moduleMemoMap = /* @__PURE__ */ new Map();
242
+ _activatingEvents = Effect2.runSync(Ref.make([]));
243
+ _activatingModules = Effect2.runSync(Ref.make([]));
313
244
  constructor({ pluginLoader, plugins = [], core = plugins.map(({ meta }) => meta.id), enabled = [], registry }) {
314
- this.activation = new Event();
315
- this._capabilities = /* @__PURE__ */ new Map();
316
245
  this.registry = registry ?? Registry.make();
317
246
  this.context = new PluginContext({
318
247
  registry: this.registry,
@@ -326,8 +255,8 @@ var PluginManager = class {
326
255
  enabled,
327
256
  modules: [],
328
257
  active: [],
329
- pendingReset: [],
330
- eventsFired: []
258
+ eventsFired: [],
259
+ pendingReset: []
331
260
  });
332
261
  plugins.forEach((plugin) => this._addPlugin(plugin));
333
262
  core.forEach((id) => this.enable(id));
@@ -399,7 +328,7 @@ var PluginManager = class {
399
328
  id
400
329
  }, {
401
330
  F: __dxlog_file2,
402
- L: 154,
331
+ L: 157,
403
332
  S: this,
404
333
  C: (f, a) => f(...a)
405
334
  });
@@ -418,7 +347,7 @@ var PluginManager = class {
418
347
  id
419
348
  }, {
420
349
  F: __dxlog_file2,
421
- L: 167,
350
+ L: 170,
422
351
  S: this,
423
352
  C: (f, a) => f(...a)
424
353
  });
@@ -439,7 +368,7 @@ var PluginManager = class {
439
368
  ]
440
369
  }, {
441
370
  F: __dxlog_file2,
442
- L: 182,
371
+ L: 185,
443
372
  S: this,
444
373
  C: (f, a) => f(...a)
445
374
  });
@@ -459,7 +388,7 @@ var PluginManager = class {
459
388
  id
460
389
  }, {
461
390
  F: __dxlog_file2,
462
- L: 200,
391
+ L: 203,
463
392
  S: this,
464
393
  C: (f, a) => f(...a)
465
394
  });
@@ -481,7 +410,7 @@ var PluginManager = class {
481
410
  id
482
411
  }, {
483
412
  F: __dxlog_file2,
484
- L: 217,
413
+ L: 220,
485
414
  S: this,
486
415
  C: (f, a) => f(...a)
487
416
  });
@@ -533,7 +462,7 @@ var PluginManager = class {
533
462
  id: plugin.meta.id
534
463
  }, {
535
464
  F: __dxlog_file2,
536
- L: 270,
465
+ L: 273,
537
466
  S: this,
538
467
  C: (f, a) => f(...a)
539
468
  });
@@ -548,7 +477,7 @@ var PluginManager = class {
548
477
  id
549
478
  }, {
550
479
  F: __dxlog_file2,
551
- L: 279,
480
+ L: 283,
552
481
  S: this,
553
482
  C: (f, a) => f(...a)
554
483
  });
@@ -564,7 +493,7 @@ var PluginManager = class {
564
493
  id: module.id
565
494
  }, {
566
495
  F: __dxlog_file2,
567
- L: 289,
496
+ L: 293,
568
497
  S: this,
569
498
  C: (f, a) => f(...a)
570
499
  });
@@ -579,7 +508,7 @@ var PluginManager = class {
579
508
  id
580
509
  }, {
581
510
  F: __dxlog_file2,
582
- L: 298,
511
+ L: 303,
583
512
  S: this,
584
513
  C: (f, a) => f(...a)
585
514
  });
@@ -607,13 +536,13 @@ var PluginManager = class {
607
536
  _setPendingResetByModule(module) {
608
537
  return untracked(() => {
609
538
  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));
539
+ const pendingReset = Array.fromIterable(new Set(activationEvents)).filter((event) => !this._state.pendingReset.includes(event));
611
540
  if (pendingReset.length > 0) {
612
541
  log2("pending reset", {
613
542
  events: pendingReset
614
543
  }, {
615
544
  F: __dxlog_file2,
616
- L: 336,
545
+ L: 341,
617
546
  S: this,
618
547
  C: (f, a) => f(...a)
619
548
  });
@@ -625,35 +554,40 @@ var PluginManager = class {
625
554
  * @internal
626
555
  */
627
556
  // TODO(wittjosiah): Improve error typing.
628
- _activate(event) {
557
+ _activate(event, params) {
629
558
  return Effect2.gen(this, function* () {
630
559
  const key = typeof event === "string" ? event : eventKey(event);
631
560
  log2("activating", {
632
- key
561
+ key,
562
+ ...params
633
563
  }, {
634
564
  F: __dxlog_file2,
635
- L: 349,
565
+ L: 357,
636
566
  S: this,
637
567
  C: (f, a) => f(...a)
638
568
  });
569
+ yield* Ref.update(this._activatingEvents, (activating) => Array.append(activating, key));
639
570
  const pendingIndex = this._state.pendingReset.findIndex((event2) => event2 === key);
640
571
  if (pendingIndex !== -1) {
641
572
  this._state.pendingReset.splice(pendingIndex, 1);
642
573
  }
574
+ const activatingEvents = yield* this._activatingEvents;
575
+ const activatingModules = yield* this._activatingModules;
643
576
  const modules = this._getInactiveModulesByEvent(key).filter((module) => {
644
577
  const allOf2 = isAllOf(module.activatesOn);
645
578
  if (!allOf2) {
646
579
  return true;
647
580
  }
648
581
  const events = module.activatesOn.events.filter((event2) => eventKey(event2) !== key);
649
- return events.every((event2) => this._state.eventsFired.includes(eventKey(event2)));
582
+ return events.every((event2) => this._state.eventsFired.includes(eventKey(event2)) || activatingEvents.includes(eventKey(event2))) && !activatingModules.includes(module.id);
650
583
  });
584
+ yield* Ref.update(this._activatingModules, (activating) => Array.appendAll(activating, modules.map((module) => module.id)));
651
585
  if (modules.length === 0) {
652
586
  log2("no modules to activate", {
653
587
  key
654
588
  }, {
655
589
  F: __dxlog_file2,
656
- L: 365,
590
+ L: 388,
657
591
  S: this,
658
592
  C: (f, a) => f(...a)
659
593
  });
@@ -667,7 +601,7 @@ var PluginManager = class {
667
601
  modules: modules.map((module) => module.id)
668
602
  }, {
669
603
  F: __dxlog_file2,
670
- L: 372,
604
+ L: 395,
671
605
  S: this,
672
606
  C: (f, a) => f(...a)
673
607
  });
@@ -675,29 +609,36 @@ var PluginManager = class {
675
609
  event: key,
676
610
  state: "activating"
677
611
  });
678
- const getCapabilities = yield* Effect2.all(modules.map(({ activate }) => Effect2.tryPromise({
679
- try: async () => activate(this.context),
680
- catch: (error) => error
681
- })), {
612
+ yield* pipe(modules, Array.flatMap((module) => module.activatesBefore ?? []), HashSet.fromIterable, HashSet.toValues, Array.filter((event2) => !activatingEvents.includes(eventKey(event2))), Array.map((event2) => this._activate(event2, {
613
+ before: key
614
+ })), Effect2.allWith({
682
615
  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)) {
616
+ }));
617
+ const getCapabilities = yield* pipe(modules, Array.map((mod) => this._loadModule(mod)), Effect2.allWith({
618
+ concurrency: "unbounded"
619
+ }), Effect2.catchAll((error) => {
694
620
  this.activation.emit({
695
621
  event: key,
696
622
  state: "error",
697
- error: result.left
623
+ error
698
624
  });
699
- yield* Effect2.fail(result.left);
700
- }
625
+ return Effect2.fail(error);
626
+ }));
627
+ yield* pipe(
628
+ modules,
629
+ Array.zip(getCapabilities),
630
+ Array.map(([module, capabilities]) => this._contributeCapabilities(module, capabilities)),
631
+ // TODO(wittjosiah): This currently can't be run in parallel.
632
+ // Running this with concurrency causes races with `allOf` activation events.
633
+ Effect2.all
634
+ );
635
+ yield* pipe(modules, Array.flatMap((module) => module.activatesAfter ?? []), HashSet.fromIterable, HashSet.toValues, Array.filter((event2) => !activatingEvents.includes(eventKey(event2))), Array.map((event2) => this._activate(event2, {
636
+ after: key
637
+ })), Effect2.allWith({
638
+ concurrency: "unbounded"
639
+ }));
640
+ yield* Ref.update(this._activatingEvents, (activating) => Array.filter(activating, (event2) => event2 !== key));
641
+ yield* Ref.update(this._activatingModules, (activating) => Array.filter(activating, (module) => !modules.map((module2) => module2.id).includes(module)));
701
642
  if (!this._state.eventsFired.includes(key)) {
702
643
  this._state.eventsFired.push(key);
703
644
  }
@@ -709,39 +650,76 @@ var PluginManager = class {
709
650
  key
710
651
  }, {
711
652
  F: __dxlog_file2,
712
- L: 406,
653
+ L: 451,
713
654
  S: this,
714
655
  C: (f, a) => f(...a)
715
656
  });
716
657
  return true;
717
658
  });
718
659
  }
719
- _activateModule(module, getCapabilities) {
660
+ // Memoized with _moduleMemoMap
661
+ _loadModule = (mod) => Effect2.tryPromise({
662
+ try: async () => {
663
+ const entry = this._moduleMemoMap.get(mod.id);
664
+ if (entry) {
665
+ return entry;
666
+ }
667
+ const promise = (async () => {
668
+ const start = performance.now();
669
+ let failed = false;
670
+ try {
671
+ log2("loading module", {
672
+ module: mod.id
673
+ }, {
674
+ F: __dxlog_file2,
675
+ L: 470,
676
+ S: this,
677
+ C: (f, a) => f(...a)
678
+ });
679
+ let activationResult = await mod.activate(this.context);
680
+ if (typeof activationResult === "function") {
681
+ activationResult = await activationResult();
682
+ }
683
+ return Array.isArray(activationResult) ? activationResult : [
684
+ activationResult
685
+ ];
686
+ } catch (error) {
687
+ failed = true;
688
+ throw error;
689
+ } finally {
690
+ performance.measure("activate-module", {
691
+ start,
692
+ end: performance.now(),
693
+ detail: {
694
+ module: mod.id
695
+ }
696
+ });
697
+ log2("loaded module", {
698
+ module: mod.id,
699
+ elapsed: performance.now() - start,
700
+ failed
701
+ }, {
702
+ F: __dxlog_file2,
703
+ L: 488,
704
+ S: this,
705
+ C: (f, a) => f(...a)
706
+ });
707
+ }
708
+ })();
709
+ this._moduleMemoMap.set(mod.id, promise);
710
+ return promise;
711
+ },
712
+ catch: (error) => error
713
+ }).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`, {
714
+ module: mod.id
715
+ }, {
716
+ F: __dxlog_file2,
717
+ L: 499,
718
+ S: this,
719
+ C: (f, a) => f(...a)
720
+ }))))));
721
+ _contributeCapabilities(module, capabilities) {
720
722
  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
723
  capabilities.forEach((capability) => {
746
724
  this.context.contributeCapability({
747
725
  module: module.id,
@@ -750,17 +728,6 @@ var PluginManager = class {
750
728
  });
751
729
  this._state.active.push(module.id);
752
730
  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
731
  });
765
732
  }
766
733
  _deactivate(id) {
@@ -783,10 +750,11 @@ var PluginManager = class {
783
750
  id
784
751
  }, {
785
752
  F: __dxlog_file2,
786
- L: 471,
753
+ L: 533,
787
754
  S: this,
788
755
  C: (f, a) => f(...a)
789
756
  });
757
+ this._moduleMemoMap.delete(id);
790
758
  const capabilities = this._capabilities.get(id);
791
759
  if (capabilities) {
792
760
  for (const capability of capabilities) {
@@ -807,7 +775,7 @@ var PluginManager = class {
807
775
  id
808
776
  }, {
809
777
  F: __dxlog_file2,
810
- L: 497,
778
+ L: 560,
811
779
  S: this,
812
780
  C: (f, a) => f(...a)
813
781
  });
@@ -821,7 +789,7 @@ var PluginManager = class {
821
789
  key
822
790
  }, {
823
791
  F: __dxlog_file2,
824
- L: 505,
792
+ L: 568,
825
793
  S: this,
826
794
  C: (f, a) => f(...a)
827
795
  });
@@ -837,9 +805,20 @@ var PluginManager = class {
837
805
  });
838
806
  }
839
807
  };
808
+ var together = (togetherEffect) => (effect) => Effect2.gen(function* () {
809
+ const togetherFiber = yield* Effect2.fork(togetherEffect);
810
+ const result = yield* effect;
811
+ yield* Fiber.interrupt(togetherFiber);
812
+ return result;
813
+ });
840
814
 
841
815
  // src/core/plugin.ts
842
816
  var PluginModule = class {
817
+ id;
818
+ activatesOn;
819
+ activatesBefore;
820
+ activatesAfter;
821
+ activate;
843
822
  constructor(options) {
844
823
  this.id = options.id;
845
824
  this.activatesOn = options.activatesOn;
@@ -850,6 +829,8 @@ var PluginModule = class {
850
829
  };
851
830
  var defineModule = (options) => new PluginModule(options);
852
831
  var Plugin = class {
832
+ meta;
833
+ modules;
853
834
  constructor(meta, modules) {
854
835
  this.meta = meta;
855
836
  this.modules = modules;
@@ -878,7 +859,9 @@ var definePlugin = (meta, modules) => {
878
859
  Capabilities2.Settings = defineCapability("dxos.org/app-framework/capability/settings");
879
860
  Capabilities2.Metadata = defineCapability("dxos.org/app-framework/capability/metadata");
880
861
  Capabilities2.Tools = defineCapability("dxos.org/app-framework/capability/tools");
881
- Capabilities2.ArtifactDefinition = defineCapability("dxos.org/app-framework/capability/artifact-definition");
862
+ Capabilities2.Toolkit = defineCapability("dxos.org/app-framework/capability/ai-toolkit");
863
+ Capabilities2.ToolkitHandler = defineCapability("dxos.org/app-framework/capability/ai-toolkit-handler");
864
+ Capabilities2.BlueprintDefinition = defineCapability("dxos.org/app-framework/capability/blueprint-definition");
882
865
  Capabilities2.Functions = defineCapability("dxos.org/app-framework/capability/functions");
883
866
  Capabilities2.FileUploader = defineCapability("dxos.org/app-framework/capability/file-uploader");
884
867
  Capabilities2.AnchorSort = defineCapability("dxos.org/app-framework/capability/anchor-sort");
@@ -886,19 +869,19 @@ var definePlugin = (meta, modules) => {
886
869
  var Capabilities;
887
870
 
888
871
  // src/common/collaboration.ts
889
- import { Schema as Schema3 } from "effect";
890
- import { Expando, Ref } from "@dxos/echo-schema";
872
+ import { Schema } from "effect";
873
+ import { Expando, Ref as Ref2 } from "@dxos/echo-schema";
891
874
  (function(CollaborationActions2) {
892
- class InsertContent extends Schema3.TaggedClass()("assistant/intent-content", {
893
- input: Schema3.Struct({
875
+ class InsertContent extends Schema.TaggedClass()("assistant/intent-content", {
876
+ input: Schema.Struct({
894
877
  target: Expando,
895
- object: Ref(Expando),
896
- at: Schema3.optional(Schema3.String),
897
- label: Schema3.String.pipe(Schema3.optional)
878
+ object: Ref2(Expando),
879
+ at: Schema.optional(Schema.String),
880
+ label: Schema.String.pipe(Schema.optional)
898
881
  }).annotations({
899
882
  description: "Enables plugins to inject content blocks or references into a related entity."
900
883
  }),
901
- output: Schema3.Void
884
+ output: Schema.Void
902
885
  }) {
903
886
  }
904
887
  CollaborationActions2.InsertContent = InsertContent;
@@ -924,7 +907,7 @@ var CollaborationActions;
924
907
  var Events;
925
908
 
926
909
  // src/common/file.ts
927
- import { Schema as Schema4 } from "effect";
910
+ import { Schema as Schema2 } from "effect";
928
911
  var defaultFileTypes = {
929
912
  images: [
930
913
  "png",
@@ -944,16 +927,87 @@ var defaultFileTypes = {
944
927
  "md"
945
928
  ]
946
929
  };
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)
930
+ var FileInfoSchema = Schema2.Struct({
931
+ name: Schema2.String,
932
+ type: Schema2.String,
933
+ url: Schema2.optional(Schema2.String),
934
+ cid: Schema2.optional(Schema2.String)
952
935
  });
953
936
 
954
937
  // src/common/layout.ts
955
938
  import { Schema as Schema5 } from "effect";
956
939
 
940
+ // src/plugin-intent/actions.ts
941
+ import { Schema as Schema4 } from "effect";
942
+
943
+ // src/plugin-intent/intent.ts
944
+ import { Schema as Schema3 } from "effect";
945
+ var createIntent = (schema, data = {}, params = {}) => {
946
+ const _ = Schema3.validateSync(schema.fields.input)(data);
947
+ const intent = {
948
+ ...params,
949
+ _schema: schema,
950
+ id: schema._tag,
951
+ data
952
+ };
953
+ return {
954
+ first: intent,
955
+ last: intent,
956
+ all: [
957
+ intent
958
+ ]
959
+ };
960
+ };
961
+ var chain = (schema, data = {}, params = {}) => (intent) => {
962
+ const intents = "all" in intent ? intent.all : [
963
+ intent
964
+ ];
965
+ const first = intents[0];
966
+ const last = {
967
+ ...params,
968
+ _schema: schema,
969
+ id: schema._tag,
970
+ data
971
+ };
972
+ return {
973
+ first,
974
+ last,
975
+ all: [
976
+ ...intents,
977
+ last
978
+ ]
979
+ };
980
+ };
981
+ var Label = Schema3.Union(Schema3.String, Schema3.mutable(Schema3.Tuple(Schema3.String, Schema3.mutable(Schema3.Struct({
982
+ ns: Schema3.String,
983
+ count: Schema3.optional(Schema3.Number),
984
+ defaultValue: Schema3.optional(Schema3.String)
985
+ })))));
986
+
987
+ // src/plugin-intent/actions.ts
988
+ var INTENT_PLUGIN = "dxos.org/plugin/intent";
989
+ var INTENT_ACTION = `${INTENT_PLUGIN}/action`;
990
+ (function(IntentAction2) {
991
+ class Track extends Schema4.TaggedClass()(`${INTENT_ACTION}/track`, {
992
+ input: Schema4.Struct({
993
+ intents: Schema4.Array(Schema4.String),
994
+ error: Schema4.optional(Schema4.String)
995
+ }),
996
+ output: Schema4.Void
997
+ }) {
998
+ }
999
+ IntentAction2.Track = Track;
1000
+ class ShowUndo extends Schema4.TaggedClass()(`${INTENT_ACTION}/show-undo`, {
1001
+ input: Schema4.Struct({
1002
+ message: Label
1003
+ }),
1004
+ output: Schema4.Void
1005
+ }) {
1006
+ }
1007
+ IntentAction2.ShowUndo = ShowUndo;
1008
+ })(IntentAction || (IntentAction = {}));
1009
+ var IntentAction;
1010
+
957
1011
  // src/plugin-intent/IntentPlugin.ts
958
1012
  var IntentPlugin = () => definePlugin({
959
1013
  id: INTENT_PLUGIN,
@@ -968,7 +1022,7 @@ var IntentPlugin = () => definePlugin({
968
1022
  activatesAfter: [
969
1023
  Events.DispatcherReady
970
1024
  ],
971
- activate: lazy(() => import("./intent-dispatcher-6CYNGPSW.mjs"))
1025
+ activate: lazy(() => import("./intent-dispatcher-YQIQ55LJ.mjs"))
972
1026
  })
973
1027
  ]);
974
1028
 
@@ -1327,6 +1381,31 @@ var Resource = Schema6.Record({
1327
1381
  value: ResourceLanguage
1328
1382
  });
1329
1383
 
1384
+ // src/plugin-intent/errors.ts
1385
+ var BaseError = class extends Error {
1386
+ code;
1387
+ context;
1388
+ constructor(code, message, context) {
1389
+ super(message ?? code, {
1390
+ cause: context
1391
+ }), this.code = code, this.context = context;
1392
+ this.name = code;
1393
+ Object.setPrototypeOf(this, new.target.prototype);
1394
+ }
1395
+ };
1396
+ var NoResolversError = class extends BaseError {
1397
+ constructor(action) {
1398
+ super("NO_RESOLVERS", "No resolvers were found for the action", {
1399
+ action
1400
+ });
1401
+ }
1402
+ };
1403
+ var CycleDetectedError = class extends BaseError {
1404
+ constructor(context) {
1405
+ super("CYCLE_DETECTED", "Intent execution limit exceeded. This is likely due to an infinite loop within intent resolvers.", context);
1406
+ }
1407
+ };
1408
+
1330
1409
  // src/plugin-intent/intent-dispatcher.ts
1331
1410
  var __dxlog_file3 = "/__w/dxos/dxos/packages/sdk/app-framework/src/plugin-intent/intent-dispatcher.ts";
1332
1411
  var EXECUTION_LIMIT = 100;
@@ -1334,7 +1413,7 @@ var HISTORY_LIMIT = 100;
1334
1413
  var createResolver = (resolver) => resolver;
1335
1414
  var isUndoable = (historyEntry) => historyEntry.length > 0 && historyEntry.every(({ undoable }) => !!undoable);
1336
1415
  var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, historyLimit = HISTORY_LIMIT } = {}) => {
1337
- const historyRef = Effect3.runSync(Ref2.make([]));
1416
+ const historyRef = Effect3.runSync(Ref3.make([]));
1338
1417
  const handleIntent = (intent) => Effect3.gen(function* () {
1339
1418
  const candidates = getResolvers().filter((resolver) => resolver.intent._tag === intent.id).filter((resolver) => !resolver.filter || resolver.filter(intent.data)).toSorted(byPosition);
1340
1419
  if (candidates.length === 0) {
@@ -1352,7 +1431,7 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1352
1431
  if (depth > executionLimit) {
1353
1432
  yield* Effect3.fail(new CycleDetectedError());
1354
1433
  }
1355
- const resultsRef = yield* Ref2.make([]);
1434
+ const resultsRef = yield* Ref3.make([]);
1356
1435
  for (const intent of intentChain.all) {
1357
1436
  const { data: prev } = (yield* resultsRef.get)[0] ?? {};
1358
1437
  const result2 = yield* handleIntent({
@@ -1362,7 +1441,7 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1362
1441
  ...prev
1363
1442
  }
1364
1443
  });
1365
- yield* Ref2.update(resultsRef, (results2) => [
1444
+ yield* Ref3.update(resultsRef, (results2) => [
1366
1445
  result2,
1367
1446
  ...results2
1368
1447
  ]);
@@ -1377,7 +1456,7 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1377
1456
  }
1378
1457
  const results = yield* resultsRef.get;
1379
1458
  const result = results[0];
1380
- yield* Ref2.update(historyRef, (history) => {
1459
+ yield* Ref3.update(historyRef, (history) => {
1381
1460
  const next = [
1382
1461
  ...history,
1383
1462
  results
@@ -1401,7 +1480,7 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1401
1480
  })).catch((error) => {
1402
1481
  log3.catch(error, void 0, {
1403
1482
  F: __dxlog_file3,
1404
- L: 270,
1483
+ L: 271,
1405
1484
  S: void 0,
1406
1485
  C: (f, a) => f(...a)
1407
1486
  });
@@ -1433,7 +1512,7 @@ var createDispatcher = (getResolvers, { executionLimit = EXECUTION_LIMIT, histor
1433
1512
  last: all.at(-1),
1434
1513
  all
1435
1514
  };
1436
- yield* Ref2.update(historyRef, (h) => h.filter((_, index) => index !== last));
1515
+ yield* Ref3.update(historyRef, (h) => h.filter((_, index) => index !== last));
1437
1516
  return yield* dispatch(intent);
1438
1517
  }
1439
1518
  });
@@ -1518,4 +1597,4 @@ export {
1518
1597
  ResourceLanguage,
1519
1598
  Resource
1520
1599
  };
1521
- //# sourceMappingURL=chunk-ZEZ4FVEU.mjs.map
1600
+ //# sourceMappingURL=chunk-YEN7NKTF.mjs.map