@atlaskit/editor-plugin-autocomplete 6.0.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/analytics/ufo.js +3 -2
  3. package/dist/cjs/pm-plugins/artifacts-manifest.js +210 -0
  4. package/dist/cjs/pm-plugins/autocomplete-plugin.js +10 -2
  5. package/dist/cjs/pm-plugins/local-slow-lane-client.js +68 -153
  6. package/dist/cjs/pm-plugins/scoring-pipeline.js +130 -28
  7. package/dist/cjs/pm-plugins/text-predictor.js +45 -106
  8. package/dist/es2019/analytics/ufo.js +4 -2
  9. package/dist/es2019/pm-plugins/artifacts-manifest.js +126 -0
  10. package/dist/es2019/pm-plugins/autocomplete-plugin.js +10 -2
  11. package/dist/es2019/pm-plugins/local-slow-lane-client.js +8 -78
  12. package/dist/es2019/pm-plugins/scoring-pipeline.js +97 -21
  13. package/dist/es2019/pm-plugins/text-predictor.js +17 -59
  14. package/dist/esm/analytics/ufo.js +3 -2
  15. package/dist/esm/pm-plugins/artifacts-manifest.js +204 -0
  16. package/dist/esm/pm-plugins/autocomplete-plugin.js +10 -2
  17. package/dist/esm/pm-plugins/local-slow-lane-client.js +67 -148
  18. package/dist/esm/pm-plugins/scoring-pipeline.js +128 -26
  19. package/dist/esm/pm-plugins/text-predictor.js +45 -98
  20. package/dist/types/analytics/ufo.d.ts +1 -0
  21. package/dist/types/pm-plugins/artifacts-manifest.d.ts +55 -0
  22. package/dist/types/pm-plugins/autocomplete-plugin.d.ts +5 -11
  23. package/dist/types/pm-plugins/scoring-pipeline.d.ts +14 -0
  24. package/dist/types/pm-plugins/text-predictor.d.ts +0 -1
  25. package/package.json +2 -5
  26. package/src/analytics/ufo.ts +5 -0
  27. package/src/pm-plugins/artifacts-manifest.ts +151 -0
  28. package/src/pm-plugins/autocomplete-plugin.ts +14 -12
  29. package/src/pm-plugins/local-slow-lane-client.ts +10 -92
  30. package/src/pm-plugins/scoring-pipeline.ts +115 -23
  31. package/src/pm-plugins/text-predictor.ts +26 -76
  32. package/dist/cjs/pm-plugins/data/combined_l2_l3_pos_tags.json +0 -73571
  33. package/dist/cjs/pm-plugins/data/first_token_to_words.json +0 -1
  34. package/dist/cjs/pm-plugins/data/ghost_pos_tags.json +0 -43
  35. package/dist/cjs/pm-plugins/data/grammar_transitions_10k.json +0 -46
  36. package/dist/cjs/pm-plugins/data/l3_vocabulary.json +0 -20002
  37. package/dist/cjs/pm-plugins/data/vocabulary_10k.json +0 -38794
  38. package/dist/cjs/pm-plugins/data/word_index_10k.json +0 -7762
  39. package/dist/es2019/pm-plugins/data/combined_l2_l3_pos_tags.json +0 -73571
  40. package/dist/es2019/pm-plugins/data/first_token_to_words.json +0 -1
  41. package/dist/es2019/pm-plugins/data/ghost_pos_tags.json +0 -43
  42. package/dist/es2019/pm-plugins/data/grammar_transitions_10k.json +0 -46
  43. package/dist/es2019/pm-plugins/data/l3_vocabulary.json +0 -20002
  44. package/dist/es2019/pm-plugins/data/vocabulary_10k.json +0 -38794
  45. package/dist/es2019/pm-plugins/data/word_index_10k.json +0 -7762
  46. package/dist/esm/pm-plugins/data/combined_l2_l3_pos_tags.json +0 -73571
  47. package/dist/esm/pm-plugins/data/first_token_to_words.json +0 -1
  48. package/dist/esm/pm-plugins/data/ghost_pos_tags.json +0 -43
  49. package/dist/esm/pm-plugins/data/grammar_transitions_10k.json +0 -46
  50. package/dist/esm/pm-plugins/data/l3_vocabulary.json +0 -20002
  51. package/dist/esm/pm-plugins/data/vocabulary_10k.json +0 -38794
  52. package/dist/esm/pm-plugins/data/word_index_10k.json +0 -7762
  53. package/src/pm-plugins/data/combined_l2_l3_pos_tags.json +0 -73571
  54. package/src/pm-plugins/data/first_token_to_words.json +0 -1
  55. package/src/pm-plugins/data/ghost_pos_tags.json +0 -43
  56. package/src/pm-plugins/data/grammar_transitions_10k.json +0 -46
  57. package/src/pm-plugins/data/l3_vocabulary.json +0 -20002
  58. package/src/pm-plugins/data/vocabulary_10k.json +0 -38794
  59. package/src/pm-plugins/data/word-vectors_10k.bin +0 -3
  60. package/src/pm-plugins/data/word_index_10k.json +0 -7762
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @atlaskit/editor-plugin-autocomplete
2
2
 
3
+ ## 7.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [`7a16264359631`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7a16264359631) -
8
+ Load autocomplete model artifacts from the CDN instead of bundling them. The vocabulary,
9
+ POS/grammar, word-index and word-vectors payloads are now resolved from GET
10
+ /gateway/api/v1/autocomplete/artifacts, so this endpoint must be reachable for autocomplete to
11
+ produce suggestions. BREAKING: the `getVectorsBinaryUrl` plugin option has been removed — the word
12
+ vectors binary URL now always comes from the artifacts manifest, so hosts must stop serving it
13
+ themselves.
14
+
15
+ Rovo chat autocomplete now runs on-device via WebGPU instead of the network slow-lane backend.
16
+
3
17
  ## 6.0.0
4
18
 
5
19
  ### Patch Changes
@@ -38,7 +38,8 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
38
38
  var EXPERIENCE_NAME = exports.EXPERIENCE_NAME = {
39
39
  SLOW_LANE_FETCH: 'slow-lane-fetch',
40
40
  LOAD_VOCABULARY: 'load-vocabulary',
41
- LOAD_VECTORS: 'load-vectors'
41
+ LOAD_VECTORS: 'load-vectors',
42
+ LOAD_GRAMMAR: 'load-grammar'
42
43
  };
43
44
  var isUfoEnabled = function isUfoEnabled() {
44
45
  var _process;
@@ -56,7 +57,7 @@ var operationConfig = {
56
57
  })
57
58
  }
58
59
  };
59
- var experiences = (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, EXPERIENCE_NAME.SLOW_LANE_FETCH, new _ufo.ConcurrentExperience(EXPERIENCE_NAME.SLOW_LANE_FETCH, operationConfig)), EXPERIENCE_NAME.LOAD_VOCABULARY, new _ufo.ConcurrentExperience(EXPERIENCE_NAME.LOAD_VOCABULARY, operationConfig)), EXPERIENCE_NAME.LOAD_VECTORS, new _ufo.ConcurrentExperience(EXPERIENCE_NAME.LOAD_VECTORS, operationConfig));
60
+ var experiences = (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, EXPERIENCE_NAME.SLOW_LANE_FETCH, new _ufo.ConcurrentExperience(EXPERIENCE_NAME.SLOW_LANE_FETCH, operationConfig)), EXPERIENCE_NAME.LOAD_VOCABULARY, new _ufo.ConcurrentExperience(EXPERIENCE_NAME.LOAD_VOCABULARY, operationConfig)), EXPERIENCE_NAME.LOAD_VECTORS, new _ufo.ConcurrentExperience(EXPERIENCE_NAME.LOAD_VECTORS, operationConfig)), EXPERIENCE_NAME.LOAD_GRAMMAR, new _ufo.ConcurrentExperience(EXPERIENCE_NAME.LOAD_GRAMMAR, operationConfig));
60
61
  var startExp = exports.startExp = function startExp(name, id, metadata) {
61
62
  if (!isUfoEnabled()) {
62
63
  return;
@@ -0,0 +1,210 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.resetArtifactsManifestCache = exports.getArtifactUrl = exports.fetchArtifactJson = exports.ARTIFACT_NAME = void 0;
8
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
+ var _debugMode = require("./debug-mode");
11
+ /**
12
+ * Artifacts Manifest Client: resolves the autocomplete model artifacts hosted on
13
+ * the CDN.
14
+ *
15
+ * `GET /gateway/api/v1/autocomplete/artifacts` returns one presigned CDN URL per
16
+ * artifact for the tenant's active model version:
17
+ *
18
+ * { activeVersion, artifacts: [{ name, url, contentType, sizeBytes, checksum }] }
19
+ *
20
+ * Every loader in the plugin resolves its payload through here, so no model data
21
+ * is bundled with the package.
22
+ */
23
+
24
+ // ─── Types ───────────────────────────────────────────────────────────────────
25
+
26
+ /**
27
+ * Manifest artifact names. These are the manifest's lookup keys and are
28
+ * hyphenated, unlike the underscored filenames the artifacts are generated from.
29
+ */
30
+ var ARTIFACT_NAME = exports.ARTIFACT_NAME = {
31
+ FIRST_TOKEN_TO_WORDS: 'first-token-to-words.json',
32
+ GHOST_POS_TAGS: 'ghost-pos-tags.json',
33
+ GRAMMAR_TRANSITIONS: 'grammar-transitions-10k.json',
34
+ L3_VOCABULARY: 'l3-vocabulary.json',
35
+ POS_TAGS: 'combined-l2-l3-pos-tags.json',
36
+ VOCABULARY: 'vocabulary-10k.json',
37
+ WORD_INDEX: 'word-index-10k.json',
38
+ WORD_VECTORS: 'word-vectors-10k.bin'
39
+ };
40
+
41
+ /** A single entry in the artifacts manifest. */
42
+
43
+ /** Response body of the artifacts endpoint. */
44
+
45
+ // ─── Constants ───────────────────────────────────────────────────────────────
46
+
47
+ var MANIFEST_ENDPOINT = '/gateway/api/v1/autocomplete/artifacts';
48
+
49
+ /**
50
+ * Presigned artifact URLs expire ~10 minutes after the manifest is issued, so
51
+ * the manifest is re-requested well inside that window instead of being cached
52
+ * for the session and handing out dead URLs to a late loader.
53
+ */
54
+ var MANIFEST_TTL_MS = 5 * 60 * 1000;
55
+
56
+ // ─── Manifest ────────────────────────────────────────────────────────────────
57
+
58
+ var manifestPromise;
59
+ var manifestRequestedAt = 0;
60
+
61
+ /** Test-only: drops the memoised manifest so the next lookup re-requests it. */
62
+ var resetArtifactsManifestCache = exports.resetArtifactsManifestCache = function resetArtifactsManifestCache() {
63
+ manifestPromise = undefined;
64
+ manifestRequestedAt = 0;
65
+ };
66
+ var requestManifest = /*#__PURE__*/function () {
67
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
68
+ var res, body;
69
+ return _regenerator.default.wrap(function (_context) {
70
+ while (1) switch (_context.prev = _context.next) {
71
+ case 0:
72
+ _context.next = 1;
73
+ return fetch(MANIFEST_ENDPOINT, {
74
+ method: 'GET',
75
+ headers: {
76
+ 'x-experience-id': 'confluence-smart-typeahead-artifacts',
77
+ 'x-product': 'confluence'
78
+ }
79
+ });
80
+ case 1:
81
+ res = _context.sent;
82
+ if (res.ok) {
83
+ _context.next = 2;
84
+ break;
85
+ }
86
+ throw new Error("[autocomplete-artifacts] Manifest request failed: ".concat(res.status));
87
+ case 2:
88
+ _context.next = 3;
89
+ return res.json();
90
+ case 3:
91
+ body = _context.sent;
92
+ if (!(!Array.isArray(body === null || body === void 0 ? void 0 : body.artifacts) || body.artifacts.length === 0)) {
93
+ _context.next = 4;
94
+ break;
95
+ }
96
+ throw new Error('[autocomplete-artifacts] Manifest response contained no artifacts');
97
+ case 4:
98
+ if ((0, _debugMode.isAutocompleteDebugEnabled)()) {
99
+ // eslint-disable-next-line no-console
100
+ console.log('[autocomplete-artifacts] Manifest loaded:', {
101
+ activeVersion: body.activeVersion,
102
+ names: body.artifacts.map(function (artifact) {
103
+ return artifact.name;
104
+ })
105
+ });
106
+ }
107
+ return _context.abrupt("return", new Map(body.artifacts.map(function (artifact) {
108
+ return [artifact.name, artifact];
109
+ })));
110
+ case 5:
111
+ case "end":
112
+ return _context.stop();
113
+ }
114
+ }, _callee);
115
+ }));
116
+ return function requestManifest() {
117
+ return _ref.apply(this, arguments);
118
+ };
119
+ }();
120
+ var getManifest = function getManifest() {
121
+ if (manifestPromise && Date.now() - manifestRequestedAt < MANIFEST_TTL_MS) {
122
+ return manifestPromise;
123
+ }
124
+ manifestRequestedAt = Date.now();
125
+ manifestPromise = requestManifest().catch(function (e) {
126
+ // Never cache a rejection — a transient failure would otherwise stop every
127
+ // later loader in the session from retrying.
128
+ resetArtifactsManifestCache();
129
+ throw e;
130
+ });
131
+ return manifestPromise;
132
+ };
133
+
134
+ // ─── Public API ──────────────────────────────────────────────────────────────
135
+
136
+ /**
137
+ * Resolve the CDN URL for an artifact.
138
+ *
139
+ * :raises Error: when the manifest cannot be fetched or omits the artifact.
140
+ */
141
+ var getArtifactUrl = exports.getArtifactUrl = /*#__PURE__*/function () {
142
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(name) {
143
+ var _manifest$get;
144
+ var manifest, url;
145
+ return _regenerator.default.wrap(function (_context2) {
146
+ while (1) switch (_context2.prev = _context2.next) {
147
+ case 0:
148
+ _context2.next = 1;
149
+ return getManifest();
150
+ case 1:
151
+ manifest = _context2.sent;
152
+ url = (_manifest$get = manifest.get(name)) === null || _manifest$get === void 0 ? void 0 : _manifest$get.url;
153
+ if (url) {
154
+ _context2.next = 2;
155
+ break;
156
+ }
157
+ throw new Error("[autocomplete-artifacts] Manifest has no URL for \"".concat(name, "\""));
158
+ case 2:
159
+ return _context2.abrupt("return", url);
160
+ case 3:
161
+ case "end":
162
+ return _context2.stop();
163
+ }
164
+ }, _callee2);
165
+ }));
166
+ return function getArtifactUrl(_x) {
167
+ return _ref2.apply(this, arguments);
168
+ };
169
+ }();
170
+
171
+ /**
172
+ * Download and parse a JSON artifact. The presigned URL carries its own auth
173
+ * token, so the request is sent without Atlassian headers or credentials.
174
+ *
175
+ * :raises Error: when the manifest lookup or the download fails.
176
+ */
177
+ var fetchArtifactJson = exports.fetchArtifactJson = /*#__PURE__*/function () {
178
+ var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(name) {
179
+ var url, res;
180
+ return _regenerator.default.wrap(function (_context3) {
181
+ while (1) switch (_context3.prev = _context3.next) {
182
+ case 0:
183
+ _context3.next = 1;
184
+ return getArtifactUrl(name);
185
+ case 1:
186
+ url = _context3.sent;
187
+ _context3.next = 2;
188
+ return fetch(url);
189
+ case 2:
190
+ res = _context3.sent;
191
+ if (res.ok) {
192
+ _context3.next = 3;
193
+ break;
194
+ }
195
+ throw new Error("[autocomplete-artifacts] Failed to download \"".concat(name, "\": ").concat(res.status));
196
+ case 3:
197
+ _context3.next = 4;
198
+ return res.json();
199
+ case 4:
200
+ return _context3.abrupt("return", _context3.sent);
201
+ case 5:
202
+ case "end":
203
+ return _context3.stop();
204
+ }
205
+ }, _callee3);
206
+ }));
207
+ return function fetchArtifactJson(_x2) {
208
+ return _ref3.apply(this, arguments);
209
+ };
210
+ }();
@@ -16,6 +16,7 @@ var _view = require("@atlaskit/editor-prosemirror/view");
16
16
  var _debugMode = require("./debug-mode");
17
17
  var _ghostTextDecoration = require("./ghost-text-decoration");
18
18
  var _localSlowLaneClient = require("./local-slow-lane-client");
19
+ var _scoringPipeline = require("./scoring-pipeline");
19
20
  var _slowLaneClient = require("./slow-lane-client");
20
21
  var _textPredictor = require("./text-predictor");
21
22
  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; } } }; }
@@ -678,7 +679,7 @@ var createAutocompletePlugin = exports.createAutocompletePlugin = function creat
678
679
  return accepted;
679
680
  },
680
681
  focus: function focus() {
681
- var _options$useLocalMode, _options$useLocalMode2;
682
+ var _options$useLocalMode, _options$useLocalMode2, _options$useLocalMode3;
682
683
  if (!isAutocompleteEnabled) {
683
684
  return false;
684
685
  }
@@ -691,7 +692,6 @@ var createAutocompletePlugin = exports.createAutocompletePlugin = function creat
691
692
  });
692
693
  });
693
694
  (0, _textPredictor.loadVectorsAsync)({
694
- getBinaryUrl: options === null || options === void 0 ? void 0 : options.getVectorsBinaryUrl,
695
695
  isLocalLLM: (_options$useLocalMode2 = options === null || options === void 0 ? void 0 : options.useLocalModel) !== null && _options$useLocalMode2 !== void 0 ? _options$useLocalMode2 : false,
696
696
  surface: surface
697
697
  }).catch(function (error) {
@@ -699,6 +699,14 @@ var createAutocompletePlugin = exports.createAutocompletePlugin = function creat
699
699
  location: 'editor-plugin-autocomplete/loadVectorsAsync'
700
700
  });
701
701
  });
702
+ (0, _scoringPipeline.loadGrammarDataAsync)({
703
+ isLocalLLM: (_options$useLocalMode3 = options === null || options === void 0 ? void 0 : options.useLocalModel) !== null && _options$useLocalMode3 !== void 0 ? _options$useLocalMode3 : false,
704
+ surface: surface
705
+ }).catch(function (error) {
706
+ (0, _monitoring.logException)(error, {
707
+ location: 'editor-plugin-autocomplete/loadGrammarDataAsync'
708
+ });
709
+ });
702
710
  if (!hasIngestedPage) {
703
711
  hasIngestedPage = true;
704
712
  refreshContext({
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _typeof3 = require("@babel/runtime/helpers/typeof");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
@@ -10,16 +10,16 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
10
10
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
11
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
12
12
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
14
13
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
14
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
16
15
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
16
  var _ufo = require("../analytics/ufo");
17
+ var _artifactsManifest = require("./artifacts-manifest");
18
18
  var _debugMode = require("./debug-mode");
19
19
  var _slowLaneClient = require("./slow-lane-client");
20
20
  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; }
21
21
  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; }
22
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t6 in e) "default" !== _t6 && {}.hasOwnProperty.call(e, _t6) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t6)) && (i.get || i.set) ? o(f, _t6, i) : f[_t6] = e[_t6]); return f; })(e, t); }
22
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t6 in e) "default" !== _t6 && {}.hasOwnProperty.call(e, _t6) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t6)) && (i.get || i.set) ? o(f, _t6, i) : f[_t6] = e[_t6]); return f; })(e, t); }
23
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; } } }; }
24
24
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
25
25
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } /**
@@ -242,88 +242,9 @@ var prefixMapTokenIds = [];
242
242
  var bePayloadDataPromise;
243
243
 
244
244
  /**
245
- * Unwrap a dynamically imported JSON module to the parsed JSON value, working
246
- * across the two interop modes AFM's bundler chain emits:
247
- *
248
- * 1. **`.default`-wrapped namespace** — classic webpack (and Jest) hang the
249
- * JSON value under the `default` export.
250
- * 2. **Named-exports namespace** — webpack 5 / atlaspack with JSON
251
- * named-exports (or native ESM JSON modules) expose each top-level key as
252
- * a named export and shadow `default`, so `mod.default` can be `undefined`
253
- * (or some unrelated value) even though `mod` itself holds the data.
254
- *
255
- * The caller MUST declare the underlying JSON shape via `shape` because, in
256
- * named-exports mode, a dense array `["a","b"]` and a sparse numeric-keyed
257
- * object `{"5":"a","12":"b"}` are emitted identically (`{"0":..}` / `{"5":..}`);
258
- * no runtime heuristic can tell them apart, so only the caller knows which:
259
- *
260
- * - `'object'` — the JSON is a `{...}` (including sparse maps keyed by integer
261
- * IDs). The named exports are rebuilt into a plain object so `Object.entries`
262
- * yields the real keys, not synthetic array indices.
263
- * - `'array'` — the JSON is a `[...]`, reconstructed from the `0..n-1` indices.
264
- *
265
- * :param mod: The raw module object returned by `await import('./*.json')`.
266
- * :param shape: `'object'` if the source JSON is `{...}`, `'array'` if `[...]`.
267
- * :returns: The parsed JSON value, or `null` if neither interop mode applies.
268
- */
269
- function unwrapJsonModule(mod, shape) {
270
- if (mod == null || (0, _typeof2.default)(mod) !== 'object') {
271
- return null;
272
- }
273
- var namespace = mod;
274
-
275
- // Compute the named-export own-keys (strip synthetic markers).
276
- var ownKeys = Object.keys(namespace).filter(function (k) {
277
- return k !== 'default' && k !== '__esModule';
278
- });
279
-
280
- // PREFER named exports when present — they always reflect the JSON's real
281
- // top-level keys / indices, regardless of what `default` happens to be.
282
- // Under JSON named-exports mode `default` is not necessarily the parsed
283
- // value (e.g. for `{"service": 0, ...}` it can be the number `0`, with the
284
- // real data in the named exports), so taking `default` first would corrupt it.
285
- if (ownKeys.length > 0) {
286
- if (shape === 'array') {
287
- // JSON arrays are dense; reconstruct from `0..length-1` indices.
288
- var len = ownKeys.length;
289
- var arr = new Array(len);
290
- for (var i = 0; i < len; i++) {
291
- arr[i] = namespace[String(i)];
292
- }
293
- return arr;
294
- }
295
- // shape === 'object'. Rebuild a plain object from the (stripped) own
296
- // keys so callers can `Object.entries()` it without iterating over
297
- // `default` / `__esModule`, and to detach from the module-namespace
298
- // object (which is sealed/non-extensible on some bundler outputs).
299
- var obj = {};
300
- var _iterator = _createForOfIteratorHelper(ownKeys),
301
- _step;
302
- try {
303
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
304
- var k = _step.value;
305
- obj[k] = namespace[k];
306
- }
307
- } catch (err) {
308
- _iterator.e(err);
309
- } finally {
310
- _iterator.f();
311
- }
312
- return obj;
313
- }
314
-
315
- // Fallback: no named exports — classic webpack JSON-module interop where
316
- // the whole parsed JSON value is hung under `default`. Trust it.
317
- if ('default' in namespace && namespace.default != null) {
318
- return namespace.default;
319
- }
320
- return null;
321
- }
322
-
323
- /**
324
- * Lazily load and build the BE-parity lookup tables from their JSON payloads.
325
- * The dynamic imports are split into their own async chunks so neither file is
326
- * bundled into the editor's main chunk unless local inference is initialised.
245
+ * Lazily load and build the BE-parity lookup tables from their CDN payloads.
246
+ * Both artifacts are fetched on demand so neither is downloaded unless local
247
+ * inference is initialised.
327
248
  *
328
249
  * :returns:
329
250
  * A promise that resolves once `firstTokenToWords`, `l2Words` and
@@ -332,28 +253,22 @@ function unwrapJsonModule(mod, shape) {
332
253
  var loadBePayloadData = function loadBePayloadData() {
333
254
  if (!bePayloadDataPromise) {
334
255
  bePayloadDataPromise = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
335
- var _yield$Promise$all, _yield$Promise$all2, firstTokenToWordsModule, vocabularyModule, firstTokenToWordsData, vocabularyData;
256
+ var _yield$Promise$all, _yield$Promise$all2, firstTokenToWordsData, vocabularyData;
336
257
  return _regenerator.default.wrap(function (_context) {
337
258
  while (1) switch (_context.prev = _context.next) {
338
259
  case 0:
339
260
  _context.next = 1;
340
- return Promise.all([Promise.resolve().then(function () {
341
- return _interopRequireWildcard(require( /* webpackChunkName: "@atlaskit-internal_editor-plugin-autocomplete-first-token-to-words" */'./data/first_token_to_words.json'));
342
- }), Promise.resolve().then(function () {
343
- return _interopRequireWildcard(require( /* webpackChunkName: "@atlaskit-internal_editor-plugin-autocomplete-vocabulary-10k" */'./data/vocabulary_10k.json'));
344
- })]);
261
+ return Promise.all([(0, _artifactsManifest.fetchArtifactJson)(_artifactsManifest.ARTIFACT_NAME.FIRST_TOKEN_TO_WORDS), (0, _artifactsManifest.fetchArtifactJson)(_artifactsManifest.ARTIFACT_NAME.VOCABULARY)]);
345
262
  case 1:
346
263
  _yield$Promise$all = _context.sent;
347
264
  _yield$Promise$all2 = (0, _slicedToArray2.default)(_yield$Promise$all, 2);
348
- firstTokenToWordsModule = _yield$Promise$all2[0];
349
- vocabularyModule = _yield$Promise$all2[1];
350
- firstTokenToWordsData = unwrapJsonModule(firstTokenToWordsModule, 'object');
351
- vocabularyData = unwrapJsonModule(vocabularyModule, 'object');
265
+ firstTokenToWordsData = _yield$Promise$all2[0];
266
+ vocabularyData = _yield$Promise$all2[1];
352
267
  if (!(firstTokenToWordsData == null || (vocabularyData === null || vocabularyData === void 0 ? void 0 : vocabularyData.words) == null)) {
353
268
  _context.next = 2;
354
269
  break;
355
270
  }
356
- throw new Error("[LocalSlowLane] JSON module could not be unwrapped \u2014 " + "firstTokenToWordsData=".concat(firstTokenToWordsData == null ? 'null/undefined' : 'defined', ", ") + "vocabularyData=".concat(vocabularyData == null ? 'null/undefined' : vocabularyData.words == null ? 'defined but missing .words' : 'defined'));
271
+ throw new Error("[LocalSlowLane] unexpected artifact payload \u2014 " + "firstTokenToWordsData=".concat(firstTokenToWordsData == null ? 'null/undefined' : 'defined', ", ") + "vocabularyData=".concat(vocabularyData == null ? 'null/undefined' : vocabularyData.words == null ? 'defined but missing .words' : 'defined'));
357
272
  case 2:
358
273
  firstTokenToWords = new Map(Object.entries(firstTokenToWordsData).map(function (_ref2) {
359
274
  var _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
@@ -410,28 +325,28 @@ var computeBePayload = exports.computeBePayload = function computeBePayload(rawL
410
325
  var validTokenIds = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : prefixMapTokenIds;
411
326
  // 1. Numerically-stable masked softmax over validTokenIds only.
412
327
  var maxLogit = -Infinity;
413
- var _iterator2 = _createForOfIteratorHelper(validTokenIds),
414
- _step2;
328
+ var _iterator = _createForOfIteratorHelper(validTokenIds),
329
+ _step;
415
330
  try {
416
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
417
- var id = _step2.value;
331
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
332
+ var id = _step.value;
418
333
  var v = rawLogits[id];
419
334
  if (v > maxLogit) {
420
335
  maxLogit = v;
421
336
  }
422
337
  }
423
338
  } catch (err) {
424
- _iterator2.e(err);
339
+ _iterator.e(err);
425
340
  } finally {
426
- _iterator2.f();
341
+ _iterator.f();
427
342
  }
428
343
  var sumExp = 0;
429
344
  var expByToken = new Map();
430
- var _iterator3 = _createForOfIteratorHelper(validTokenIds),
431
- _step3;
345
+ var _iterator2 = _createForOfIteratorHelper(validTokenIds),
346
+ _step2;
432
347
  try {
433
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
434
- var _id = _step3.value;
348
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
349
+ var _id = _step2.value;
435
350
  var e = Math.exp(rawLogits[_id] - maxLogit);
436
351
  expByToken.set(_id, e);
437
352
  sumExp += e;
@@ -440,53 +355,53 @@ var computeBePayload = exports.computeBePayload = function computeBePayload(rawL
440
355
  // 2. Prefix expansion with max aggregation (probabilities sum to 1 over the
441
356
  // masked subset, so divide each token's exp by sumExp on the fly).
442
357
  } catch (err) {
443
- _iterator3.e(err);
358
+ _iterator2.e(err);
444
359
  } finally {
445
- _iterator3.f();
360
+ _iterator2.f();
446
361
  }
447
362
  var wordProbs = new Map();
448
- var _iterator4 = _createForOfIteratorHelper(prefixMap),
449
- _step4;
363
+ var _iterator3 = _createForOfIteratorHelper(prefixMap),
364
+ _step3;
450
365
  try {
451
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
366
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
452
367
  var _expByToken$get;
453
- var _step4$value = (0, _slicedToArray2.default)(_step4.value, 2),
454
- _id2 = _step4$value[0],
455
- words = _step4$value[1];
368
+ var _step3$value = (0, _slicedToArray2.default)(_step3.value, 2),
369
+ _id2 = _step3$value[0],
370
+ words = _step3$value[1];
456
371
  var _p = sumExp > 0 ? ((_expByToken$get = expByToken.get(_id2)) !== null && _expByToken$get !== void 0 ? _expByToken$get : 0) / sumExp : 0;
457
- var _iterator9 = _createForOfIteratorHelper(words),
458
- _step9;
372
+ var _iterator8 = _createForOfIteratorHelper(words),
373
+ _step8;
459
374
  try {
460
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
375
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
461
376
  var _wordProbs$get2;
462
- var _w = _step9.value;
377
+ var _w = _step8.value;
463
378
  var prev = (_wordProbs$get2 = wordProbs.get(_w)) !== null && _wordProbs$get2 !== void 0 ? _wordProbs$get2 : 0;
464
379
  if (_p > prev) {
465
380
  wordProbs.set(_w, _p);
466
381
  }
467
382
  }
468
383
  } catch (err) {
469
- _iterator9.e(err);
384
+ _iterator8.e(err);
470
385
  } finally {
471
- _iterator9.f();
386
+ _iterator8.f();
472
387
  }
473
388
  }
474
389
 
475
390
  // 3. Split into L2 / L3 and reserve the top L2 slots unconditionally.
476
391
  } catch (err) {
477
- _iterator4.e(err);
392
+ _iterator3.e(err);
478
393
  } finally {
479
- _iterator4.f();
394
+ _iterator3.f();
480
395
  }
481
396
  var l2Matches = [];
482
397
  var l3Matches = [];
483
- var _iterator5 = _createForOfIteratorHelper(wordProbs),
484
- _step5;
398
+ var _iterator4 = _createForOfIteratorHelper(wordProbs),
399
+ _step4;
485
400
  try {
486
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
487
- var _step5$value = (0, _slicedToArray2.default)(_step5.value, 2),
488
- _w2 = _step5$value[0],
489
- _p2 = _step5$value[1];
401
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
402
+ var _step4$value = (0, _slicedToArray2.default)(_step4.value, 2),
403
+ _w2 = _step4$value[0],
404
+ _p2 = _step4$value[1];
490
405
  if (domainWords.has(_w2)) {
491
406
  l2Matches.push([_w2, _p2]);
492
407
  } else {
@@ -494,9 +409,9 @@ var computeBePayload = exports.computeBePayload = function computeBePayload(rawL
494
409
  }
495
410
  }
496
411
  } catch (err) {
497
- _iterator5.e(err);
412
+ _iterator4.e(err);
498
413
  } finally {
499
- _iterator5.f();
414
+ _iterator4.f();
500
415
  }
501
416
  l2Matches.sort(function (a, b) {
502
417
  return b[1] - a[1];
@@ -509,19 +424,19 @@ var computeBePayload = exports.computeBePayload = function computeBePayload(rawL
509
424
  // it directly rather than allocating a Set and scanning every entry on this
510
425
  // hot path (runs ~every word boundary while typing).
511
426
  var pool = [];
512
- var _iterator6 = _createForOfIteratorHelper(l2Matches.slice(BE_PARITY.RESERVED_L2_SLOTS)),
513
- _step6;
427
+ var _iterator5 = _createForOfIteratorHelper(l2Matches.slice(BE_PARITY.RESERVED_L2_SLOTS)),
428
+ _step5;
514
429
  try {
515
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
516
- var _step6$value = (0, _slicedToArray2.default)(_step6.value, 2),
517
- _w3 = _step6$value[0],
518
- _p3 = _step6$value[1];
430
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
431
+ var _step5$value = (0, _slicedToArray2.default)(_step5.value, 2),
432
+ _w3 = _step5$value[0],
433
+ _p3 = _step5$value[1];
519
434
  pool.push([_w3, Math.log(Math.max(_p3, 1e-10)) + BE_PARITY.L2_BIAS]);
520
435
  }
521
436
  } catch (err) {
522
- _iterator6.e(err);
437
+ _iterator5.e(err);
523
438
  } finally {
524
- _iterator6.f();
439
+ _iterator5.f();
525
440
  }
526
441
  for (var _i = 0, _l3Matches = l3Matches; _i < _l3Matches.length; _i++) {
527
442
  var _l3Matches$_i = (0, _slicedToArray2.default)(_l3Matches[_i], 2),
@@ -554,33 +469,33 @@ var computeBePayload = exports.computeBePayload = function computeBePayload(rawL
554
469
  }
555
470
  result[key] = prob;
556
471
  };
557
- var _iterator7 = _createForOfIteratorHelper(reserved),
558
- _step7;
472
+ var _iterator6 = _createForOfIteratorHelper(reserved),
473
+ _step6;
559
474
  try {
560
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
561
- var _step7$value = (0, _slicedToArray2.default)(_step7.value, 2),
562
- _w4 = _step7$value[0],
563
- _p4 = _step7$value[1];
475
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
476
+ var _step6$value = (0, _slicedToArray2.default)(_step6.value, 2),
477
+ _w4 = _step6$value[0],
478
+ _p4 = _step6$value[1];
564
479
  addEntry(_w4, _p4, true);
565
480
  }
566
481
  } catch (err) {
567
- _iterator7.e(err);
482
+ _iterator6.e(err);
568
483
  } finally {
569
- _iterator7.f();
484
+ _iterator6.f();
570
485
  }
571
- var _iterator8 = _createForOfIteratorHelper(poolWinners),
572
- _step8;
486
+ var _iterator7 = _createForOfIteratorHelper(poolWinners),
487
+ _step7;
573
488
  try {
574
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
489
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
575
490
  var _wordProbs$get3;
576
- var _step8$value = (0, _slicedToArray2.default)(_step8.value, 1),
577
- _w5 = _step8$value[0];
491
+ var _step7$value = (0, _slicedToArray2.default)(_step7.value, 1),
492
+ _w5 = _step7$value[0];
578
493
  addEntry(_w5, (_wordProbs$get3 = wordProbs.get(_w5)) !== null && _wordProbs$get3 !== void 0 ? _wordProbs$get3 : 0, false);
579
494
  }
580
495
  } catch (err) {
581
- _iterator8.e(err);
496
+ _iterator7.e(err);
582
497
  } finally {
583
- _iterator8.f();
498
+ _iterator7.f();
584
499
  }
585
500
  if ((0, _debugMode.isAutocompleteDebugEnabled)()) {
586
501
  var topReserved = reserved.slice(0, 5).map(function (_ref4) {