@atlaskit/editor-plugin-mentions 14.5.9 → 14.5.10

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/editor-plugin-mentions
2
2
 
3
+ ## 14.5.10
4
+
5
+ ### Patch Changes
6
+
7
+ - [`1448830a87645`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1448830a87645) -
8
+ Preserve ADF-backed editor agent mention prompt context through Rovo chat drafts and sends.
9
+ - Updated dependencies
10
+
3
11
  ## 14.5.9
4
12
 
5
13
  ### Patch Changes
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getAgentMentionParentContext = void 0;
7
+ var PASS_THROUGH_PROMPT_INLINE_NODE_TYPES = new Set(['hardBreak', 'inlineCard', 'mention', 'text']);
8
+ var isAgentMention = function isAgentMention(node) {
9
+ var _node$attrs;
10
+ return node.type === 'mention' && ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.userType) === 'APP';
11
+ };
12
+ var isAllowedAgentMention = function isAllowedAgentMention(node, agentMentionLocalId) {
13
+ var _node$attrs2;
14
+ return !isAgentMention(node) || ((_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.localId) === agentMentionLocalId;
15
+ };
16
+ var getStatusText = function getStatusText(node) {
17
+ var _node$attrs3;
18
+ var text = (_node$attrs3 = node.attrs) === null || _node$attrs3 === void 0 ? void 0 : _node$attrs3.text;
19
+ return typeof text === 'string' && text ? text : null;
20
+ };
21
+ var getDateText = function getDateText(node) {
22
+ var _node$attrs4;
23
+ var timestamp = (_node$attrs4 = node.attrs) === null || _node$attrs4 === void 0 ? void 0 : _node$attrs4.timestamp;
24
+ if (typeof timestamp !== 'string' || !timestamp) {
25
+ return null;
26
+ }
27
+ var date = new Date(Number(timestamp));
28
+ if (Number.isNaN(date.getTime())) {
29
+ return null;
30
+ }
31
+ return date.toISOString().slice(0, 10);
32
+ };
33
+ var toPromptInlineNode = function toPromptInlineNode(node, agentMentionLocalId) {
34
+ if (!isAllowedAgentMention(node, agentMentionLocalId)) {
35
+ return null;
36
+ }
37
+ if (PASS_THROUGH_PROMPT_INLINE_NODE_TYPES.has(node.type)) {
38
+ return node;
39
+ }
40
+ if (node.type === 'status') {
41
+ var text = getStatusText(node);
42
+ return text ? {
43
+ type: 'text',
44
+ text: text
45
+ } : null;
46
+ }
47
+ if (node.type === 'date') {
48
+ var _text = getDateText(node);
49
+ return _text ? {
50
+ type: 'text',
51
+ text: _text
52
+ } : null;
53
+ }
54
+ return null;
55
+ };
56
+
57
+ /**
58
+ * Returns the direct parent content of an inserted agent mention as prompt ADF.
59
+ *
60
+ * The chat input supports only a subset of editor inline ADF, so this keeps prompt content
61
+ * intentionally narrow:
62
+ * - `text`, `inlineCard`, and `hardBreak` pass through unchanged.
63
+ * - people mentions pass through unchanged.
64
+ * - only the invoked agent mention is kept, identified by `localId`; other agent mentions are dropped.
65
+ * - `status` becomes its label text.
66
+ * - `date` becomes ISO date text.
67
+ * - everything else is dropped.
68
+ *
69
+ * This only reads direct parent content. It does not recursively pull content out of nested or
70
+ * unsupported nodes.
71
+ */
72
+ var getAgentMentionParentContext = exports.getAgentMentionParentContext = function getAgentMentionParentContext(parentNode, agentMentionLocalId) {
73
+ var _parentAdf$content;
74
+ var parentAdf = parentNode.toJSON();
75
+ var supportedInlineContent = ((_parentAdf$content = parentAdf.content) !== null && _parentAdf$content !== void 0 ? _parentAdf$content : []).flatMap(function (node) {
76
+ var promptNode = toPromptInlineNode(node, agentMentionLocalId);
77
+ return promptNode ? [promptNode] : [];
78
+ });
79
+ return {
80
+ type: 'doc',
81
+ version: 1,
82
+ content: [{
83
+ type: 'paragraph',
84
+ content: supportedInlineContent
85
+ }]
86
+ };
87
+ };
@@ -17,6 +17,7 @@ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
17
17
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
18
18
  var _mentionNodeView = require("../nodeviews/mentionNodeView");
19
19
  var _types2 = require("../types");
20
+ var _agentMentionContext = require("./agent-mention-context");
20
21
  var _key = require("./key");
21
22
  var _utils = require("./utils");
22
23
  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; } } }; }
@@ -51,7 +52,7 @@ var AI_STREAMING_TRANSFORMATION_META_KEY = 'isAIStreamingTransformation';
51
52
  var AGENT_MENTION_INACTIVITY_MS = 3000;
52
53
  var MAX_PENDING_TYPED_AGENT_MENTION_FOCUS_DEFERS = 20;
53
54
  var PACKAGE_NAME = "@atlaskit/editor-plugin-mentions";
54
- var PACKAGE_VERSION = "14.5.8";
55
+ var PACKAGE_VERSION = "14.5.9";
55
56
  var setProvider = function setProvider(provider) {
56
57
  return function (state, dispatch) {
57
58
  if (dispatch) {
@@ -103,11 +104,14 @@ var getAgentMentionDetailsAtPos = function getAgentMentionDetailsAtPos(state, po
103
104
  }
104
105
  var $mentionPos = state.doc.resolve(Math.min(pos + node.nodeSize, state.doc.content.size));
105
106
  var parentNode = $mentionPos.node($mentionPos.depth);
107
+ var id = node.attrs.id;
108
+ var name = getAgentMentionName(node.attrs.text, fallbackName);
106
109
  return {
107
- id: node.attrs.id,
110
+ id: id,
108
111
  localId: node.attrs.localId,
109
- context: parentNode.textContent.trim() || null,
110
- name: getAgentMentionName(node.attrs.text, fallbackName),
112
+ context: (0, _agentMentionContext.getAgentMentionParentContext)(parentNode, node.attrs.localId),
113
+ name: name,
114
+ prompt: parentNode.textContent.trim() || null,
111
115
  nodeSize: node.nodeSize,
112
116
  parentEnd: $mentionPos.end($mentionPos.depth),
113
117
  parentNodeType: (_parentNode$type$name = parentNode.type.name) !== null && _parentNode$type$name !== void 0 ? _parentNode$type$name : null,
@@ -196,6 +200,7 @@ var commitResolvedPendingTypedAgentMention = function commitResolvedPendingTyped
196
200
  lastInsertedAgentMentionLocalId: pendingMentionDetails.localId,
197
201
  lastInsertedAgentMentionContext: pendingMentionDetails.context,
198
202
  lastInsertedAgentMentionName: pendingMentionDetails.name,
203
+ lastInsertedAgentMentionPrompt: pendingMentionDetails.prompt,
199
204
  lastInsertedAgentMentionParentNodeType: pendingMentionDetails.parentNodeType,
200
205
  lastAgentMentionInsertionCount: ((_pluginState$lastAgen = pluginState.lastAgentMentionInsertionCount) !== null && _pluginState$lastAgen !== void 0 ? _pluginState$lastAgen : 0) + 1
201
206
  })
@@ -222,7 +227,7 @@ var commitPendingTypedAgentMention = function commitPendingTypedAgentMention(sta
222
227
  return commitResolvedPendingTypedAgentMention(pluginState, pendingMentionDetails);
223
228
  };
224
229
  var hasTrackedAgentMentionState = function hasTrackedAgentMentionState(pluginState) {
225
- return Boolean(pluginState.pendingTypedAgentMention) || pluginState.lastInsertedAgentMentionId != null || pluginState.lastInsertedAgentMentionLocalId != null || pluginState.lastInsertedAgentMentionContext != null || pluginState.lastInsertedAgentMentionName != null || pluginState.lastInsertedAgentMentionParentNodeType != null;
230
+ return Boolean(pluginState.pendingTypedAgentMention) || pluginState.lastInsertedAgentMentionId != null || pluginState.lastInsertedAgentMentionLocalId != null || pluginState.lastInsertedAgentMentionContext != null || pluginState.lastInsertedAgentMentionName != null || pluginState.lastInsertedAgentMentionPrompt != null || pluginState.lastInsertedAgentMentionParentNodeType != null;
226
231
  };
227
232
 
228
233
  /**
@@ -237,6 +242,7 @@ var clearTrackedAgentMentionState = function clearTrackedAgentMentionState(plugi
237
242
  lastInsertedAgentMentionLocalId: null,
238
243
  lastInsertedAgentMentionContext: null,
239
244
  lastInsertedAgentMentionName: null,
245
+ lastInsertedAgentMentionPrompt: null,
240
246
  lastInsertedAgentMentionParentNodeType: null
241
247
  });
242
248
  };
@@ -426,6 +432,7 @@ function createMentionPlugin(_ref2) {
426
432
  var agentMentionLocalId = null;
427
433
  var agentMentionContext = null;
428
434
  var agentMentionName = null;
435
+ var agentMentionPrompt = null;
429
436
  var agentMentionParentNodeType = null;
430
437
  var existingAgentMentionLocalIdsInChangedRanges = new Set();
431
438
  var pendingTypedAgentMentionDetails = null;
@@ -457,6 +464,7 @@ function createMentionPlugin(_ref2) {
457
464
  agentMentionLocalId = agentMentionDetails.localId;
458
465
  agentMentionContext = agentMentionDetails.context;
459
466
  agentMentionName = agentMentionDetails.name;
467
+ agentMentionPrompt = agentMentionDetails.prompt;
460
468
  agentMentionParentNodeType = agentMentionDetails.parentNodeType;
461
469
  }
462
470
  }
@@ -505,6 +513,7 @@ function createMentionPlugin(_ref2) {
505
513
  agentMentionLocalId = survivorDetails.localId;
506
514
  agentMentionContext = survivorDetails.context;
507
515
  agentMentionName = survivorDetails.name;
516
+ agentMentionPrompt = survivorDetails.prompt;
508
517
  agentMentionParentNodeType = survivorDetails.parentNodeType;
509
518
  resolvedFromFullDocFallback = true;
510
519
  }
@@ -553,17 +562,19 @@ function createMentionPlugin(_ref2) {
553
562
  lastInsertedAgentMentionLocalId: agentMentionLocalId,
554
563
  lastInsertedAgentMentionContext: agentMentionContext,
555
564
  lastInsertedAgentMentionName: agentMentionName,
565
+ lastInsertedAgentMentionPrompt: agentMentionPrompt,
556
566
  lastInsertedAgentMentionParentNodeType: agentMentionParentNodeType
557
567
  }, newInsertionCount !== undefined ? {
558
568
  lastAgentMentionInsertionCount: newInsertionCount
559
569
  } : {});
560
570
  hasPublicPluginStateChanged = true;
561
- } 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) || agentMentionContext !== ((_newPluginState$lastI4 = newPluginState.lastInsertedAgentMentionContext) !== null && _newPluginState$lastI4 !== void 0 ? _newPluginState$lastI4 : null) || agentMentionName !== ((_newPluginState$lastI5 = newPluginState.lastInsertedAgentMentionName) !== null && _newPluginState$lastI5 !== void 0 ? _newPluginState$lastI5 : null) || agentMentionParentNodeType !== ((_newPluginState$lastI6 = newPluginState.lastInsertedAgentMentionParentNodeType) !== null && _newPluginState$lastI6 !== void 0 ? _newPluginState$lastI6 : null) || newInsertionCount !== undefined) {
571
+ } 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) {
562
572
  newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
563
573
  lastInsertedAgentMentionId: agentMentionId,
564
574
  lastInsertedAgentMentionLocalId: agentMentionLocalId,
565
575
  lastInsertedAgentMentionContext: agentMentionContext,
566
576
  lastInsertedAgentMentionName: agentMentionName,
577
+ lastInsertedAgentMentionPrompt: agentMentionPrompt,
567
578
  lastInsertedAgentMentionParentNodeType: agentMentionParentNodeType
568
579
  }, newInsertionCount !== undefined ? {
569
580
  lastAgentMentionInsertionCount: newInsertionCount
@@ -0,0 +1,81 @@
1
+ const PASS_THROUGH_PROMPT_INLINE_NODE_TYPES = new Set(['hardBreak', 'inlineCard', 'mention', 'text']);
2
+ const isAgentMention = node => {
3
+ var _node$attrs;
4
+ return node.type === 'mention' && ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.userType) === 'APP';
5
+ };
6
+ const isAllowedAgentMention = (node, agentMentionLocalId) => {
7
+ var _node$attrs2;
8
+ return !isAgentMention(node) || ((_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.localId) === agentMentionLocalId;
9
+ };
10
+ const getStatusText = node => {
11
+ var _node$attrs3;
12
+ const text = (_node$attrs3 = node.attrs) === null || _node$attrs3 === void 0 ? void 0 : _node$attrs3.text;
13
+ return typeof text === 'string' && text ? text : null;
14
+ };
15
+ const getDateText = node => {
16
+ var _node$attrs4;
17
+ const timestamp = (_node$attrs4 = node.attrs) === null || _node$attrs4 === void 0 ? void 0 : _node$attrs4.timestamp;
18
+ if (typeof timestamp !== 'string' || !timestamp) {
19
+ return null;
20
+ }
21
+ const date = new Date(Number(timestamp));
22
+ if (Number.isNaN(date.getTime())) {
23
+ return null;
24
+ }
25
+ return date.toISOString().slice(0, 10);
26
+ };
27
+ const toPromptInlineNode = (node, agentMentionLocalId) => {
28
+ if (!isAllowedAgentMention(node, agentMentionLocalId)) {
29
+ return null;
30
+ }
31
+ if (PASS_THROUGH_PROMPT_INLINE_NODE_TYPES.has(node.type)) {
32
+ return node;
33
+ }
34
+ if (node.type === 'status') {
35
+ const text = getStatusText(node);
36
+ return text ? {
37
+ type: 'text',
38
+ text
39
+ } : null;
40
+ }
41
+ if (node.type === 'date') {
42
+ const text = getDateText(node);
43
+ return text ? {
44
+ type: 'text',
45
+ text
46
+ } : null;
47
+ }
48
+ return null;
49
+ };
50
+
51
+ /**
52
+ * Returns the direct parent content of an inserted agent mention as prompt ADF.
53
+ *
54
+ * The chat input supports only a subset of editor inline ADF, so this keeps prompt content
55
+ * intentionally narrow:
56
+ * - `text`, `inlineCard`, and `hardBreak` pass through unchanged.
57
+ * - people mentions pass through unchanged.
58
+ * - only the invoked agent mention is kept, identified by `localId`; other agent mentions are dropped.
59
+ * - `status` becomes its label text.
60
+ * - `date` becomes ISO date text.
61
+ * - everything else is dropped.
62
+ *
63
+ * This only reads direct parent content. It does not recursively pull content out of nested or
64
+ * unsupported nodes.
65
+ */
66
+ export const getAgentMentionParentContext = (parentNode, agentMentionLocalId) => {
67
+ var _parentAdf$content;
68
+ const parentAdf = parentNode.toJSON();
69
+ const supportedInlineContent = ((_parentAdf$content = parentAdf.content) !== null && _parentAdf$content !== void 0 ? _parentAdf$content : []).flatMap(node => {
70
+ const promptNode = toPromptInlineNode(node, agentMentionLocalId);
71
+ return promptNode ? [promptNode] : [];
72
+ });
73
+ return {
74
+ type: 'doc',
75
+ version: 1,
76
+ content: [{
77
+ type: 'paragraph',
78
+ content: supportedInlineContent
79
+ }]
80
+ };
81
+ };
@@ -7,6 +7,7 @@ import { fg } from '@atlaskit/platform-feature-flags';
7
7
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
8
8
  import { MentionNodeView } from '../nodeviews/mentionNodeView';
9
9
  import { MENTION_PROVIDER_REJECTED, MENTION_PROVIDER_UNDEFINED } from '../types';
10
+ import { getAgentMentionParentContext } from './agent-mention-context';
10
11
  import { mentionPluginKey } from './key';
11
12
  import { canMentionBeCreatedInRange } from './utils';
12
13
  export const ACTIONS = {
@@ -36,7 +37,7 @@ const AI_STREAMING_TRANSFORMATION_META_KEY = 'isAIStreamingTransformation';
36
37
  const AGENT_MENTION_INACTIVITY_MS = 3000;
37
38
  const MAX_PENDING_TYPED_AGENT_MENTION_FOCUS_DEFERS = 20;
38
39
  const PACKAGE_NAME = "@atlaskit/editor-plugin-mentions";
39
- const PACKAGE_VERSION = "14.5.8";
40
+ const PACKAGE_VERSION = "14.5.9";
40
41
  const setProvider = provider => (state, dispatch) => {
41
42
  if (dispatch) {
42
43
  dispatch(state.tr.setMeta(mentionPluginKey, {
@@ -86,11 +87,14 @@ const getAgentMentionDetailsAtPos = (state, pos, matchesMention, fallbackName) =
86
87
  }
87
88
  const $mentionPos = state.doc.resolve(Math.min(pos + node.nodeSize, state.doc.content.size));
88
89
  const parentNode = $mentionPos.node($mentionPos.depth);
90
+ const id = node.attrs.id;
91
+ const name = getAgentMentionName(node.attrs.text, fallbackName);
89
92
  return {
90
- id: node.attrs.id,
93
+ id,
91
94
  localId: node.attrs.localId,
92
- context: parentNode.textContent.trim() || null,
93
- name: getAgentMentionName(node.attrs.text, fallbackName),
95
+ context: getAgentMentionParentContext(parentNode, node.attrs.localId),
96
+ name,
97
+ prompt: parentNode.textContent.trim() || null,
94
98
  nodeSize: node.nodeSize,
95
99
  parentEnd: $mentionPos.end($mentionPos.depth),
96
100
  parentNodeType: (_parentNode$type$name = parentNode.type.name) !== null && _parentNode$type$name !== void 0 ? _parentNode$type$name : null,
@@ -175,6 +179,7 @@ const commitResolvedPendingTypedAgentMention = (pluginState, pendingMentionDetai
175
179
  lastInsertedAgentMentionLocalId: pendingMentionDetails.localId,
176
180
  lastInsertedAgentMentionContext: pendingMentionDetails.context,
177
181
  lastInsertedAgentMentionName: pendingMentionDetails.name,
182
+ lastInsertedAgentMentionPrompt: pendingMentionDetails.prompt,
178
183
  lastInsertedAgentMentionParentNodeType: pendingMentionDetails.parentNodeType,
179
184
  lastAgentMentionInsertionCount: ((_pluginState$lastAgen = pluginState.lastAgentMentionInsertionCount) !== null && _pluginState$lastAgen !== void 0 ? _pluginState$lastAgen : 0) + 1
180
185
  }
@@ -199,7 +204,7 @@ const commitPendingTypedAgentMention = (state, pluginState, pendingTypedAgentMen
199
204
  }
200
205
  return commitResolvedPendingTypedAgentMention(pluginState, pendingMentionDetails);
201
206
  };
202
- const hasTrackedAgentMentionState = pluginState => Boolean(pluginState.pendingTypedAgentMention) || pluginState.lastInsertedAgentMentionId != null || pluginState.lastInsertedAgentMentionLocalId != null || pluginState.lastInsertedAgentMentionContext != null || pluginState.lastInsertedAgentMentionName != null || pluginState.lastInsertedAgentMentionParentNodeType != null;
207
+ const hasTrackedAgentMentionState = pluginState => Boolean(pluginState.pendingTypedAgentMention) || pluginState.lastInsertedAgentMentionId != null || pluginState.lastInsertedAgentMentionLocalId != null || pluginState.lastInsertedAgentMentionContext != null || pluginState.lastInsertedAgentMentionName != null || pluginState.lastInsertedAgentMentionPrompt != null || pluginState.lastInsertedAgentMentionParentNodeType != null;
203
208
 
204
209
  /**
205
210
  * Clears agent mention state that points at a specific document snapshot.
@@ -214,6 +219,7 @@ const clearTrackedAgentMentionState = pluginState => {
214
219
  lastInsertedAgentMentionLocalId: null,
215
220
  lastInsertedAgentMentionContext: null,
216
221
  lastInsertedAgentMentionName: null,
222
+ lastInsertedAgentMentionPrompt: null,
217
223
  lastInsertedAgentMentionParentNodeType: null
218
224
  };
219
225
  };
@@ -406,6 +412,7 @@ export function createMentionPlugin({
406
412
  let agentMentionLocalId = null;
407
413
  let agentMentionContext = null;
408
414
  let agentMentionName = null;
415
+ let agentMentionPrompt = null;
409
416
  let agentMentionParentNodeType = null;
410
417
  const existingAgentMentionLocalIdsInChangedRanges = new Set();
411
418
  let pendingTypedAgentMentionDetails = null;
@@ -427,6 +434,7 @@ export function createMentionPlugin({
427
434
  agentMentionLocalId = agentMentionDetails.localId;
428
435
  agentMentionContext = agentMentionDetails.context;
429
436
  agentMentionName = agentMentionDetails.name;
437
+ agentMentionPrompt = agentMentionDetails.prompt;
430
438
  agentMentionParentNodeType = agentMentionDetails.parentNodeType;
431
439
  }
432
440
  }
@@ -459,6 +467,7 @@ export function createMentionPlugin({
459
467
  agentMentionLocalId = survivorDetails.localId;
460
468
  agentMentionContext = survivorDetails.context;
461
469
  agentMentionName = survivorDetails.name;
470
+ agentMentionPrompt = survivorDetails.prompt;
462
471
  agentMentionParentNodeType = survivorDetails.parentNodeType;
463
472
  resolvedFromFullDocFallback = true;
464
473
  }
@@ -509,19 +518,21 @@ export function createMentionPlugin({
509
518
  lastInsertedAgentMentionLocalId: agentMentionLocalId,
510
519
  lastInsertedAgentMentionContext: agentMentionContext,
511
520
  lastInsertedAgentMentionName: agentMentionName,
521
+ lastInsertedAgentMentionPrompt: agentMentionPrompt,
512
522
  lastInsertedAgentMentionParentNodeType: agentMentionParentNodeType,
513
523
  ...(newInsertionCount !== undefined ? {
514
524
  lastAgentMentionInsertionCount: newInsertionCount
515
525
  } : {})
516
526
  };
517
527
  hasPublicPluginStateChanged = true;
518
- } 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) || agentMentionContext !== ((_newPluginState$lastI4 = newPluginState.lastInsertedAgentMentionContext) !== null && _newPluginState$lastI4 !== void 0 ? _newPluginState$lastI4 : null) || agentMentionName !== ((_newPluginState$lastI5 = newPluginState.lastInsertedAgentMentionName) !== null && _newPluginState$lastI5 !== void 0 ? _newPluginState$lastI5 : null) || agentMentionParentNodeType !== ((_newPluginState$lastI6 = newPluginState.lastInsertedAgentMentionParentNodeType) !== null && _newPluginState$lastI6 !== void 0 ? _newPluginState$lastI6 : null) || newInsertionCount !== undefined) {
528
+ } 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) {
519
529
  newPluginState = {
520
530
  ...newPluginState,
521
531
  lastInsertedAgentMentionId: agentMentionId,
522
532
  lastInsertedAgentMentionLocalId: agentMentionLocalId,
523
533
  lastInsertedAgentMentionContext: agentMentionContext,
524
534
  lastInsertedAgentMentionName: agentMentionName,
535
+ lastInsertedAgentMentionPrompt: agentMentionPrompt,
525
536
  lastInsertedAgentMentionParentNodeType: agentMentionParentNodeType,
526
537
  ...(newInsertionCount !== undefined ? {
527
538
  lastAgentMentionInsertionCount: newInsertionCount
@@ -0,0 +1,81 @@
1
+ var PASS_THROUGH_PROMPT_INLINE_NODE_TYPES = new Set(['hardBreak', 'inlineCard', 'mention', 'text']);
2
+ var isAgentMention = function isAgentMention(node) {
3
+ var _node$attrs;
4
+ return node.type === 'mention' && ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.userType) === 'APP';
5
+ };
6
+ var isAllowedAgentMention = function isAllowedAgentMention(node, agentMentionLocalId) {
7
+ var _node$attrs2;
8
+ return !isAgentMention(node) || ((_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.localId) === agentMentionLocalId;
9
+ };
10
+ var getStatusText = function getStatusText(node) {
11
+ var _node$attrs3;
12
+ var text = (_node$attrs3 = node.attrs) === null || _node$attrs3 === void 0 ? void 0 : _node$attrs3.text;
13
+ return typeof text === 'string' && text ? text : null;
14
+ };
15
+ var getDateText = function getDateText(node) {
16
+ var _node$attrs4;
17
+ var timestamp = (_node$attrs4 = node.attrs) === null || _node$attrs4 === void 0 ? void 0 : _node$attrs4.timestamp;
18
+ if (typeof timestamp !== 'string' || !timestamp) {
19
+ return null;
20
+ }
21
+ var date = new Date(Number(timestamp));
22
+ if (Number.isNaN(date.getTime())) {
23
+ return null;
24
+ }
25
+ return date.toISOString().slice(0, 10);
26
+ };
27
+ var toPromptInlineNode = function toPromptInlineNode(node, agentMentionLocalId) {
28
+ if (!isAllowedAgentMention(node, agentMentionLocalId)) {
29
+ return null;
30
+ }
31
+ if (PASS_THROUGH_PROMPT_INLINE_NODE_TYPES.has(node.type)) {
32
+ return node;
33
+ }
34
+ if (node.type === 'status') {
35
+ var text = getStatusText(node);
36
+ return text ? {
37
+ type: 'text',
38
+ text: text
39
+ } : null;
40
+ }
41
+ if (node.type === 'date') {
42
+ var _text = getDateText(node);
43
+ return _text ? {
44
+ type: 'text',
45
+ text: _text
46
+ } : null;
47
+ }
48
+ return null;
49
+ };
50
+
51
+ /**
52
+ * Returns the direct parent content of an inserted agent mention as prompt ADF.
53
+ *
54
+ * The chat input supports only a subset of editor inline ADF, so this keeps prompt content
55
+ * intentionally narrow:
56
+ * - `text`, `inlineCard`, and `hardBreak` pass through unchanged.
57
+ * - people mentions pass through unchanged.
58
+ * - only the invoked agent mention is kept, identified by `localId`; other agent mentions are dropped.
59
+ * - `status` becomes its label text.
60
+ * - `date` becomes ISO date text.
61
+ * - everything else is dropped.
62
+ *
63
+ * This only reads direct parent content. It does not recursively pull content out of nested or
64
+ * unsupported nodes.
65
+ */
66
+ export var getAgentMentionParentContext = function getAgentMentionParentContext(parentNode, agentMentionLocalId) {
67
+ var _parentAdf$content;
68
+ var parentAdf = parentNode.toJSON();
69
+ var supportedInlineContent = ((_parentAdf$content = parentAdf.content) !== null && _parentAdf$content !== void 0 ? _parentAdf$content : []).flatMap(function (node) {
70
+ var promptNode = toPromptInlineNode(node, agentMentionLocalId);
71
+ return promptNode ? [promptNode] : [];
72
+ });
73
+ return {
74
+ type: 'doc',
75
+ version: 1,
76
+ content: [{
77
+ type: 'paragraph',
78
+ content: supportedInlineContent
79
+ }]
80
+ };
81
+ };
@@ -14,6 +14,7 @@ import { fg } from '@atlaskit/platform-feature-flags';
14
14
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
15
15
  import { MentionNodeView } from '../nodeviews/mentionNodeView';
16
16
  import { MENTION_PROVIDER_REJECTED, MENTION_PROVIDER_UNDEFINED } from '../types';
17
+ import { getAgentMentionParentContext } from './agent-mention-context';
17
18
  import { mentionPluginKey } from './key';
18
19
  import { canMentionBeCreatedInRange } from './utils';
19
20
  export var ACTIONS = {
@@ -43,7 +44,7 @@ var AI_STREAMING_TRANSFORMATION_META_KEY = 'isAIStreamingTransformation';
43
44
  var AGENT_MENTION_INACTIVITY_MS = 3000;
44
45
  var MAX_PENDING_TYPED_AGENT_MENTION_FOCUS_DEFERS = 20;
45
46
  var PACKAGE_NAME = "@atlaskit/editor-plugin-mentions";
46
- var PACKAGE_VERSION = "14.5.8";
47
+ var PACKAGE_VERSION = "14.5.9";
47
48
  var setProvider = function setProvider(provider) {
48
49
  return function (state, dispatch) {
49
50
  if (dispatch) {
@@ -95,11 +96,14 @@ var getAgentMentionDetailsAtPos = function getAgentMentionDetailsAtPos(state, po
95
96
  }
96
97
  var $mentionPos = state.doc.resolve(Math.min(pos + node.nodeSize, state.doc.content.size));
97
98
  var parentNode = $mentionPos.node($mentionPos.depth);
99
+ var id = node.attrs.id;
100
+ var name = getAgentMentionName(node.attrs.text, fallbackName);
98
101
  return {
99
- id: node.attrs.id,
102
+ id: id,
100
103
  localId: node.attrs.localId,
101
- context: parentNode.textContent.trim() || null,
102
- name: getAgentMentionName(node.attrs.text, fallbackName),
104
+ context: getAgentMentionParentContext(parentNode, node.attrs.localId),
105
+ name: name,
106
+ prompt: parentNode.textContent.trim() || null,
103
107
  nodeSize: node.nodeSize,
104
108
  parentEnd: $mentionPos.end($mentionPos.depth),
105
109
  parentNodeType: (_parentNode$type$name = parentNode.type.name) !== null && _parentNode$type$name !== void 0 ? _parentNode$type$name : null,
@@ -188,6 +192,7 @@ var commitResolvedPendingTypedAgentMention = function commitResolvedPendingTyped
188
192
  lastInsertedAgentMentionLocalId: pendingMentionDetails.localId,
189
193
  lastInsertedAgentMentionContext: pendingMentionDetails.context,
190
194
  lastInsertedAgentMentionName: pendingMentionDetails.name,
195
+ lastInsertedAgentMentionPrompt: pendingMentionDetails.prompt,
191
196
  lastInsertedAgentMentionParentNodeType: pendingMentionDetails.parentNodeType,
192
197
  lastAgentMentionInsertionCount: ((_pluginState$lastAgen = pluginState.lastAgentMentionInsertionCount) !== null && _pluginState$lastAgen !== void 0 ? _pluginState$lastAgen : 0) + 1
193
198
  })
@@ -214,7 +219,7 @@ var commitPendingTypedAgentMention = function commitPendingTypedAgentMention(sta
214
219
  return commitResolvedPendingTypedAgentMention(pluginState, pendingMentionDetails);
215
220
  };
216
221
  var hasTrackedAgentMentionState = function hasTrackedAgentMentionState(pluginState) {
217
- return Boolean(pluginState.pendingTypedAgentMention) || pluginState.lastInsertedAgentMentionId != null || pluginState.lastInsertedAgentMentionLocalId != null || pluginState.lastInsertedAgentMentionContext != null || pluginState.lastInsertedAgentMentionName != null || pluginState.lastInsertedAgentMentionParentNodeType != null;
222
+ return Boolean(pluginState.pendingTypedAgentMention) || pluginState.lastInsertedAgentMentionId != null || pluginState.lastInsertedAgentMentionLocalId != null || pluginState.lastInsertedAgentMentionContext != null || pluginState.lastInsertedAgentMentionName != null || pluginState.lastInsertedAgentMentionPrompt != null || pluginState.lastInsertedAgentMentionParentNodeType != null;
218
223
  };
219
224
 
220
225
  /**
@@ -229,6 +234,7 @@ var clearTrackedAgentMentionState = function clearTrackedAgentMentionState(plugi
229
234
  lastInsertedAgentMentionLocalId: null,
230
235
  lastInsertedAgentMentionContext: null,
231
236
  lastInsertedAgentMentionName: null,
237
+ lastInsertedAgentMentionPrompt: null,
232
238
  lastInsertedAgentMentionParentNodeType: null
233
239
  });
234
240
  };
@@ -418,6 +424,7 @@ export function createMentionPlugin(_ref2) {
418
424
  var agentMentionLocalId = null;
419
425
  var agentMentionContext = null;
420
426
  var agentMentionName = null;
427
+ var agentMentionPrompt = null;
421
428
  var agentMentionParentNodeType = null;
422
429
  var existingAgentMentionLocalIdsInChangedRanges = new Set();
423
430
  var pendingTypedAgentMentionDetails = null;
@@ -449,6 +456,7 @@ export function createMentionPlugin(_ref2) {
449
456
  agentMentionLocalId = agentMentionDetails.localId;
450
457
  agentMentionContext = agentMentionDetails.context;
451
458
  agentMentionName = agentMentionDetails.name;
459
+ agentMentionPrompt = agentMentionDetails.prompt;
452
460
  agentMentionParentNodeType = agentMentionDetails.parentNodeType;
453
461
  }
454
462
  }
@@ -497,6 +505,7 @@ export function createMentionPlugin(_ref2) {
497
505
  agentMentionLocalId = survivorDetails.localId;
498
506
  agentMentionContext = survivorDetails.context;
499
507
  agentMentionName = survivorDetails.name;
508
+ agentMentionPrompt = survivorDetails.prompt;
500
509
  agentMentionParentNodeType = survivorDetails.parentNodeType;
501
510
  resolvedFromFullDocFallback = true;
502
511
  }
@@ -545,17 +554,19 @@ export function createMentionPlugin(_ref2) {
545
554
  lastInsertedAgentMentionLocalId: agentMentionLocalId,
546
555
  lastInsertedAgentMentionContext: agentMentionContext,
547
556
  lastInsertedAgentMentionName: agentMentionName,
557
+ lastInsertedAgentMentionPrompt: agentMentionPrompt,
548
558
  lastInsertedAgentMentionParentNodeType: agentMentionParentNodeType
549
559
  }, newInsertionCount !== undefined ? {
550
560
  lastAgentMentionInsertionCount: newInsertionCount
551
561
  } : {});
552
562
  hasPublicPluginStateChanged = true;
553
- } 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) || agentMentionContext !== ((_newPluginState$lastI4 = newPluginState.lastInsertedAgentMentionContext) !== null && _newPluginState$lastI4 !== void 0 ? _newPluginState$lastI4 : null) || agentMentionName !== ((_newPluginState$lastI5 = newPluginState.lastInsertedAgentMentionName) !== null && _newPluginState$lastI5 !== void 0 ? _newPluginState$lastI5 : null) || agentMentionParentNodeType !== ((_newPluginState$lastI6 = newPluginState.lastInsertedAgentMentionParentNodeType) !== null && _newPluginState$lastI6 !== void 0 ? _newPluginState$lastI6 : null) || newInsertionCount !== undefined) {
563
+ } 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) {
554
564
  newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
555
565
  lastInsertedAgentMentionId: agentMentionId,
556
566
  lastInsertedAgentMentionLocalId: agentMentionLocalId,
557
567
  lastInsertedAgentMentionContext: agentMentionContext,
558
568
  lastInsertedAgentMentionName: agentMentionName,
569
+ lastInsertedAgentMentionPrompt: agentMentionPrompt,
559
570
  lastInsertedAgentMentionParentNodeType: agentMentionParentNodeType
560
571
  }, newInsertionCount !== undefined ? {
561
572
  lastAgentMentionInsertionCount: newInsertionCount
@@ -0,0 +1,18 @@
1
+ import type { DocNode } from '@atlaskit/adf-schema';
2
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
+ /**
4
+ * Returns the direct parent content of an inserted agent mention as prompt ADF.
5
+ *
6
+ * The chat input supports only a subset of editor inline ADF, so this keeps prompt content
7
+ * intentionally narrow:
8
+ * - `text`, `inlineCard`, and `hardBreak` pass through unchanged.
9
+ * - people mentions pass through unchanged.
10
+ * - only the invoked agent mention is kept, identified by `localId`; other agent mentions are dropped.
11
+ * - `status` becomes its label text.
12
+ * - `date` becomes ISO date text.
13
+ * - everything else is dropped.
14
+ *
15
+ * This only reads direct parent content. It does not recursively pull content out of nested or
16
+ * unsupported nodes.
17
+ */
18
+ export declare const getAgentMentionParentContext: (parentNode: PMNode, agentMentionLocalId?: string | null) => DocNode;
@@ -1,3 +1,4 @@
1
+ import type { DocNode } from '@atlaskit/adf-schema';
1
2
  import type { AnalyticsEventPayload } from '@atlaskit/editor-common/analytics';
2
3
  import type { Providers, ProfilecardProvider } from '@atlaskit/editor-common/provider-factory';
3
4
  import type { TypeAheadHandler } from '@atlaskit/editor-common/types';
@@ -44,7 +45,7 @@ export interface MentionsPluginOptions extends MentionPluginConfig {
44
45
  */
45
46
  export type MentionPluginOptions = MentionsPluginOptions;
46
47
  export type AgentMentionDetails = {
47
- context: string | null;
48
+ context: DocNode;
48
49
  id: string;
49
50
  localId: string;
50
51
  name: string | null;
@@ -59,6 +60,7 @@ export type AgentMentionDetails = {
59
60
  */
60
61
  parentStart: number;
61
62
  pos: number;
63
+ prompt: string | null;
62
64
  };
63
65
  export type MentionPluginState = {
64
66
  canInsertMention?: boolean;
@@ -68,10 +70,10 @@ export type MentionPluginState = {
68
70
  */
69
71
  lastAgentMentionInsertionCount?: number;
70
72
  /**
71
- * Plain-text content of the block node containing the agent mention.
73
+ * Prompt-safe ADF context from the direct parent of the agent mention.
72
74
  * Used as a prompt context for Rovo chat.
73
75
  */
74
- lastInsertedAgentMentionContext?: string | null;
76
+ lastInsertedAgentMentionContext?: DocNode | null;
75
77
  /**
76
78
  * The ID of the most recently inserted agent (APP | AGENT userType) mention.
77
79
  * Null when no agent mention is present in the document.
@@ -92,6 +94,11 @@ export type MentionPluginState = {
92
94
  * (e.g. 'taskItem', 'paragraph'). Determines auto-send vs. draft behaviour.
93
95
  */
94
96
  lastInsertedAgentMentionParentNodeType?: string | null;
97
+ /**
98
+ * Plain-text prompt from the direct parent of the agent mention.
99
+ * Preserves the pre-ADF fallback behaviour for chat input drafts.
100
+ */
101
+ lastInsertedAgentMentionPrompt?: string | null;
95
102
  mentionProvider?: MentionProvider;
96
103
  mentions?: Array<MentionDescription>;
97
104
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-mentions",
3
- "version": "14.5.9",
3
+ "version": "14.5.10",
4
4
  "description": "Mentions plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -41,7 +41,7 @@
41
41
  "@atlaskit/profilecard": "^26.5.0",
42
42
  "@atlaskit/teams-app-config": "^2.1.0",
43
43
  "@atlaskit/theme": "^26.1.0",
44
- "@atlaskit/tmp-editor-statsig": "^119.2.0",
44
+ "@atlaskit/tmp-editor-statsig": "^120.0.0",
45
45
  "@atlaskit/tokens": "^15.3.0",
46
46
  "@atlaskit/tooltip": "^23.1.0",
47
47
  "@atlaskit/user-picker": "^13.4.0",
@@ -53,7 +53,7 @@
53
53
  "uuid": "^3.1.0"
54
54
  },
55
55
  "peerDependencies": {
56
- "@atlaskit/editor-common": "^116.19.0",
56
+ "@atlaskit/editor-common": "^116.20.0",
57
57
  "react": "^18.2.0",
58
58
  "react-dom": "^18.2.0",
59
59
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"