@atlaskit/editor-plugin-mentions 15.0.2 → 15.0.4

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.
@@ -0,0 +1,763 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.resolveAndDispatchPastedAgentMentionName = exports.createAgentMentionPluginView = exports.createAgentMentionPlugin = exports.applyAgentMentionState = exports.agentMentionPluginKey = void 0;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
11
+ var _state = require("@atlaskit/editor-prosemirror/state");
12
+ var _resource = require("@atlaskit/mention/resource");
13
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
14
+ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
15
+ var _agentMentionContext = require("./agent-mention-context");
16
+ var _key = require("./key");
17
+ var _main = require("./main");
18
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
19
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
20
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
21
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
22
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
23
+ // 'AGENT' is not in the ADF schema UserType enum but is used at runtime.
24
+
25
+ var AGENT_USER_TYPES = new Set(['APP', 'AGENT']);
26
+ var isAgentUserType = function isAgentUserType(userType) {
27
+ return typeof userType === 'string' && AGENT_USER_TYPES.has(userType);
28
+ };
29
+ var getAgentMentionName = function getAgentMentionName(text, fallbackName) {
30
+ var trimmedFallbackName = typeof fallbackName === 'string' ? fallbackName.trim() : '';
31
+ var normalizedFallbackName = (trimmedFallbackName.startsWith('@') ? trimmedFallbackName.slice(1).trim() : trimmedFallbackName) || null;
32
+ if (typeof text !== 'string') {
33
+ return normalizedFallbackName;
34
+ }
35
+ var trimmedText = text.trim();
36
+ var displayName = trimmedText.startsWith('@') ? trimmedText.slice(1).trim() : trimmedText;
37
+ var normalizedName = displayName || normalizedFallbackName;
38
+ return normalizedName;
39
+ };
40
+ var AI_STREAMING_TRANSFORMATION_META_KEY = 'isAIStreamingTransformation';
41
+ var AGENT_MENTION_INACTIVITY_MS = 3000;
42
+ var MAX_PENDING_TYPED_AGENT_MENTION_FOCUS_DEFERS = 20;
43
+ /**
44
+ * Returns true when a transaction represents a local user document edit that
45
+ * should restart pending agent-mention inactivity tracking.
46
+ *
47
+ * Remote/collab updates, replace-document transactions, AI streaming transforms,
48
+ * selection-only movements, and metadata-only transactions are intentionally ignored.
49
+ */
50
+ var isQualifyingLocalUserDocChange = function isQualifyingLocalUserDocChange(tr) {
51
+ var isAIStreaming = Boolean(tr.getMeta(AI_STREAMING_TRANSFORMATION_META_KEY));
52
+ return tr.docChanged && !tr.getMeta('isRemote') && !tr.getMeta('replaceDocument') && !isAIStreaming;
53
+ };
54
+ var isLocalSelectionChange = function isLocalSelectionChange(tr, hasPositionChanged) {
55
+ var isAIStreaming = Boolean(tr.getMeta(AI_STREAMING_TRANSFORMATION_META_KEY));
56
+
57
+ // Pressing Enter can move selection through a doc split without setting tr.selectionSet
58
+ // or changing from/to numerically, so local doc changes are checked against the
59
+ // pending mention's current parent before publishing.
60
+ return (hasPositionChanged || tr.docChanged) && !tr.getMeta('isRemote') && !tr.getMeta('replaceDocument') && !isAIStreaming;
61
+ };
62
+
63
+ /**
64
+ * Reads agent-mention details from a known document position without traversing
65
+ * the document. Callers pass a matcher so mapped positions are only accepted
66
+ * when they still point at the same pending/tracked mention.
67
+ */
68
+ var getAgentMentionDetailsAtPos = function getAgentMentionDetailsAtPos(state, pos, matchesMention, fallbackName) {
69
+ var _parentNode$type$name;
70
+ if (pos < 0 || pos > state.doc.content.size) {
71
+ return null;
72
+ }
73
+ var node = state.doc.nodeAt(pos);
74
+ var mentionSchema = state.schema.nodes.mention;
75
+ if ((node === null || node === void 0 ? void 0 : node.type) !== mentionSchema || !isAgentUserType(node.attrs.userType) || !matchesMention(node.attrs) || !node.attrs.id || !node.attrs.localId) {
76
+ return null;
77
+ }
78
+ var $mentionPos = state.doc.resolve(Math.min(pos + node.nodeSize, state.doc.content.size));
79
+ var parentNode = $mentionPos.node($mentionPos.depth);
80
+ var id = node.attrs.id;
81
+ var name = getAgentMentionName(node.attrs.text, fallbackName);
82
+ return {
83
+ id: id,
84
+ localId: node.attrs.localId,
85
+ context: (0, _agentMentionContext.getAgentMentionParentContext)(parentNode, node.attrs.localId),
86
+ name: name,
87
+ prompt: parentNode.textContent.trim() || null,
88
+ nodeSize: node.nodeSize,
89
+ parentEnd: $mentionPos.end($mentionPos.depth),
90
+ parentNodeType: (_parentNode$type$name = parentNode.type.name) !== null && _parentNode$type$name !== void 0 ? _parentNode$type$name : null,
91
+ parentStart: $mentionPos.start($mentionPos.depth),
92
+ pos: pos
93
+ };
94
+ };
95
+
96
+ /**
97
+ * Finds an agent mention that survived a document change when the changed-range
98
+ * scan did not find one. Uses the tracked localId as the mention instance identity
99
+ * so same-agent mentions elsewhere in the document cannot be selected as fallback.
100
+ */
101
+ var getSurvivingAgentMentionDetails = function getSurvivingAgentMentionDetails(state, preferredLocalId, preferredName) {
102
+ var mentionSchema = state.schema.nodes.mention;
103
+ var result = null;
104
+ state.doc.descendants(function (node, pos) {
105
+ if (result) {
106
+ return false;
107
+ }
108
+ if (node.type !== mentionSchema || !isAgentUserType(node.attrs.userType) || node.attrs.localId !== preferredLocalId) {
109
+ return true;
110
+ }
111
+ result = getAgentMentionDetailsAtPos(state, pos, function (attrs) {
112
+ return attrs.localId === preferredLocalId;
113
+ }, preferredName);
114
+ return !result;
115
+ });
116
+ return result;
117
+ };
118
+
119
+ /**
120
+ * Maps a pending typed agent mention through a document-changing transaction and
121
+ * returns the updated pending state. If the mapped position was deleted or no
122
+ * longer points at the same local mention, the pending mention is cleared.
123
+ */
124
+ var getPendingTypedAgentMentionAfterDocChange = function getPendingTypedAgentMentionAfterDocChange(state, tr, pendingTypedAgentMention, _ref) {
125
+ var resetTimer = _ref.resetTimer;
126
+ var mappedPos = tr.mapping.mapResult(pendingTypedAgentMention.pos, 1);
127
+ var resetCount = resetTimer ? pendingTypedAgentMention.resetCount + 1 : pendingTypedAgentMention.resetCount;
128
+ if (mappedPos.deleted) {
129
+ return null;
130
+ }
131
+ var pendingMentionDetails = getAgentMentionDetailsAtPos(state, mappedPos.pos, function (attrs) {
132
+ return attrs.localId === pendingTypedAgentMention.localId;
133
+ }, pendingTypedAgentMention.name);
134
+ return pendingMentionDetails ? {
135
+ id: pendingMentionDetails.id,
136
+ localId: pendingTypedAgentMention.localId,
137
+ name: pendingMentionDetails.name,
138
+ nodeSize: pendingMentionDetails.nodeSize,
139
+ parentNodeType: pendingMentionDetails.parentNodeType,
140
+ pos: pendingMentionDetails.pos,
141
+ resetCount: resetCount
142
+ } : null;
143
+ };
144
+ var hasPendingMentionMovedToNewParent = function hasPendingMentionMovedToNewParent(oldState, tr, previousPendingTypedAgentMention, pendingMentionDetails) {
145
+ if (!previousPendingTypedAgentMention) {
146
+ return false;
147
+ }
148
+ var previousMentionDetails = getAgentMentionDetailsAtPos(oldState, previousPendingTypedAgentMention.pos, function (attrs) {
149
+ return attrs.localId === previousPendingTypedAgentMention.localId;
150
+ });
151
+
152
+ // Keep the previous parent boundary associated with the left side of an
153
+ // insertion at that boundary, so typing at the start of the parent does not
154
+ // look like the pending mention moved into a new parent.
155
+ var mappedPreviousParentStart = previousMentionDetails && tr.mapping.map(previousMentionDetails.parentStart, -1);
156
+ return Boolean(previousMentionDetails && mappedPreviousParentStart !== pendingMentionDetails.parentStart);
157
+ };
158
+ var isSelectionOutsideDirectParent = function isSelectionOutsideDirectParent(state, pendingMentionDetails) {
159
+ return state.selection.from < pendingMentionDetails.parentStart || state.selection.to > pendingMentionDetails.parentEnd;
160
+ };
161
+
162
+ /**
163
+ * Finalises a pending typed agent mention by copying its details into the
164
+ * public lastInserted* plugin state after the caller has already resolved the
165
+ * pending mention from the current document.
166
+ */
167
+ var commitResolvedPendingTypedAgentMention = function commitResolvedPendingTypedAgentMention(pluginState, pendingMentionDetails) {
168
+ var _pluginState$lastAgen;
169
+ return {
170
+ hasPublicPluginStateChanged: true,
171
+ pluginState: _objectSpread(_objectSpread({}, pluginState), {}, {
172
+ pendingTypedAgentMention: null,
173
+ lastInsertedAgentMentionId: pendingMentionDetails.id,
174
+ lastInsertedAgentMentionLocalId: pendingMentionDetails.localId,
175
+ lastInsertedAgentMentionContext: pendingMentionDetails.context,
176
+ lastInsertedAgentMentionName: pendingMentionDetails.name,
177
+ lastInsertedAgentMentionPrompt: pendingMentionDetails.prompt,
178
+ lastInsertedAgentMentionParentNodeType: pendingMentionDetails.parentNodeType,
179
+ lastAgentMentionInsertionCount: ((_pluginState$lastAgen = pluginState.lastAgentMentionInsertionCount) !== null && _pluginState$lastAgen !== void 0 ? _pluginState$lastAgen : 0) + 1
180
+ })
181
+ };
182
+ };
183
+
184
+ /**
185
+ * Resolves and finalises a pending typed agent mention. If the tracked mention
186
+ * no longer resolves, the stale pending state is cleared without dispatching a
187
+ * public update.
188
+ */
189
+ var commitPendingTypedAgentMention = function commitPendingTypedAgentMention(state, pluginState, pendingTypedAgentMention) {
190
+ var pendingMentionDetails = getAgentMentionDetailsAtPos(state, pendingTypedAgentMention.pos, function (attrs) {
191
+ return attrs.localId === pendingTypedAgentMention.localId;
192
+ }, pendingTypedAgentMention.name);
193
+ if (!pendingMentionDetails) {
194
+ return {
195
+ hasPublicPluginStateChanged: false,
196
+ pluginState: _objectSpread(_objectSpread({}, pluginState), {}, {
197
+ pendingTypedAgentMention: null
198
+ })
199
+ };
200
+ }
201
+ return commitResolvedPendingTypedAgentMention(pluginState, pendingMentionDetails);
202
+ };
203
+ var hasTrackedAgentMentionState = function hasTrackedAgentMentionState(pluginState) {
204
+ return Boolean(pluginState.pendingTypedAgentMention) || Boolean(pluginState.pendingPastedAgentMention) && (0, _platformFeatureFlags.fg)('platform_editor_agent_mentions_drop_one_fixes') || pluginState.lastInsertedAgentMentionId != null || pluginState.lastInsertedAgentMentionLocalId != null || pluginState.lastInsertedAgentMentionContext != null || pluginState.lastInsertedAgentMentionName != null || pluginState.lastInsertedAgentMentionPrompt != null || pluginState.lastInsertedAgentMentionParentNodeType != null;
205
+ };
206
+
207
+ /**
208
+ * Clears agent mention state that points at a specific document snapshot.
209
+ * replaceDocument swaps content wholesale, so pending typed mentions and
210
+ * lastInserted* details from the previous document must be cleared together.
211
+ */
212
+ var clearTrackedAgentMentionState = function clearTrackedAgentMentionState(pluginState) {
213
+ return _objectSpread(_objectSpread(_objectSpread({}, pluginState), {}, {
214
+ pendingTypedAgentMention: null
215
+ }, (0, _platformFeatureFlags.fg)('platform_editor_agent_mentions_drop_one_fixes') ? {
216
+ pendingPastedAgentMention: null
217
+ } : {}), {}, {
218
+ lastInsertedAgentMentionId: null,
219
+ lastInsertedAgentMentionLocalId: null,
220
+ lastInsertedAgentMentionContext: null,
221
+ lastInsertedAgentMentionName: null,
222
+ lastInsertedAgentMentionPrompt: null,
223
+ lastInsertedAgentMentionParentNodeType: null
224
+ });
225
+ };
226
+
227
+ /**
228
+ * Attempts to synchronously resolve an agent mention name from the mention
229
+ * provider's cache. Falls back to undefined if the provider doesn't support
230
+ * name resolution, the result is a Promise (async/cache miss), or the status
231
+ * is not OK.
232
+ */
233
+ var resolveCachedAgentMentionName = function resolveCachedAgentMentionName(mentionProvider, params, id) {
234
+ if (params !== null && params !== void 0 && params.name || !(0, _resource.isResolvingMentionProvider)(mentionProvider)) {
235
+ var _params$name;
236
+ return (_params$name = params === null || params === void 0 ? void 0 : params.name) !== null && _params$name !== void 0 ? _params$name : undefined;
237
+ }
238
+ var result = mentionProvider.resolveMentionName(id);
239
+ if (!(result instanceof Promise) && result.status === _resource.MentionNameStatus.OK) {
240
+ return result.name || undefined;
241
+ }
242
+ return undefined;
243
+ };
244
+
245
+ /**
246
+ * Resolves the name of a pasted agent mention via the mention provider and
247
+ * dispatches the appropriate action to update plugin state.
248
+ */
249
+ var resolveAndDispatchPastedAgentMentionName = exports.resolveAndDispatchPastedAgentMentionName = function resolveAndDispatchPastedAgentMentionName(agentId, mentionProvider, pendingResolveMentionIds, view) {
250
+ if (pendingResolveMentionIds.has(agentId)) {
251
+ return;
252
+ }
253
+ pendingResolveMentionIds.add(agentId);
254
+ var result = mentionProvider.resolveMentionName(agentId);
255
+ if (result instanceof Promise) {
256
+ result.then(function (nameDetails) {
257
+ pendingResolveMentionIds.delete(agentId);
258
+ if (nameDetails.status === _resource.MentionNameStatus.OK && nameDetails.name) {
259
+ view.dispatch(view.state.tr.setMeta(_key.mentionPluginKey, {
260
+ action: _main.ACTIONS.RESOLVE_PASTED_AGENT_MENTION_NAME,
261
+ params: {
262
+ id: agentId,
263
+ name: nameDetails.name
264
+ }
265
+ }));
266
+ } else {
267
+ view.dispatch(view.state.tr.setMeta(_key.mentionPluginKey, {
268
+ action: _main.ACTIONS.CLEAR_PENDING_PASTED_AGENT_MENTION,
269
+ params: {
270
+ id: agentId
271
+ }
272
+ }));
273
+ }
274
+ }).catch(function () {
275
+ pendingResolveMentionIds.delete(agentId);
276
+ });
277
+ } else if (result.status === _resource.MentionNameStatus.OK && result.name) {
278
+ pendingResolveMentionIds.delete(agentId);
279
+ view.dispatch(view.state.tr.setMeta(_key.mentionPluginKey, {
280
+ action: _main.ACTIONS.RESOLVE_PASTED_AGENT_MENTION_NAME,
281
+ params: {
282
+ id: agentId,
283
+ name: result.name
284
+ }
285
+ }));
286
+ } else {
287
+ pendingResolveMentionIds.delete(agentId);
288
+ view.dispatch(view.state.tr.setMeta(_key.mentionPluginKey, {
289
+ action: _main.ACTIONS.CLEAR_PENDING_PASTED_AGENT_MENTION,
290
+ params: {
291
+ id: agentId
292
+ }
293
+ }));
294
+ }
295
+ };
296
+ var applyAgentMentionState = exports.applyAgentMentionState = function applyAgentMentionState(_ref2) {
297
+ var tr = _ref2.tr,
298
+ pluginState = _ref2.pluginState,
299
+ oldState = _ref2.oldState,
300
+ newState = _ref2.newState,
301
+ getIsRovoPanelOpen = _ref2.getIsRovoPanelOpen;
302
+ // mentionPluginKey intentionally remains the shared transaction action channel while
303
+ // agentMentionPluginKey owns the extracted agent state.
304
+ var _ref3 = tr.getMeta(_key.mentionPluginKey) || {
305
+ action: null,
306
+ params: null
307
+ },
308
+ action = _ref3.action,
309
+ params = _ref3.params;
310
+ var hasPublicPluginStateChanged = false;
311
+ var newPluginState = pluginState;
312
+ var isAgentMentionsExperimentEnabled = (0, _experiments.editorExperiment)('platform_editor_agent_mentions', true);
313
+ var hasPositionChanged = oldState.selection.from !== newState.selection.from || oldState.selection.to !== newState.selection.to;
314
+ switch (action) {
315
+ case _main.ACTIONS.COMMIT_PENDING_TYPED_AGENT_MENTION:
316
+ {
317
+ var pendingTypedAgentMention = newPluginState.pendingTypedAgentMention;
318
+ if (!isAgentMentionsExperimentEnabled || !pendingTypedAgentMention || pendingTypedAgentMention.localId !== (params === null || params === void 0 ? void 0 : params.localId) || pendingTypedAgentMention.resetCount !== (params === null || params === void 0 ? void 0 : params.resetCount)) {
319
+ break;
320
+ }
321
+ var commitResult = commitPendingTypedAgentMention(newState, newPluginState, pendingTypedAgentMention);
322
+ newPluginState = commitResult.pluginState;
323
+ hasPublicPluginStateChanged = hasPublicPluginStateChanged || commitResult.hasPublicPluginStateChanged;
324
+ break;
325
+ }
326
+ case _main.ACTIONS.DISCARD_PENDING_TYPED_AGENT_MENTION:
327
+ {
328
+ var pendingTypedAgentMentionToDiscard = newPluginState.pendingTypedAgentMention;
329
+ if (!isAgentMentionsExperimentEnabled || !pendingTypedAgentMentionToDiscard || pendingTypedAgentMentionToDiscard.localId !== (params === null || params === void 0 ? void 0 : params.localId) || pendingTypedAgentMentionToDiscard.resetCount !== (params === null || params === void 0 ? void 0 : params.resetCount)) {
330
+ break;
331
+ }
332
+ newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
333
+ pendingTypedAgentMention: null
334
+ });
335
+ hasPublicPluginStateChanged = true;
336
+ break;
337
+ }
338
+ case _main.ACTIONS.SET_PROVIDER:
339
+ newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
340
+ mentionProvider: params.provider
341
+ });
342
+ hasPublicPluginStateChanged = true;
343
+ break;
344
+ case _main.ACTIONS.RESOLVE_PASTED_AGENT_MENTION_NAME:
345
+ {
346
+ var _newPluginState$pendi, _newPluginState$pendi2, _newPluginState$pendi3, _newPluginState$pendi4, _newPluginState$pendi5, _newPluginState$pendi6;
347
+ if (!isAgentMentionsExperimentEnabled || !(params !== null && params !== void 0 && params.id) || !(params !== null && params !== void 0 && params.name) || ((_newPluginState$pendi = newPluginState.pendingPastedAgentMention) === null || _newPluginState$pendi === void 0 ? void 0 : _newPluginState$pendi.id) !== params.id || !(0, _platformFeatureFlags.fg)('platform_editor_agent_mentions_drop_one_fixes')) {
348
+ break;
349
+ }
350
+ newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
351
+ pendingPastedAgentMention: null,
352
+ lastInsertedAgentMentionId: (_newPluginState$pendi2 = newPluginState.pendingPastedAgentMention) === null || _newPluginState$pendi2 === void 0 ? void 0 : _newPluginState$pendi2.id,
353
+ lastInsertedAgentMentionLocalId: (_newPluginState$pendi3 = newPluginState.pendingPastedAgentMention) === null || _newPluginState$pendi3 === void 0 ? void 0 : _newPluginState$pendi3.localId,
354
+ lastInsertedAgentMentionContext: (_newPluginState$pendi4 = newPluginState.pendingPastedAgentMention) === null || _newPluginState$pendi4 === void 0 ? void 0 : _newPluginState$pendi4.context,
355
+ lastInsertedAgentMentionName: params.name,
356
+ lastInsertedAgentMentionPrompt: (_newPluginState$pendi5 = newPluginState.pendingPastedAgentMention) === null || _newPluginState$pendi5 === void 0 ? void 0 : _newPluginState$pendi5.prompt,
357
+ lastInsertedAgentMentionParentNodeType: (_newPluginState$pendi6 = newPluginState.pendingPastedAgentMention) === null || _newPluginState$pendi6 === void 0 ? void 0 : _newPluginState$pendi6.parentNodeType
358
+ });
359
+ hasPublicPluginStateChanged = true;
360
+ break;
361
+ }
362
+ case _main.ACTIONS.CLEAR_PENDING_PASTED_AGENT_MENTION:
363
+ {
364
+ var _newPluginState$pendi7;
365
+ if (!isAgentMentionsExperimentEnabled || !(params !== null && params !== void 0 && params.id) || ((_newPluginState$pendi7 = newPluginState.pendingPastedAgentMention) === null || _newPluginState$pendi7 === void 0 ? void 0 : _newPluginState$pendi7.id) !== params.id || !(0, _platformFeatureFlags.fg)('platform_editor_agent_mentions_drop_one_fixes')) {
366
+ break;
367
+ }
368
+ newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
369
+ pendingPastedAgentMention: null
370
+ });
371
+ break;
372
+ }
373
+ }
374
+ if (isAgentMentionsExperimentEnabled && isQualifyingLocalUserDocChange(tr)) {
375
+ var mentionSchema = newState.schema.nodes.mention;
376
+ var newDocRanges = [];
377
+ var oldDocRanges = [];
378
+ var stepsTouchMentions = false;
379
+ tr.steps.forEach(function (step) {
380
+ var found = false;
381
+ var stepNewRanges = [];
382
+ var stepOldRanges = [];
383
+ step.getMap().forEach(function (oldFrom, oldTo, newFrom, newTo) {
384
+ stepOldRanges.push([oldFrom, oldTo]);
385
+ stepNewRanges.push([newFrom, newTo]);
386
+ if (!found) {
387
+ var clampedNewFrom = Math.min(newFrom, newState.doc.content.size);
388
+ var clampedNewTo = Math.min(newTo, newState.doc.content.size);
389
+ if (clampedNewFrom < clampedNewTo) {
390
+ newState.doc.nodesBetween(clampedNewFrom, clampedNewTo, function (node) {
391
+ if (node.type === mentionSchema && isAgentUserType(node.attrs.userType)) {
392
+ found = true;
393
+ }
394
+ return !found;
395
+ });
396
+ }
397
+ if (!found) {
398
+ var clampedOldFrom = Math.min(oldFrom, oldState.doc.content.size);
399
+ var clampedOldTo = Math.min(oldTo, oldState.doc.content.size);
400
+ if (clampedOldFrom < clampedOldTo) {
401
+ oldState.doc.nodesBetween(clampedOldFrom, clampedOldTo, function (node) {
402
+ if (node.type === mentionSchema && AGENT_USER_TYPES.has(node.attrs.userType)) {
403
+ found = true;
404
+ }
405
+ return !found;
406
+ });
407
+ }
408
+ }
409
+ }
410
+ });
411
+ if (found) {
412
+ stepsTouchMentions = true;
413
+ newDocRanges.push.apply(newDocRanges, stepNewRanges);
414
+ oldDocRanges.push.apply(oldDocRanges, stepOldRanges);
415
+ }
416
+ });
417
+ var shouldResolveAgentMentionState = stepsTouchMentions || Boolean(newPluginState.lastInsertedAgentMentionLocalId);
418
+ if (shouldResolveAgentMentionState) {
419
+ var _newPluginState$lastI, _newPluginState$lastA, _newPluginState$lastI2, _newPluginState$lastI3, _newPluginState$lastI4, _newPluginState$lastI5, _newPluginState$lastI6;
420
+ var agentMentionId = null;
421
+ var agentMentionLocalId = null;
422
+ var agentMentionContext = null;
423
+ var agentMentionName = null;
424
+ var agentMentionPrompt = null;
425
+ var agentMentionParentNodeType = null;
426
+ var existingAgentMentionLocalIdsInChangedRanges = new Set();
427
+ var pendingTypedAgentMentionDetails = null;
428
+ if (stepsTouchMentions) {
429
+ var _iterator = _createForOfIteratorHelper(newDocRanges),
430
+ _step;
431
+ try {
432
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
433
+ var _step$value = (0, _slicedToArray2.default)(_step.value, 2),
434
+ from = _step$value[0],
435
+ to = _step$value[1];
436
+ var clampedTo = Math.min(to, newState.doc.content.size);
437
+ if (from >= clampedTo) {
438
+ continue;
439
+ }
440
+ newState.doc.nodesBetween(from, clampedTo, function (node, pos) {
441
+ if (node.type !== mentionSchema || !isAgentUserType(node.attrs.userType)) {
442
+ return true;
443
+ }
444
+ if (pendingTypedAgentMentionDetails === null && action === _main.ACTIONS.SET_PENDING_TYPED_AGENT_MENTION && node.attrs.localId === (params === null || params === void 0 ? void 0 : params.localId)) {
445
+ pendingTypedAgentMentionDetails = getAgentMentionDetailsAtPos(newState, pos, function (attrs) {
446
+ return attrs.localId === params.localId;
447
+ }, params.name);
448
+ }
449
+ if (agentMentionLocalId === null && node.attrs.localId) {
450
+ var cachedName = (0, _platformFeatureFlags.fg)('platform_editor_agent_mentions_drop_one_fixes') ? resolveCachedAgentMentionName(newPluginState.mentionProvider, params, node.attrs.id) : params === null || params === void 0 ? void 0 : params.name;
451
+ var agentMentionDetails = getAgentMentionDetailsAtPos(newState, pos, function (attrs) {
452
+ return attrs.localId === node.attrs.localId;
453
+ }, cachedName);
454
+ if (agentMentionDetails) {
455
+ agentMentionId = agentMentionDetails.id;
456
+ agentMentionLocalId = agentMentionDetails.localId;
457
+ agentMentionContext = agentMentionDetails.context;
458
+ agentMentionName = agentMentionDetails.name;
459
+ agentMentionPrompt = agentMentionDetails.prompt;
460
+ agentMentionParentNodeType = agentMentionDetails.parentNodeType;
461
+ }
462
+ }
463
+ return true;
464
+ });
465
+ }
466
+ } catch (err) {
467
+ _iterator.e(err);
468
+ } finally {
469
+ _iterator.f();
470
+ }
471
+ var _iterator2 = _createForOfIteratorHelper(oldDocRanges),
472
+ _step2;
473
+ try {
474
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
475
+ var _step2$value = (0, _slicedToArray2.default)(_step2.value, 2),
476
+ _from = _step2$value[0],
477
+ _to = _step2$value[1];
478
+ var clampedOldTo = Math.min(_to, oldState.doc.content.size);
479
+ if (_from >= clampedOldTo) {
480
+ continue;
481
+ }
482
+ oldState.doc.nodesBetween(_from, clampedOldTo, function (node) {
483
+ if (node.type !== mentionSchema || !isAgentUserType(node.attrs.userType)) {
484
+ return true;
485
+ }
486
+ if (node.attrs.localId) {
487
+ existingAgentMentionLocalIdsInChangedRanges.add(node.attrs.localId);
488
+ }
489
+ return true;
490
+ });
491
+ }
492
+ } catch (err) {
493
+ _iterator2.e(err);
494
+ } finally {
495
+ _iterator2.f();
496
+ }
497
+ }
498
+ var resolvedFromFullDocFallback = false;
499
+ if (agentMentionId === null && newPluginState.lastInsertedAgentMentionLocalId) {
500
+ var survivorDetails = getSurvivingAgentMentionDetails(newState, newPluginState.lastInsertedAgentMentionLocalId, newPluginState.lastInsertedAgentMentionName);
501
+ if (survivorDetails) {
502
+ agentMentionId = survivorDetails.id;
503
+ agentMentionLocalId = survivorDetails.localId;
504
+ agentMentionContext = survivorDetails.context;
505
+ agentMentionName = survivorDetails.name;
506
+ agentMentionPrompt = survivorDetails.prompt;
507
+ agentMentionParentNodeType = survivorDetails.parentNodeType;
508
+ resolvedFromFullDocFallback = true;
509
+ }
510
+ }
511
+ var trackedAgentMentionLocalId = (_newPluginState$lastI = newPluginState.lastInsertedAgentMentionLocalId) !== null && _newPluginState$lastI !== void 0 ? _newPluginState$lastI : null;
512
+ var changedRangeMentionIsNew = agentMentionLocalId !== null && !existingAgentMentionLocalIdsInChangedRanges.has(agentMentionLocalId);
513
+ if (agentMentionLocalId !== null && !changedRangeMentionIsNew && agentMentionLocalId !== trackedAgentMentionLocalId) {
514
+ var _survivorDetails = trackedAgentMentionLocalId ? getSurvivingAgentMentionDetails(newState, trackedAgentMentionLocalId, newPluginState.lastInsertedAgentMentionName) : null;
515
+ if (_survivorDetails) {
516
+ agentMentionId = _survivorDetails.id;
517
+ agentMentionLocalId = _survivorDetails.localId;
518
+ agentMentionContext = _survivorDetails.context;
519
+ agentMentionName = _survivorDetails.name;
520
+ agentMentionParentNodeType = _survivorDetails.parentNodeType;
521
+ resolvedFromFullDocFallback = true;
522
+ } else {
523
+ agentMentionId = null;
524
+ agentMentionLocalId = null;
525
+ agentMentionContext = null;
526
+ agentMentionName = null;
527
+ agentMentionParentNodeType = null;
528
+ }
529
+ }
530
+ var isNewInsertion = agentMentionId !== null && !resolvedFromFullDocFallback && changedRangeMentionIsNew;
531
+ var isPendingTypedAgentMentionInsertion = isNewInsertion && action === _main.ACTIONS.SET_PENDING_TYPED_AGENT_MENTION && typeof (params === null || params === void 0 ? void 0 : params.localId) === 'string';
532
+ var newInsertionCount = isNewInsertion ? ((_newPluginState$lastA = newPluginState.lastAgentMentionInsertionCount) !== null && _newPluginState$lastA !== void 0 ? _newPluginState$lastA : 0) + 1 : undefined;
533
+ var pendingTypedAgentMentionDetailsForState = pendingTypedAgentMentionDetails;
534
+ if (isPendingTypedAgentMentionInsertion && pendingTypedAgentMentionDetailsForState) {
535
+ var pendingTypedAgentMentionLocalId = params === null || params === void 0 ? void 0 : params.localId;
536
+ newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
537
+ pendingTypedAgentMention: {
538
+ id: pendingTypedAgentMentionDetailsForState.id,
539
+ localId: pendingTypedAgentMentionLocalId,
540
+ name: pendingTypedAgentMentionDetailsForState.name,
541
+ nodeSize: pendingTypedAgentMentionDetailsForState.nodeSize,
542
+ parentNodeType: pendingTypedAgentMentionDetailsForState.parentNodeType,
543
+ pos: pendingTypedAgentMentionDetailsForState.pos,
544
+ resetCount: 1
545
+ }
546
+ });
547
+ } else if (isPendingTypedAgentMentionInsertion) {
548
+ newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
549
+ pendingTypedAgentMention: null,
550
+ lastInsertedAgentMentionId: agentMentionId,
551
+ lastInsertedAgentMentionLocalId: agentMentionLocalId,
552
+ lastInsertedAgentMentionContext: agentMentionContext,
553
+ lastInsertedAgentMentionName: agentMentionName,
554
+ lastInsertedAgentMentionPrompt: agentMentionPrompt,
555
+ lastInsertedAgentMentionParentNodeType: agentMentionParentNodeType
556
+ }, newInsertionCount !== undefined ? {
557
+ lastAgentMentionInsertionCount: newInsertionCount
558
+ } : {});
559
+ hasPublicPluginStateChanged = true;
560
+ } else if (agentMentionId !== ((_newPluginState$lastI2 = newPluginState.lastInsertedAgentMentionId) !== null && _newPluginState$lastI2 !== void 0 ? _newPluginState$lastI2 : null) || agentMentionLocalId !== ((_newPluginState$lastI3 = newPluginState.lastInsertedAgentMentionLocalId) !== null && _newPluginState$lastI3 !== void 0 ? _newPluginState$lastI3 : null) || agentMentionName !== ((_newPluginState$lastI4 = newPluginState.lastInsertedAgentMentionName) !== null && _newPluginState$lastI4 !== void 0 ? _newPluginState$lastI4 : null) || agentMentionPrompt !== ((_newPluginState$lastI5 = newPluginState.lastInsertedAgentMentionPrompt) !== null && _newPluginState$lastI5 !== void 0 ? _newPluginState$lastI5 : null) || agentMentionParentNodeType !== ((_newPluginState$lastI6 = newPluginState.lastInsertedAgentMentionParentNodeType) !== null && _newPluginState$lastI6 !== void 0 ? _newPluginState$lastI6 : null) || newInsertionCount !== undefined) {
561
+ var isTaskItemMentionForPaste = agentMentionParentNodeType === 'taskItem';
562
+ if (!isTaskItemMentionForPaste && isNewInsertion && getIsRovoPanelOpen !== null && getIsRovoPanelOpen !== void 0 && getIsRovoPanelOpen()) {
563
+ // Rovo is already open, so do not publish a nudge-triggering state change.
564
+ } else if (agentMentionName === null && agentMentionId !== null && (0, _resource.isResolvingMentionProvider)(newPluginState.mentionProvider) && (0, _platformFeatureFlags.fg)('platform_editor_agent_mentions_drop_one_fixes')) {
565
+ newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
566
+ pendingPastedAgentMention: {
567
+ id: agentMentionId,
568
+ localId: agentMentionLocalId,
569
+ context: agentMentionContext,
570
+ prompt: agentMentionPrompt,
571
+ parentNodeType: agentMentionParentNodeType
572
+ }
573
+ }, newInsertionCount !== undefined ? {
574
+ lastAgentMentionInsertionCount: newInsertionCount
575
+ } : {});
576
+ } else {
577
+ newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
578
+ lastInsertedAgentMentionId: agentMentionId,
579
+ lastInsertedAgentMentionLocalId: agentMentionLocalId,
580
+ lastInsertedAgentMentionContext: agentMentionContext,
581
+ lastInsertedAgentMentionName: agentMentionName,
582
+ lastInsertedAgentMentionPrompt: agentMentionPrompt,
583
+ lastInsertedAgentMentionParentNodeType: agentMentionParentNodeType
584
+ }, newInsertionCount !== undefined ? {
585
+ lastAgentMentionInsertionCount: newInsertionCount
586
+ } : {});
587
+ hasPublicPluginStateChanged = true;
588
+ }
589
+ }
590
+ }
591
+ }
592
+ if (isAgentMentionsExperimentEnabled && tr.docChanged && tr.getMeta('replaceDocument') && hasTrackedAgentMentionState(newPluginState)) {
593
+ newPluginState = clearTrackedAgentMentionState(newPluginState);
594
+ hasPublicPluginStateChanged = true;
595
+ }
596
+ if (isAgentMentionsExperimentEnabled && newPluginState.pendingTypedAgentMention && action !== _main.ACTIONS.SET_PENDING_TYPED_AGENT_MENTION && action !== _main.ACTIONS.COMMIT_PENDING_TYPED_AGENT_MENTION && tr.docChanged) {
597
+ newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
598
+ pendingTypedAgentMention: getPendingTypedAgentMentionAfterDocChange(newState, tr, newPluginState.pendingTypedAgentMention, {
599
+ resetTimer: isQualifyingLocalUserDocChange(tr)
600
+ })
601
+ });
602
+ }
603
+ var shouldCheckPendingTypedAgentMentionParent = isLocalSelectionChange(tr, hasPositionChanged);
604
+ if (isAgentMentionsExperimentEnabled && newPluginState.pendingTypedAgentMention && action !== _main.ACTIONS.SET_PENDING_TYPED_AGENT_MENTION && action !== _main.ACTIONS.COMMIT_PENDING_TYPED_AGENT_MENTION && shouldCheckPendingTypedAgentMentionParent) {
605
+ var _pendingTypedAgentMention = newPluginState.pendingTypedAgentMention;
606
+ var pendingMentionDetails = getAgentMentionDetailsAtPos(newState, _pendingTypedAgentMention.pos, function (attrs) {
607
+ return attrs.localId === _pendingTypedAgentMention.localId;
608
+ }, _pendingTypedAgentMention.name);
609
+ if (!pendingMentionDetails) {
610
+ newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
611
+ pendingTypedAgentMention: null
612
+ });
613
+ } else if (hasPendingMentionMovedToNewParent(oldState, tr, pluginState.pendingTypedAgentMention, pendingMentionDetails) || isSelectionOutsideDirectParent(newState, pendingMentionDetails)) {
614
+ if (pendingMentionDetails.parentNodeType !== 'taskItem' && getIsRovoPanelOpen !== null && getIsRovoPanelOpen !== void 0 && getIsRovoPanelOpen()) {
615
+ newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
616
+ pendingTypedAgentMention: null
617
+ });
618
+ hasPublicPluginStateChanged = true;
619
+ } else {
620
+ var _commitResult = commitResolvedPendingTypedAgentMention(newPluginState, pendingMentionDetails);
621
+ newPluginState = _commitResult.pluginState;
622
+ hasPublicPluginStateChanged = hasPublicPluginStateChanged || _commitResult.hasPublicPluginStateChanged;
623
+ }
624
+ }
625
+ }
626
+ return {
627
+ hasPublicPluginStateChanged: hasPublicPluginStateChanged,
628
+ pluginState: newPluginState
629
+ };
630
+ };
631
+ var createAgentMentionPluginView = exports.createAgentMentionPluginView = function createAgentMentionPluginView(_ref4) {
632
+ var editorView = _ref4.editorView,
633
+ getIsRovoPanelOpen = _ref4.getIsRovoPanelOpen,
634
+ stateKey = _ref4.stateKey;
635
+ var isAgentMentionsEnabled = (0, _experiments.editorExperiment)('platform_editor_agent_mentions', true);
636
+ var pendingTypedAgentMentionTimer;
637
+ var pendingTypedAgentMentionTimerKey = null;
638
+ var pendingTypedAgentMentionFocusDeferCount = 0;
639
+ var pendingResolveMentionIds = new Set();
640
+ var clearPendingTypedAgentMentionTimer = function clearPendingTypedAgentMentionTimer() {
641
+ var _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
642
+ _ref5$preserveFocusDe = _ref5.preserveFocusDeferCount,
643
+ preserveFocusDeferCount = _ref5$preserveFocusDe === void 0 ? false : _ref5$preserveFocusDe;
644
+ if (pendingTypedAgentMentionTimer) {
645
+ clearTimeout(pendingTypedAgentMentionTimer);
646
+ pendingTypedAgentMentionTimer = undefined;
647
+ }
648
+ pendingTypedAgentMentionTimerKey = null;
649
+ if (!preserveFocusDeferCount) {
650
+ pendingTypedAgentMentionFocusDeferCount = 0;
651
+ }
652
+ };
653
+ var shouldDeferPendingTypedAgentMention = function shouldDeferPendingTypedAgentMention() {
654
+ return typeof document !== 'undefined' && document.hasFocus() && !editorView.hasFocus();
655
+ };
656
+ var _schedulePendingTypedAgentMentionTimer = function schedulePendingTypedAgentMentionTimer(mentionPluginState) {
657
+ var _ref6 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
658
+ _ref6$preserveFocusDe = _ref6.preserveFocusDeferCount,
659
+ preserveFocusDeferCount = _ref6$preserveFocusDe === void 0 ? false : _ref6$preserveFocusDe;
660
+ if (!isAgentMentionsEnabled) {
661
+ clearPendingTypedAgentMentionTimer();
662
+ return;
663
+ }
664
+ var pendingTypedAgentMention = mentionPluginState === null || mentionPluginState === void 0 ? void 0 : mentionPluginState.pendingTypedAgentMention;
665
+ if (!pendingTypedAgentMention) {
666
+ clearPendingTypedAgentMentionTimer();
667
+ return;
668
+ }
669
+ var timerKey = "".concat(pendingTypedAgentMention.localId, ":").concat(pendingTypedAgentMention.resetCount);
670
+ if (timerKey === pendingTypedAgentMentionTimerKey) {
671
+ return;
672
+ }
673
+ clearPendingTypedAgentMentionTimer({
674
+ preserveFocusDeferCount: preserveFocusDeferCount
675
+ });
676
+ pendingTypedAgentMentionTimerKey = timerKey;
677
+ pendingTypedAgentMentionTimer = setTimeout(function () {
678
+ var _stateKey$getState;
679
+ var isTaskItemMention = pendingTypedAgentMention.parentNodeType === 'taskItem';
680
+ if (!isTaskItemMention && getIsRovoPanelOpen !== null && getIsRovoPanelOpen !== void 0 && getIsRovoPanelOpen()) {
681
+ // Agent actions continue to use mentionPluginKey as the shared transaction meta channel.
682
+ editorView.dispatch(editorView.state.tr.setMeta(_key.mentionPluginKey, {
683
+ action: _main.ACTIONS.DISCARD_PENDING_TYPED_AGENT_MENTION,
684
+ params: {
685
+ localId: pendingTypedAgentMention.localId,
686
+ resetCount: pendingTypedAgentMention.resetCount
687
+ }
688
+ }));
689
+ return;
690
+ }
691
+ var latestPendingTypedAgentMention = (_stateKey$getState = stateKey.getState(editorView.state)) === null || _stateKey$getState === void 0 ? void 0 : _stateKey$getState.pendingTypedAgentMention;
692
+ if (!latestPendingTypedAgentMention || latestPendingTypedAgentMention.localId !== pendingTypedAgentMention.localId || latestPendingTypedAgentMention.resetCount !== pendingTypedAgentMention.resetCount) {
693
+ return;
694
+ }
695
+ if (shouldDeferPendingTypedAgentMention() && pendingTypedAgentMentionFocusDeferCount < MAX_PENDING_TYPED_AGENT_MENTION_FOCUS_DEFERS) {
696
+ pendingTypedAgentMentionFocusDeferCount++;
697
+ pendingTypedAgentMentionTimerKey = null;
698
+ _schedulePendingTypedAgentMentionTimer(stateKey.getState(editorView.state), {
699
+ preserveFocusDeferCount: true
700
+ });
701
+ return;
702
+ }
703
+ pendingTypedAgentMentionFocusDeferCount = 0;
704
+ editorView.dispatch(editorView.state.tr.setMeta(_key.mentionPluginKey, {
705
+ action: _main.ACTIONS.COMMIT_PENDING_TYPED_AGENT_MENTION,
706
+ params: {
707
+ localId: pendingTypedAgentMention.localId,
708
+ resetCount: pendingTypedAgentMention.resetCount
709
+ }
710
+ }));
711
+ }, AGENT_MENTION_INACTIVITY_MS);
712
+ };
713
+ return {
714
+ update: function update(view, prevState) {
715
+ var _mentionPluginState$p;
716
+ var mentionPluginState = stateKey.getState(view.state);
717
+ if (mentionPluginState === stateKey.getState(prevState)) {
718
+ return;
719
+ }
720
+ _schedulePendingTypedAgentMentionTimer(mentionPluginState);
721
+ if ((0, _experiments.editorExperiment)('platform_editor_agent_mentions', true) && (mentionPluginState === null || mentionPluginState === void 0 || (_mentionPluginState$p = mentionPluginState.pendingPastedAgentMention) === null || _mentionPluginState$p === void 0 ? void 0 : _mentionPluginState$p.id) != null && mentionPluginState !== null && mentionPluginState !== void 0 && mentionPluginState.mentionProvider && (0, _resource.isResolvingMentionProvider)(mentionPluginState.mentionProvider) && (0, _platformFeatureFlags.fg)('platform_editor_agent_mentions_drop_one_fixes')) {
722
+ resolveAndDispatchPastedAgentMentionName(mentionPluginState.pendingPastedAgentMention.id, mentionPluginState.mentionProvider, pendingResolveMentionIds, view);
723
+ }
724
+ },
725
+ destroy: function destroy() {
726
+ clearPendingTypedAgentMentionTimer();
727
+ }
728
+ };
729
+ };
730
+ var agentMentionPluginKey = exports.agentMentionPluginKey = new _state.PluginKey('agentMention');
731
+ var createAgentMentionPlugin = exports.createAgentMentionPlugin = function createAgentMentionPlugin(_ref7) {
732
+ var options = _ref7.options,
733
+ pmPluginFactoryParams = _ref7.pmPluginFactoryParams;
734
+ return new _safePlugin.SafePlugin({
735
+ key: agentMentionPluginKey,
736
+ state: {
737
+ init: function init() {
738
+ return {};
739
+ },
740
+ apply: function apply(tr, pluginState, oldState, newState) {
741
+ var result = applyAgentMentionState({
742
+ tr: tr,
743
+ pluginState: pluginState,
744
+ oldState: oldState,
745
+ newState: newState,
746
+ getIsRovoPanelOpen: options === null || options === void 0 ? void 0 : options.getIsRovoPanelOpen
747
+ });
748
+ var mentionPluginState = _key.mentionPluginKey.getState(newState);
749
+ if (result.hasPublicPluginStateChanged) {
750
+ pmPluginFactoryParams.dispatch(_key.mentionPluginKey, _objectSpread(_objectSpread({}, mentionPluginState), result.pluginState));
751
+ }
752
+ return result.pluginState;
753
+ }
754
+ },
755
+ view: function view(editorView) {
756
+ return createAgentMentionPluginView({
757
+ editorView: editorView,
758
+ getIsRovoPanelOpen: options === null || options === void 0 ? void 0 : options.getIsRovoPanelOpen,
759
+ stateKey: agentMentionPluginKey
760
+ });
761
+ }
762
+ });
763
+ };