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

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