@atlaskit/editor-plugin-mentions 14.5.9 → 14.5.11
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 +16 -0
- package/dist/cjs/nodeviews/mentionNodeView.js +52 -16
- package/dist/cjs/pm-plugins/agent-mention-context.js +87 -0
- package/dist/cjs/pm-plugins/main.js +17 -6
- package/dist/es2019/nodeviews/mentionNodeView.js +43 -13
- package/dist/es2019/pm-plugins/agent-mention-context.js +81 -0
- package/dist/es2019/pm-plugins/main.js +17 -6
- package/dist/esm/nodeviews/mentionNodeView.js +52 -16
- package/dist/esm/pm-plugins/agent-mention-context.js +81 -0
- package/dist/esm/pm-plugins/main.js +17 -6
- package/dist/types/pm-plugins/agent-mention-context.d.ts +18 -0
- package/dist/types/types/index.d.ts +10 -3
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-mentions
|
|
2
2
|
|
|
3
|
+
## 14.5.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`48dd7ce8c1cb2`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/48dd7ce8c1cb2) -
|
|
8
|
+
EDITOR-7322 - fix mention pill getting overwritten with aaid
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
11
|
+
## 14.5.10
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [`1448830a87645`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1448830a87645) -
|
|
16
|
+
Preserve ADF-backed editor agent mention prompt context through Rovo chat drafts and sends.
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
3
19
|
## 14.5.9
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -23,11 +23,36 @@ var _profileCardRenderer2 = require("./profileCardRenderer");
|
|
|
23
23
|
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; }
|
|
24
24
|
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; }
|
|
25
25
|
var primitiveClassName = 'editor-mention-primitive';
|
|
26
|
-
//
|
|
26
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
27
27
|
var AT_PREFIX_REGEX = /^@/;
|
|
28
28
|
var getAccessibilityLabelFromName = function getAccessibilityLabelFromName(name) {
|
|
29
29
|
return name.replace(AT_PREFIX_REGEX, '');
|
|
30
30
|
};
|
|
31
|
+
|
|
32
|
+
// Workaround: AI-rewritten pages may store the raw AAID (e.g. '@712020:uuid') in attrs.text for
|
|
33
|
+
// APP/AGENT mentions instead of the display name. Detect this so we can fall through to provider
|
|
34
|
+
// resolution. Pattern: '@digits:uuid' — distinct from plain-UUID human AAIDs (no numeric prefix).
|
|
35
|
+
var AAID_MENTION_TEXT_PATTERN =
|
|
36
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
37
|
+
/^@\d+:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
38
|
+
|
|
39
|
+
/** Returns true if `text` looks like a raw AAID rather than a display name. */
|
|
40
|
+
var isMentionTextAnAaid = function isMentionTextAnAaid(text) {
|
|
41
|
+
return AAID_MENTION_TEXT_PATTERN.test(text);
|
|
42
|
+
};
|
|
43
|
+
var isAgentMentionsExperimentEnabled = function isAgentMentionsExperimentEnabled() {
|
|
44
|
+
return (0, _expVal.expVal)('platform_editor_agent_mentions', 'isEnabled', false);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Returns true if the node is an APP/AGENT mention whose stored text is a raw
|
|
49
|
+
* AAID (e.g. '@712020:uuid') rather than a resolved display name.
|
|
50
|
+
* All AAID-workaround guards should go through this helper so the checks stay
|
|
51
|
+
* consistent and can't drift apart.
|
|
52
|
+
*/
|
|
53
|
+
var isAgentAaidText = function isAgentAaidText(node, isAgentMentionsEnabled) {
|
|
54
|
+
return isAgentMentionsEnabled && (node.attrs.userType === 'APP' || node.attrs.userType === 'AGENT') && !!node.attrs.text && isMentionTextAnAaid(node.attrs.text);
|
|
55
|
+
};
|
|
31
56
|
var toDOM = function toDOM(node) {
|
|
32
57
|
// packages/elements/mention/src/components/Mention/index.tsx
|
|
33
58
|
var mentionAttrs = {
|
|
@@ -45,12 +70,14 @@ var toDOM = function toDOM(node) {
|
|
|
45
70
|
'data-local-id': node.attrs.localId
|
|
46
71
|
});
|
|
47
72
|
}
|
|
48
|
-
|
|
73
|
+
var isAgentMentionsEnabled = isAgentMentionsExperimentEnabled();
|
|
74
|
+
if (isAgentMentionsEnabled && node.attrs.userType) {
|
|
49
75
|
mentionAttrs = _objectSpread(_objectSpread({}, mentionAttrs), {}, {
|
|
50
76
|
'data-user-type': node.attrs.userType
|
|
51
77
|
});
|
|
52
78
|
}
|
|
53
79
|
var browser = (0, _browser.getBrowserInfo)();
|
|
80
|
+
var hasAgentAaidText = isAgentAaidText(node, isAgentMentionsEnabled);
|
|
54
81
|
return ['span', mentionAttrs, ['span', {
|
|
55
82
|
class: 'zeroWidthSpaceContainer'
|
|
56
83
|
}, ['span', {
|
|
@@ -58,7 +85,7 @@ var toDOM = function toDOM(node) {
|
|
|
58
85
|
}, _whitespace.ZERO_WIDTH_SPACE]], ['span', {
|
|
59
86
|
spellcheck: 'false',
|
|
60
87
|
class: primitiveClassName
|
|
61
|
-
}, node.attrs.text
|
|
88
|
+
}, node.attrs.text && !hasAgentAaidText ? node.attrs.text : '@…'], browser.android ? ['span', {
|
|
62
89
|
class: 'zeroWidthSpaceContainer',
|
|
63
90
|
contenteditable: 'false'
|
|
64
91
|
}, ['span', {
|
|
@@ -71,12 +98,14 @@ var processName = function processName(name) {
|
|
|
71
98
|
return name.status === _resource.MentionNameStatus.OK ? "@".concat(name.name || '') : "@_|unknown|_";
|
|
72
99
|
};
|
|
73
100
|
var handleProviderName = /*#__PURE__*/function () {
|
|
74
|
-
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(mentionProvider, node) {
|
|
75
|
-
var nameDetail, resolvedNameDetail;
|
|
101
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(mentionProvider, node, isAgentMentionsEnabled) {
|
|
102
|
+
var textIsAaid, nameDetail, resolvedNameDetail;
|
|
76
103
|
return _regenerator.default.wrap(function (_context) {
|
|
77
104
|
while (1) switch (_context.prev = _context.next) {
|
|
78
105
|
case 0:
|
|
79
|
-
|
|
106
|
+
// Also resolve when text is a raw AAID — provider will return the real display name.
|
|
107
|
+
textIsAaid = isAgentAaidText(node, isAgentMentionsEnabled);
|
|
108
|
+
if (!((0, _resource.isResolvingMentionProvider)(mentionProvider) && node.attrs.id && (!node.attrs.text || textIsAaid))) {
|
|
80
109
|
_context.next = 2;
|
|
81
110
|
break;
|
|
82
111
|
}
|
|
@@ -92,7 +121,7 @@ var handleProviderName = /*#__PURE__*/function () {
|
|
|
92
121
|
}
|
|
93
122
|
}, _callee);
|
|
94
123
|
}));
|
|
95
|
-
return function handleProviderName(_x, _x2) {
|
|
124
|
+
return function handleProviderName(_x, _x2, _x3) {
|
|
96
125
|
return _ref.apply(this, arguments);
|
|
97
126
|
};
|
|
98
127
|
}();
|
|
@@ -147,7 +176,8 @@ var MentionNodeView = exports.MentionNodeView = /*#__PURE__*/function () {
|
|
|
147
176
|
updateNode = _profileCardRenderer.updateNode;
|
|
148
177
|
// Accessibility attributes - based on `packages/people-and-teams/profilecard/src/components/User/ProfileCardTrigger.tsx`
|
|
149
178
|
if (this.domElement && options !== null && options !== void 0 && options.profilecardProvider) {
|
|
150
|
-
|
|
179
|
+
var isAgentMentionsEnabled = isAgentMentionsExperimentEnabled();
|
|
180
|
+
if (node.attrs.text && !isAgentAaidText(node, isAgentMentionsEnabled)) {
|
|
151
181
|
this.domElement.setAttribute('aria-label', getAccessibilityLabelFromName(node.attrs.text));
|
|
152
182
|
}
|
|
153
183
|
this.domElement.setAttribute('aria-expanded', 'false');
|
|
@@ -252,8 +282,10 @@ var MentionNodeView = exports.MentionNodeView = /*#__PURE__*/function () {
|
|
|
252
282
|
}
|
|
253
283
|
}, {
|
|
254
284
|
key: "setTextContent",
|
|
255
|
-
value: function setTextContent(name) {
|
|
256
|
-
|
|
285
|
+
value: function setTextContent(name, isAgentMentionsEnabled) {
|
|
286
|
+
// Also overwrite when text is a raw AAID so the resolved name takes precedence.
|
|
287
|
+
var textIsAaid = isAgentAaidText(this.node, isAgentMentionsEnabled);
|
|
288
|
+
if (name && (!this.node.attrs.text || textIsAaid) && this.mentionPrimitiveElement) {
|
|
257
289
|
this.mentionPrimitiveElement.textContent = name;
|
|
258
290
|
}
|
|
259
291
|
}
|
|
@@ -278,10 +310,11 @@ var MentionNodeView = exports.MentionNodeView = /*#__PURE__*/function () {
|
|
|
278
310
|
value: function () {
|
|
279
311
|
var _updateState = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(mentionProvider) {
|
|
280
312
|
var _mentionProvider$shou2, _this$config$options2;
|
|
281
|
-
var isHighlighted, disabledState, isDisabled, newState, disabledTooltip, name;
|
|
313
|
+
var isAgentMentionsEnabled, isHighlighted, disabledState, isDisabled, newState, disabledTooltip, name, text;
|
|
282
314
|
return _regenerator.default.wrap(function (_context2) {
|
|
283
315
|
while (1) switch (_context2.prev = _context2.next) {
|
|
284
316
|
case 0:
|
|
317
|
+
isAgentMentionsEnabled = isAgentMentionsExperimentEnabled();
|
|
285
318
|
isHighlighted = (0, _expValEquals.expValEquals)('platform_editor_vc90_transition_mentions', 'isEnabled', true) ? this.shouldHighlightMention(mentionProvider) : (_mentionProvider$shou2 = mentionProvider === null || mentionProvider === void 0 ? void 0 : mentionProvider.shouldHighlightMention({
|
|
286
319
|
id: this.node.attrs.id
|
|
287
320
|
})) !== null && _mentionProvider$shou2 !== void 0 ? _mentionProvider$shou2 : false;
|
|
@@ -298,15 +331,18 @@ var MentionNodeView = exports.MentionNodeView = /*#__PURE__*/function () {
|
|
|
298
331
|
// the chip is already disabled.
|
|
299
332
|
this.syncDisabledTooltip(disabledState);
|
|
300
333
|
_context2.next = 1;
|
|
301
|
-
return handleProviderName(mentionProvider, this.node);
|
|
334
|
+
return handleProviderName(mentionProvider, this.node, isAgentMentionsEnabled);
|
|
302
335
|
case 1:
|
|
303
336
|
name = _context2.sent;
|
|
304
|
-
this.setTextContent(name);
|
|
337
|
+
this.setTextContent(name, isAgentMentionsEnabled);
|
|
305
338
|
// Only overwrite the disabled-state aria-label with the name-based one
|
|
306
339
|
// when the chip is NOT disabled; otherwise the disabled reason set in
|
|
307
340
|
// `setClassList` would be silently clobbered, regressing a11y.
|
|
308
|
-
if (
|
|
309
|
-
this.
|
|
341
|
+
if (this.domElement && (_this$config$options2 = this.config.options) !== null && _this$config$options2 !== void 0 && _this$config$options2.profilecardProvider && newState !== 'disabled') {
|
|
342
|
+
text = name !== null && name !== void 0 ? name : this.node.attrs.text;
|
|
343
|
+
if (text && !isAgentAaidText(this.node, isAgentMentionsEnabled)) {
|
|
344
|
+
this.domElement.setAttribute('aria-label', getAccessibilityLabelFromName(text));
|
|
345
|
+
}
|
|
310
346
|
}
|
|
311
347
|
case 2:
|
|
312
348
|
case "end":
|
|
@@ -314,7 +350,7 @@ var MentionNodeView = exports.MentionNodeView = /*#__PURE__*/function () {
|
|
|
314
350
|
}
|
|
315
351
|
}, _callee2, this);
|
|
316
352
|
}));
|
|
317
|
-
function updateState(
|
|
353
|
+
function updateState(_x4) {
|
|
318
354
|
return _updateState.apply(this, arguments);
|
|
319
355
|
}
|
|
320
356
|
return updateState;
|
|
@@ -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.
|
|
55
|
+
var PACKAGE_VERSION = "14.5.10";
|
|
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:
|
|
110
|
+
id: id,
|
|
108
111
|
localId: node.attrs.localId,
|
|
109
|
-
context: parentNode.
|
|
110
|
-
name:
|
|
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) ||
|
|
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
|
|
@@ -9,9 +9,28 @@ import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
|
|
|
9
9
|
import { disabledTooltipRenderer } from './disabledTooltipRenderer';
|
|
10
10
|
import { profileCardRenderer } from './profileCardRenderer';
|
|
11
11
|
const primitiveClassName = 'editor-mention-primitive';
|
|
12
|
-
//
|
|
13
|
-
const AT_PREFIX_REGEX =
|
|
12
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
13
|
+
const AT_PREFIX_REGEX = /^@/;
|
|
14
14
|
const getAccessibilityLabelFromName = name => name.replace(AT_PREFIX_REGEX, '');
|
|
15
|
+
|
|
16
|
+
// Workaround: AI-rewritten pages may store the raw AAID (e.g. '@712020:uuid') in attrs.text for
|
|
17
|
+
// APP/AGENT mentions instead of the display name. Detect this so we can fall through to provider
|
|
18
|
+
// resolution. Pattern: '@digits:uuid' — distinct from plain-UUID human AAIDs (no numeric prefix).
|
|
19
|
+
const AAID_MENTION_TEXT_PATTERN =
|
|
20
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
21
|
+
/^@\d+:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
22
|
+
|
|
23
|
+
/** Returns true if `text` looks like a raw AAID rather than a display name. */
|
|
24
|
+
const isMentionTextAnAaid = text => AAID_MENTION_TEXT_PATTERN.test(text);
|
|
25
|
+
const isAgentMentionsExperimentEnabled = () => expVal('platform_editor_agent_mentions', 'isEnabled', false);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Returns true if the node is an APP/AGENT mention whose stored text is a raw
|
|
29
|
+
* AAID (e.g. '@712020:uuid') rather than a resolved display name.
|
|
30
|
+
* All AAID-workaround guards should go through this helper so the checks stay
|
|
31
|
+
* consistent and can't drift apart.
|
|
32
|
+
*/
|
|
33
|
+
const isAgentAaidText = (node, isAgentMentionsEnabled) => isAgentMentionsEnabled && (node.attrs.userType === 'APP' || node.attrs.userType === 'AGENT') && !!node.attrs.text && isMentionTextAnAaid(node.attrs.text);
|
|
15
34
|
const toDOM = node => {
|
|
16
35
|
// packages/elements/mention/src/components/Mention/index.tsx
|
|
17
36
|
let mentionAttrs = {
|
|
@@ -30,13 +49,15 @@ const toDOM = node => {
|
|
|
30
49
|
'data-local-id': node.attrs.localId
|
|
31
50
|
};
|
|
32
51
|
}
|
|
33
|
-
|
|
52
|
+
const isAgentMentionsEnabled = isAgentMentionsExperimentEnabled();
|
|
53
|
+
if (isAgentMentionsEnabled && node.attrs.userType) {
|
|
34
54
|
mentionAttrs = {
|
|
35
55
|
...mentionAttrs,
|
|
36
56
|
'data-user-type': node.attrs.userType
|
|
37
57
|
};
|
|
38
58
|
}
|
|
39
59
|
const browser = getBrowserInfo();
|
|
60
|
+
const hasAgentAaidText = isAgentAaidText(node, isAgentMentionsEnabled);
|
|
40
61
|
return ['span', mentionAttrs, ['span', {
|
|
41
62
|
class: 'zeroWidthSpaceContainer'
|
|
42
63
|
}, ['span', {
|
|
@@ -44,7 +65,7 @@ const toDOM = node => {
|
|
|
44
65
|
}, ZERO_WIDTH_SPACE]], ['span', {
|
|
45
66
|
spellcheck: 'false',
|
|
46
67
|
class: primitiveClassName
|
|
47
|
-
}, node.attrs.text
|
|
68
|
+
}, node.attrs.text && !hasAgentAaidText ? node.attrs.text : '@…'], browser.android ? ['span', {
|
|
48
69
|
class: 'zeroWidthSpaceContainer',
|
|
49
70
|
contenteditable: 'false'
|
|
50
71
|
}, ['span', {
|
|
@@ -56,8 +77,10 @@ const toDOM = node => {
|
|
|
56
77
|
const processName = name => {
|
|
57
78
|
return name.status === MentionNameStatus.OK ? `@${name.name || ''}` : `@_|unknown|_`;
|
|
58
79
|
};
|
|
59
|
-
const handleProviderName = async (mentionProvider, node) => {
|
|
60
|
-
|
|
80
|
+
const handleProviderName = async (mentionProvider, node, isAgentMentionsEnabled) => {
|
|
81
|
+
// Also resolve when text is a raw AAID — provider will return the real display name.
|
|
82
|
+
const textIsAaid = isAgentAaidText(node, isAgentMentionsEnabled);
|
|
83
|
+
if (isResolvingMentionProvider(mentionProvider) && node.attrs.id && (!node.attrs.text || textIsAaid)) {
|
|
61
84
|
const nameDetail = mentionProvider === null || mentionProvider === void 0 ? void 0 : mentionProvider.resolveMentionName(node.attrs.id);
|
|
62
85
|
const resolvedNameDetail = await nameDetail;
|
|
63
86
|
return processName(resolvedNameDetail);
|
|
@@ -117,7 +140,8 @@ export class MentionNodeView {
|
|
|
117
140
|
});
|
|
118
141
|
// Accessibility attributes - based on `packages/people-and-teams/profilecard/src/components/User/ProfileCardTrigger.tsx`
|
|
119
142
|
if (this.domElement && options !== null && options !== void 0 && options.profilecardProvider) {
|
|
120
|
-
|
|
143
|
+
const isAgentMentionsEnabled = isAgentMentionsExperimentEnabled();
|
|
144
|
+
if (node.attrs.text && !isAgentAaidText(node, isAgentMentionsEnabled)) {
|
|
121
145
|
this.domElement.setAttribute('aria-label', getAccessibilityLabelFromName(node.attrs.text));
|
|
122
146
|
}
|
|
123
147
|
this.domElement.setAttribute('aria-expanded', 'false');
|
|
@@ -213,8 +237,10 @@ export class MentionNodeView {
|
|
|
213
237
|
this.disabledTooltip = undefined;
|
|
214
238
|
}
|
|
215
239
|
}
|
|
216
|
-
setTextContent(name) {
|
|
217
|
-
|
|
240
|
+
setTextContent(name, isAgentMentionsEnabled) {
|
|
241
|
+
// Also overwrite when text is a raw AAID so the resolved name takes precedence.
|
|
242
|
+
const textIsAaid = isAgentAaidText(this.node, isAgentMentionsEnabled);
|
|
243
|
+
if (name && (!this.node.attrs.text || textIsAaid) && this.mentionPrimitiveElement) {
|
|
218
244
|
this.mentionPrimitiveElement.textContent = name;
|
|
219
245
|
}
|
|
220
246
|
}
|
|
@@ -235,6 +261,7 @@ export class MentionNodeView {
|
|
|
235
261
|
}
|
|
236
262
|
async updateState(mentionProvider) {
|
|
237
263
|
var _mentionProvider$shou2, _this$config$options2;
|
|
264
|
+
const isAgentMentionsEnabled = isAgentMentionsExperimentEnabled();
|
|
238
265
|
const isHighlighted = expValEquals('platform_editor_vc90_transition_mentions', 'isEnabled', true) ? this.shouldHighlightMention(mentionProvider) : (_mentionProvider$shou2 = mentionProvider === null || mentionProvider === void 0 ? void 0 : mentionProvider.shouldHighlightMention({
|
|
239
266
|
id: this.node.attrs.id
|
|
240
267
|
})) !== null && _mentionProvider$shou2 !== void 0 ? _mentionProvider$shou2 : false;
|
|
@@ -251,13 +278,16 @@ export class MentionNodeView {
|
|
|
251
278
|
// the tooltip text stays in sync if the disabled reason changes while
|
|
252
279
|
// the chip is already disabled.
|
|
253
280
|
this.syncDisabledTooltip(disabledState);
|
|
254
|
-
const name = await handleProviderName(mentionProvider, this.node);
|
|
255
|
-
this.setTextContent(name);
|
|
281
|
+
const name = await handleProviderName(mentionProvider, this.node, isAgentMentionsEnabled);
|
|
282
|
+
this.setTextContent(name, isAgentMentionsEnabled);
|
|
256
283
|
// Only overwrite the disabled-state aria-label with the name-based one
|
|
257
284
|
// when the chip is NOT disabled; otherwise the disabled reason set in
|
|
258
285
|
// `setClassList` would be silently clobbered, regressing a11y.
|
|
259
|
-
if (
|
|
260
|
-
this.
|
|
286
|
+
if (this.domElement && (_this$config$options2 = this.config.options) !== null && _this$config$options2 !== void 0 && _this$config$options2.profilecardProvider && newState !== 'disabled') {
|
|
287
|
+
const text = name !== null && name !== void 0 ? name : this.node.attrs.text;
|
|
288
|
+
if (text && !isAgentAaidText(this.node, isAgentMentionsEnabled)) {
|
|
289
|
+
this.domElement.setAttribute('aria-label', getAccessibilityLabelFromName(text));
|
|
290
|
+
}
|
|
261
291
|
}
|
|
262
292
|
}
|
|
263
293
|
nodeIsEqual(nextNode) {
|
|
@@ -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.
|
|
40
|
+
const PACKAGE_VERSION = "14.5.10";
|
|
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
|
|
93
|
+
id,
|
|
91
94
|
localId: node.attrs.localId,
|
|
92
|
-
context: parentNode.
|
|
93
|
-
name
|
|
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) ||
|
|
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
|
|
@@ -16,11 +16,36 @@ import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
|
|
|
16
16
|
import { disabledTooltipRenderer } from './disabledTooltipRenderer';
|
|
17
17
|
import { profileCardRenderer } from './profileCardRenderer';
|
|
18
18
|
var primitiveClassName = 'editor-mention-primitive';
|
|
19
|
-
//
|
|
19
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
20
20
|
var AT_PREFIX_REGEX = /^@/;
|
|
21
21
|
var getAccessibilityLabelFromName = function getAccessibilityLabelFromName(name) {
|
|
22
22
|
return name.replace(AT_PREFIX_REGEX, '');
|
|
23
23
|
};
|
|
24
|
+
|
|
25
|
+
// Workaround: AI-rewritten pages may store the raw AAID (e.g. '@712020:uuid') in attrs.text for
|
|
26
|
+
// APP/AGENT mentions instead of the display name. Detect this so we can fall through to provider
|
|
27
|
+
// resolution. Pattern: '@digits:uuid' — distinct from plain-UUID human AAIDs (no numeric prefix).
|
|
28
|
+
var AAID_MENTION_TEXT_PATTERN =
|
|
29
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
30
|
+
/^@\d+:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
31
|
+
|
|
32
|
+
/** Returns true if `text` looks like a raw AAID rather than a display name. */
|
|
33
|
+
var isMentionTextAnAaid = function isMentionTextAnAaid(text) {
|
|
34
|
+
return AAID_MENTION_TEXT_PATTERN.test(text);
|
|
35
|
+
};
|
|
36
|
+
var isAgentMentionsExperimentEnabled = function isAgentMentionsExperimentEnabled() {
|
|
37
|
+
return expVal('platform_editor_agent_mentions', 'isEnabled', false);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Returns true if the node is an APP/AGENT mention whose stored text is a raw
|
|
42
|
+
* AAID (e.g. '@712020:uuid') rather than a resolved display name.
|
|
43
|
+
* All AAID-workaround guards should go through this helper so the checks stay
|
|
44
|
+
* consistent and can't drift apart.
|
|
45
|
+
*/
|
|
46
|
+
var isAgentAaidText = function isAgentAaidText(node, isAgentMentionsEnabled) {
|
|
47
|
+
return isAgentMentionsEnabled && (node.attrs.userType === 'APP' || node.attrs.userType === 'AGENT') && !!node.attrs.text && isMentionTextAnAaid(node.attrs.text);
|
|
48
|
+
};
|
|
24
49
|
var toDOM = function toDOM(node) {
|
|
25
50
|
// packages/elements/mention/src/components/Mention/index.tsx
|
|
26
51
|
var mentionAttrs = {
|
|
@@ -38,12 +63,14 @@ var toDOM = function toDOM(node) {
|
|
|
38
63
|
'data-local-id': node.attrs.localId
|
|
39
64
|
});
|
|
40
65
|
}
|
|
41
|
-
|
|
66
|
+
var isAgentMentionsEnabled = isAgentMentionsExperimentEnabled();
|
|
67
|
+
if (isAgentMentionsEnabled && node.attrs.userType) {
|
|
42
68
|
mentionAttrs = _objectSpread(_objectSpread({}, mentionAttrs), {}, {
|
|
43
69
|
'data-user-type': node.attrs.userType
|
|
44
70
|
});
|
|
45
71
|
}
|
|
46
72
|
var browser = getBrowserInfo();
|
|
73
|
+
var hasAgentAaidText = isAgentAaidText(node, isAgentMentionsEnabled);
|
|
47
74
|
return ['span', mentionAttrs, ['span', {
|
|
48
75
|
class: 'zeroWidthSpaceContainer'
|
|
49
76
|
}, ['span', {
|
|
@@ -51,7 +78,7 @@ var toDOM = function toDOM(node) {
|
|
|
51
78
|
}, ZERO_WIDTH_SPACE]], ['span', {
|
|
52
79
|
spellcheck: 'false',
|
|
53
80
|
class: primitiveClassName
|
|
54
|
-
}, node.attrs.text
|
|
81
|
+
}, node.attrs.text && !hasAgentAaidText ? node.attrs.text : '@…'], browser.android ? ['span', {
|
|
55
82
|
class: 'zeroWidthSpaceContainer',
|
|
56
83
|
contenteditable: 'false'
|
|
57
84
|
}, ['span', {
|
|
@@ -64,12 +91,14 @@ var processName = function processName(name) {
|
|
|
64
91
|
return name.status === MentionNameStatus.OK ? "@".concat(name.name || '') : "@_|unknown|_";
|
|
65
92
|
};
|
|
66
93
|
var handleProviderName = /*#__PURE__*/function () {
|
|
67
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(mentionProvider, node) {
|
|
68
|
-
var nameDetail, resolvedNameDetail;
|
|
94
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(mentionProvider, node, isAgentMentionsEnabled) {
|
|
95
|
+
var textIsAaid, nameDetail, resolvedNameDetail;
|
|
69
96
|
return _regeneratorRuntime.wrap(function (_context) {
|
|
70
97
|
while (1) switch (_context.prev = _context.next) {
|
|
71
98
|
case 0:
|
|
72
|
-
|
|
99
|
+
// Also resolve when text is a raw AAID — provider will return the real display name.
|
|
100
|
+
textIsAaid = isAgentAaidText(node, isAgentMentionsEnabled);
|
|
101
|
+
if (!(isResolvingMentionProvider(mentionProvider) && node.attrs.id && (!node.attrs.text || textIsAaid))) {
|
|
73
102
|
_context.next = 2;
|
|
74
103
|
break;
|
|
75
104
|
}
|
|
@@ -85,7 +114,7 @@ var handleProviderName = /*#__PURE__*/function () {
|
|
|
85
114
|
}
|
|
86
115
|
}, _callee);
|
|
87
116
|
}));
|
|
88
|
-
return function handleProviderName(_x, _x2) {
|
|
117
|
+
return function handleProviderName(_x, _x2, _x3) {
|
|
89
118
|
return _ref.apply(this, arguments);
|
|
90
119
|
};
|
|
91
120
|
}();
|
|
@@ -140,7 +169,8 @@ export var MentionNodeView = /*#__PURE__*/function () {
|
|
|
140
169
|
updateNode = _profileCardRenderer.updateNode;
|
|
141
170
|
// Accessibility attributes - based on `packages/people-and-teams/profilecard/src/components/User/ProfileCardTrigger.tsx`
|
|
142
171
|
if (this.domElement && options !== null && options !== void 0 && options.profilecardProvider) {
|
|
143
|
-
|
|
172
|
+
var isAgentMentionsEnabled = isAgentMentionsExperimentEnabled();
|
|
173
|
+
if (node.attrs.text && !isAgentAaidText(node, isAgentMentionsEnabled)) {
|
|
144
174
|
this.domElement.setAttribute('aria-label', getAccessibilityLabelFromName(node.attrs.text));
|
|
145
175
|
}
|
|
146
176
|
this.domElement.setAttribute('aria-expanded', 'false');
|
|
@@ -245,8 +275,10 @@ export var MentionNodeView = /*#__PURE__*/function () {
|
|
|
245
275
|
}
|
|
246
276
|
}, {
|
|
247
277
|
key: "setTextContent",
|
|
248
|
-
value: function setTextContent(name) {
|
|
249
|
-
|
|
278
|
+
value: function setTextContent(name, isAgentMentionsEnabled) {
|
|
279
|
+
// Also overwrite when text is a raw AAID so the resolved name takes precedence.
|
|
280
|
+
var textIsAaid = isAgentAaidText(this.node, isAgentMentionsEnabled);
|
|
281
|
+
if (name && (!this.node.attrs.text || textIsAaid) && this.mentionPrimitiveElement) {
|
|
250
282
|
this.mentionPrimitiveElement.textContent = name;
|
|
251
283
|
}
|
|
252
284
|
}
|
|
@@ -271,10 +303,11 @@ export var MentionNodeView = /*#__PURE__*/function () {
|
|
|
271
303
|
value: function () {
|
|
272
304
|
var _updateState = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(mentionProvider) {
|
|
273
305
|
var _mentionProvider$shou2, _this$config$options2;
|
|
274
|
-
var isHighlighted, disabledState, isDisabled, newState, disabledTooltip, name;
|
|
306
|
+
var isAgentMentionsEnabled, isHighlighted, disabledState, isDisabled, newState, disabledTooltip, name, text;
|
|
275
307
|
return _regeneratorRuntime.wrap(function (_context2) {
|
|
276
308
|
while (1) switch (_context2.prev = _context2.next) {
|
|
277
309
|
case 0:
|
|
310
|
+
isAgentMentionsEnabled = isAgentMentionsExperimentEnabled();
|
|
278
311
|
isHighlighted = expValEquals('platform_editor_vc90_transition_mentions', 'isEnabled', true) ? this.shouldHighlightMention(mentionProvider) : (_mentionProvider$shou2 = mentionProvider === null || mentionProvider === void 0 ? void 0 : mentionProvider.shouldHighlightMention({
|
|
279
312
|
id: this.node.attrs.id
|
|
280
313
|
})) !== null && _mentionProvider$shou2 !== void 0 ? _mentionProvider$shou2 : false;
|
|
@@ -291,15 +324,18 @@ export var MentionNodeView = /*#__PURE__*/function () {
|
|
|
291
324
|
// the chip is already disabled.
|
|
292
325
|
this.syncDisabledTooltip(disabledState);
|
|
293
326
|
_context2.next = 1;
|
|
294
|
-
return handleProviderName(mentionProvider, this.node);
|
|
327
|
+
return handleProviderName(mentionProvider, this.node, isAgentMentionsEnabled);
|
|
295
328
|
case 1:
|
|
296
329
|
name = _context2.sent;
|
|
297
|
-
this.setTextContent(name);
|
|
330
|
+
this.setTextContent(name, isAgentMentionsEnabled);
|
|
298
331
|
// Only overwrite the disabled-state aria-label with the name-based one
|
|
299
332
|
// when the chip is NOT disabled; otherwise the disabled reason set in
|
|
300
333
|
// `setClassList` would be silently clobbered, regressing a11y.
|
|
301
|
-
if (
|
|
302
|
-
this.
|
|
334
|
+
if (this.domElement && (_this$config$options2 = this.config.options) !== null && _this$config$options2 !== void 0 && _this$config$options2.profilecardProvider && newState !== 'disabled') {
|
|
335
|
+
text = name !== null && name !== void 0 ? name : this.node.attrs.text;
|
|
336
|
+
if (text && !isAgentAaidText(this.node, isAgentMentionsEnabled)) {
|
|
337
|
+
this.domElement.setAttribute('aria-label', getAccessibilityLabelFromName(text));
|
|
338
|
+
}
|
|
303
339
|
}
|
|
304
340
|
case 2:
|
|
305
341
|
case "end":
|
|
@@ -307,7 +343,7 @@ export var MentionNodeView = /*#__PURE__*/function () {
|
|
|
307
343
|
}
|
|
308
344
|
}, _callee2, this);
|
|
309
345
|
}));
|
|
310
|
-
function updateState(
|
|
346
|
+
function updateState(_x4) {
|
|
311
347
|
return _updateState.apply(this, arguments);
|
|
312
348
|
}
|
|
313
349
|
return updateState;
|
|
@@ -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.
|
|
47
|
+
var PACKAGE_VERSION = "14.5.10";
|
|
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:
|
|
102
|
+
id: id,
|
|
100
103
|
localId: node.attrs.localId,
|
|
101
|
-
context: parentNode.
|
|
102
|
-
name:
|
|
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) ||
|
|
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:
|
|
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
|
-
*
|
|
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?:
|
|
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.
|
|
3
|
+
"version": "14.5.11",
|
|
4
4
|
"description": "Mentions plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"@atlaskit/popper": "^8.2.0",
|
|
39
39
|
"@atlaskit/portal": "^6.1.0",
|
|
40
40
|
"@atlaskit/primitives": "^20.3.0",
|
|
41
|
-
"@atlaskit/profilecard": "^26.
|
|
41
|
+
"@atlaskit/profilecard": "^26.8.0",
|
|
42
42
|
"@atlaskit/teams-app-config": "^2.1.0",
|
|
43
43
|
"@atlaskit/theme": "^26.1.0",
|
|
44
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
44
|
+
"@atlaskit/tmp-editor-statsig": "^120.1.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.
|
|
56
|
+
"@atlaskit/editor-common": "^116.21.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"
|