@atlaskit/editor-plugin-autocomplete 5.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.
- package/CHANGELOG.md +20 -0
- package/build/tsconfig.json +2 -1
- package/dist/cjs/analytics/ufo.js +3 -2
- package/dist/cjs/pm-plugins/artifacts-manifest.js +210 -0
- package/dist/cjs/pm-plugins/autocomplete-plugin.js +10 -2
- package/dist/cjs/pm-plugins/local-slow-lane-client.js +68 -153
- package/dist/cjs/pm-plugins/scoring-pipeline.js +130 -28
- package/dist/cjs/pm-plugins/text-predictor.js +45 -106
- package/dist/es2019/analytics/ufo.js +4 -2
- package/dist/es2019/pm-plugins/artifacts-manifest.js +126 -0
- package/dist/es2019/pm-plugins/autocomplete-plugin.js +10 -2
- package/dist/es2019/pm-plugins/local-slow-lane-client.js +8 -78
- package/dist/es2019/pm-plugins/scoring-pipeline.js +97 -21
- package/dist/es2019/pm-plugins/text-predictor.js +17 -59
- package/dist/esm/analytics/ufo.js +3 -2
- package/dist/esm/pm-plugins/artifacts-manifest.js +204 -0
- package/dist/esm/pm-plugins/autocomplete-plugin.js +10 -2
- package/dist/esm/pm-plugins/local-slow-lane-client.js +67 -148
- package/dist/esm/pm-plugins/scoring-pipeline.js +128 -26
- package/dist/esm/pm-plugins/text-predictor.js +45 -98
- package/dist/types/analytics/ufo.d.ts +1 -0
- package/dist/types/pm-plugins/artifacts-manifest.d.ts +55 -0
- package/dist/types/pm-plugins/autocomplete-plugin.d.ts +5 -11
- package/dist/types/pm-plugins/scoring-pipeline.d.ts +14 -0
- package/dist/types/pm-plugins/text-predictor.d.ts +0 -1
- package/package.json +3 -6
- package/src/analytics/ufo.ts +5 -0
- package/src/pm-plugins/artifacts-manifest.ts +151 -0
- package/src/pm-plugins/autocomplete-plugin.ts +14 -12
- package/src/pm-plugins/local-slow-lane-client.ts +10 -92
- package/src/pm-plugins/scoring-pipeline.ts +115 -23
- package/src/pm-plugins/text-predictor.ts +26 -76
- package/tsconfig.json +3 -6
- package/dist/cjs/pm-plugins/data/combined_l2_l3_pos_tags.json +0 -73571
- package/dist/cjs/pm-plugins/data/first_token_to_words.json +0 -1
- package/dist/cjs/pm-plugins/data/ghost_pos_tags.json +0 -43
- package/dist/cjs/pm-plugins/data/grammar_transitions_10k.json +0 -46
- package/dist/cjs/pm-plugins/data/l3_vocabulary.json +0 -20002
- package/dist/cjs/pm-plugins/data/vocabulary_10k.json +0 -38794
- package/dist/cjs/pm-plugins/data/word_index_10k.json +0 -7762
- package/dist/es2019/pm-plugins/data/combined_l2_l3_pos_tags.json +0 -73571
- package/dist/es2019/pm-plugins/data/first_token_to_words.json +0 -1
- package/dist/es2019/pm-plugins/data/ghost_pos_tags.json +0 -43
- package/dist/es2019/pm-plugins/data/grammar_transitions_10k.json +0 -46
- package/dist/es2019/pm-plugins/data/l3_vocabulary.json +0 -20002
- package/dist/es2019/pm-plugins/data/vocabulary_10k.json +0 -38794
- package/dist/es2019/pm-plugins/data/word_index_10k.json +0 -7762
- package/dist/esm/pm-plugins/data/combined_l2_l3_pos_tags.json +0 -73571
- package/dist/esm/pm-plugins/data/first_token_to_words.json +0 -1
- package/dist/esm/pm-plugins/data/ghost_pos_tags.json +0 -43
- package/dist/esm/pm-plugins/data/grammar_transitions_10k.json +0 -46
- package/dist/esm/pm-plugins/data/l3_vocabulary.json +0 -20002
- package/dist/esm/pm-plugins/data/vocabulary_10k.json +0 -38794
- package/dist/esm/pm-plugins/data/word_index_10k.json +0 -7762
- package/src/pm-plugins/data/combined_l2_l3_pos_tags.json +0 -73571
- package/src/pm-plugins/data/first_token_to_words.json +0 -1
- package/src/pm-plugins/data/ghost_pos_tags.json +0 -43
- package/src/pm-plugins/data/grammar_transitions_10k.json +0 -46
- package/src/pm-plugins/data/l3_vocabulary.json +0 -20002
- package/src/pm-plugins/data/vocabulary_10k.json +0 -38794
- package/src/pm-plugins/data/word-vectors_10k.bin +0 -3
- package/src/pm-plugins/data/word_index_10k.json +0 -7762
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var
|
|
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" !=
|
|
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
|
-
*
|
|
246
|
-
*
|
|
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,
|
|
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([
|
|
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
|
-
|
|
349
|
-
|
|
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]
|
|
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
|
|
414
|
-
|
|
328
|
+
var _iterator = _createForOfIteratorHelper(validTokenIds),
|
|
329
|
+
_step;
|
|
415
330
|
try {
|
|
416
|
-
for (
|
|
417
|
-
var id =
|
|
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
|
-
|
|
339
|
+
_iterator.e(err);
|
|
425
340
|
} finally {
|
|
426
|
-
|
|
341
|
+
_iterator.f();
|
|
427
342
|
}
|
|
428
343
|
var sumExp = 0;
|
|
429
344
|
var expByToken = new Map();
|
|
430
|
-
var
|
|
431
|
-
|
|
345
|
+
var _iterator2 = _createForOfIteratorHelper(validTokenIds),
|
|
346
|
+
_step2;
|
|
432
347
|
try {
|
|
433
|
-
for (
|
|
434
|
-
var _id =
|
|
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
|
-
|
|
358
|
+
_iterator2.e(err);
|
|
444
359
|
} finally {
|
|
445
|
-
|
|
360
|
+
_iterator2.f();
|
|
446
361
|
}
|
|
447
362
|
var wordProbs = new Map();
|
|
448
|
-
var
|
|
449
|
-
|
|
363
|
+
var _iterator3 = _createForOfIteratorHelper(prefixMap),
|
|
364
|
+
_step3;
|
|
450
365
|
try {
|
|
451
|
-
for (
|
|
366
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
452
367
|
var _expByToken$get;
|
|
453
|
-
var
|
|
454
|
-
_id2 =
|
|
455
|
-
words =
|
|
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
|
|
458
|
-
|
|
372
|
+
var _iterator8 = _createForOfIteratorHelper(words),
|
|
373
|
+
_step8;
|
|
459
374
|
try {
|
|
460
|
-
for (
|
|
375
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
461
376
|
var _wordProbs$get2;
|
|
462
|
-
var _w =
|
|
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
|
-
|
|
384
|
+
_iterator8.e(err);
|
|
470
385
|
} finally {
|
|
471
|
-
|
|
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
|
-
|
|
392
|
+
_iterator3.e(err);
|
|
478
393
|
} finally {
|
|
479
|
-
|
|
394
|
+
_iterator3.f();
|
|
480
395
|
}
|
|
481
396
|
var l2Matches = [];
|
|
482
397
|
var l3Matches = [];
|
|
483
|
-
var
|
|
484
|
-
|
|
398
|
+
var _iterator4 = _createForOfIteratorHelper(wordProbs),
|
|
399
|
+
_step4;
|
|
485
400
|
try {
|
|
486
|
-
for (
|
|
487
|
-
var
|
|
488
|
-
_w2 =
|
|
489
|
-
_p2 =
|
|
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
|
-
|
|
412
|
+
_iterator4.e(err);
|
|
498
413
|
} finally {
|
|
499
|
-
|
|
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
|
|
513
|
-
|
|
427
|
+
var _iterator5 = _createForOfIteratorHelper(l2Matches.slice(BE_PARITY.RESERVED_L2_SLOTS)),
|
|
428
|
+
_step5;
|
|
514
429
|
try {
|
|
515
|
-
for (
|
|
516
|
-
var
|
|
517
|
-
_w3 =
|
|
518
|
-
_p3 =
|
|
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
|
-
|
|
437
|
+
_iterator5.e(err);
|
|
523
438
|
} finally {
|
|
524
|
-
|
|
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
|
|
558
|
-
|
|
472
|
+
var _iterator6 = _createForOfIteratorHelper(reserved),
|
|
473
|
+
_step6;
|
|
559
474
|
try {
|
|
560
|
-
for (
|
|
561
|
-
var
|
|
562
|
-
_w4 =
|
|
563
|
-
_p4 =
|
|
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
|
-
|
|
482
|
+
_iterator6.e(err);
|
|
568
483
|
} finally {
|
|
569
|
-
|
|
484
|
+
_iterator6.f();
|
|
570
485
|
}
|
|
571
|
-
var
|
|
572
|
-
|
|
486
|
+
var _iterator7 = _createForOfIteratorHelper(poolWinners),
|
|
487
|
+
_step7;
|
|
573
488
|
try {
|
|
574
|
-
for (
|
|
489
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
575
490
|
var _wordProbs$get3;
|
|
576
|
-
var
|
|
577
|
-
_w5 =
|
|
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
|
-
|
|
496
|
+
_iterator7.e(err);
|
|
582
497
|
} finally {
|
|
583
|
-
|
|
498
|
+
_iterator7.f();
|
|
584
499
|
}
|
|
585
500
|
if ((0, _debugMode.isAutocompleteDebugEnabled)()) {
|
|
586
501
|
var topReserved = reserved.slice(0, 5).map(function (_ref4) {
|
|
@@ -4,19 +4,27 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.STAGE2_WEIGHT = exports.STAGE1_WEIGHT = exports.MIN_STAGE1_SCORE = void 0;
|
|
7
|
+
exports.loadGrammarDataAsync = exports.isGrammarDataLoaded = exports.STAGE2_WEIGHT = exports.STAGE1_WEIGHT = exports.MIN_STAGE1_SCORE = void 0;
|
|
8
8
|
exports.rankCandidates = rankCandidates;
|
|
9
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
9
12
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
+
var _ufo = require("../analytics/ufo");
|
|
14
|
+
var _artifactsManifest = require("./artifacts-manifest");
|
|
15
|
+
var _debugMode = require("./debug-mode");
|
|
13
16
|
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; } } }; }
|
|
14
17
|
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; } }
|
|
15
|
-
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; }
|
|
18
|
+
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; }
|
|
19
|
+
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; }
|
|
20
|
+
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; } /**
|
|
16
21
|
* Scoring Pipeline: Stage 1 (Semantic + Frequency), Grammar Filter, Stage 2 (LM Re-ranking).
|
|
17
22
|
*
|
|
18
23
|
* Operates synchronously on pre-loaded data. Each stage gracefully degrades
|
|
19
24
|
* when its required data isn't available (cold → warm → full warm).
|
|
25
|
+
*
|
|
26
|
+
* The grammar/POS payloads are fetched from the CDN by loadGrammarDataAsync, so
|
|
27
|
+
* the grammar filter is a pass-through until that resolves.
|
|
20
28
|
*/
|
|
21
29
|
// ─── Types ──────────────────────────────────────────────────
|
|
22
30
|
|
|
@@ -37,22 +45,119 @@ var L1_SESSION_CAP = 1.2;
|
|
|
37
45
|
// at 0.00024) from triggering re-ranking.
|
|
38
46
|
var LM_GATE_THRESHOLD = 0.0005;
|
|
39
47
|
|
|
40
|
-
// ─── Grammar Data (
|
|
48
|
+
// ─── Grammar Data (fetched once from the CDN) ────────────────
|
|
49
|
+
|
|
50
|
+
var posTags = new Map();
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* GHOST POS DICTIONARY
|
|
54
|
+
* A mapping of common structural English words that were stripped from the main
|
|
55
|
+
* domain vocabulary. This allows the grammar filter to understand context
|
|
56
|
+
* without suggesting these words to the user.
|
|
57
|
+
*/
|
|
58
|
+
var ghostPosTags = {};
|
|
41
59
|
|
|
42
|
-
|
|
43
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Precomputed map from each POS tag to the set of allowed next POS tags, so
|
|
62
|
+
* applyGrammarFilter never re-iterates the transition rules per call.
|
|
63
|
+
*/
|
|
64
|
+
var precomputedAllowedByPos = new Map();
|
|
65
|
+
var grammarDataPromise;
|
|
66
|
+
var setGrammarData = function setGrammarData(data) {
|
|
67
|
+
var _data$grammarTransiti;
|
|
68
|
+
posTags = new Map(Object.entries(data.posTags));
|
|
69
|
+
ghostPosTags = data.ghostPosTags;
|
|
70
|
+
precomputedAllowedByPos = new Map(Object.entries((_data$grammarTransiti = data.grammarTransitions.transitions) !== null && _data$grammarTransiti !== void 0 ? _data$grammarTransiti : {}).map(function (_ref) {
|
|
71
|
+
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
72
|
+
pos = _ref2[0],
|
|
73
|
+
rule = _ref2[1];
|
|
74
|
+
return [pos, new Set(rule.allowed)];
|
|
75
|
+
}));
|
|
76
|
+
};
|
|
77
|
+
var isGrammarDataLoaded = exports.isGrammarDataLoaded = function isGrammarDataLoaded() {
|
|
78
|
+
return precomputedAllowedByPos.size > 0;
|
|
79
|
+
};
|
|
44
80
|
|
|
45
81
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
82
|
+
* Fetch the POS tag and grammar transition payloads from the CDN.
|
|
83
|
+
*
|
|
84
|
+
* Safe to call repeatedly: the in-flight promise is shared, and a failure is not
|
|
85
|
+
* cached so a later call can retry.
|
|
49
86
|
*/
|
|
50
|
-
var
|
|
51
|
-
var
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
87
|
+
var loadGrammarDataAsync = exports.loadGrammarDataAsync = function loadGrammarDataAsync(options) {
|
|
88
|
+
var _options$isLocalLLM;
|
|
89
|
+
if (grammarDataPromise) {
|
|
90
|
+
return grammarDataPromise;
|
|
91
|
+
}
|
|
92
|
+
var isLocalLLM = (_options$isLocalLLM = options === null || options === void 0 ? void 0 : options.isLocalLLM) !== null && _options$isLocalLLM !== void 0 ? _options$isLocalLLM : false;
|
|
93
|
+
var surface = options === null || options === void 0 ? void 0 : options.surface;
|
|
94
|
+
grammarDataPromise = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
95
|
+
var _yield$Promise$all, _yield$Promise$all2, posTagsData, ghostPosTagsData, grammarTransitionsData, _t;
|
|
96
|
+
return _regenerator.default.wrap(function (_context) {
|
|
97
|
+
while (1) switch (_context.prev = _context.next) {
|
|
98
|
+
case 0:
|
|
99
|
+
(0, _ufo.startExp)(_ufo.EXPERIENCE_NAME.LOAD_GRAMMAR, 'singleton', _objectSpread({
|
|
100
|
+
isLocalLLM: isLocalLLM
|
|
101
|
+
}, surface ? {
|
|
102
|
+
surface: surface
|
|
103
|
+
} : {}));
|
|
104
|
+
_context.prev = 1;
|
|
105
|
+
_context.next = 2;
|
|
106
|
+
return Promise.all([(0, _artifactsManifest.fetchArtifactJson)(_artifactsManifest.ARTIFACT_NAME.POS_TAGS), (0, _artifactsManifest.fetchArtifactJson)(_artifactsManifest.ARTIFACT_NAME.GHOST_POS_TAGS), (0, _artifactsManifest.fetchArtifactJson)(_artifactsManifest.ARTIFACT_NAME.GRAMMAR_TRANSITIONS)]);
|
|
107
|
+
case 2:
|
|
108
|
+
_yield$Promise$all = _context.sent;
|
|
109
|
+
_yield$Promise$all2 = (0, _slicedToArray2.default)(_yield$Promise$all, 3);
|
|
110
|
+
posTagsData = _yield$Promise$all2[0];
|
|
111
|
+
ghostPosTagsData = _yield$Promise$all2[1];
|
|
112
|
+
grammarTransitionsData = _yield$Promise$all2[2];
|
|
113
|
+
if (!((grammarTransitionsData === null || grammarTransitionsData === void 0 ? void 0 : grammarTransitionsData.transitions) == null)) {
|
|
114
|
+
_context.next = 3;
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
throw new Error("[scoring-pipeline] ".concat(_artifactsManifest.ARTIFACT_NAME.GRAMMAR_TRANSITIONS, " is missing its `transitions` wrapper"));
|
|
118
|
+
case 3:
|
|
119
|
+
setGrammarData({
|
|
120
|
+
posTags: posTagsData !== null && posTagsData !== void 0 ? posTagsData : {},
|
|
121
|
+
ghostPosTags: ghostPosTagsData !== null && ghostPosTagsData !== void 0 ? ghostPosTagsData : {},
|
|
122
|
+
grammarTransitions: grammarTransitionsData
|
|
123
|
+
});
|
|
124
|
+
(0, _ufo.succeedExp)(_ufo.EXPERIENCE_NAME.LOAD_GRAMMAR, 'singleton', _objectSpread({
|
|
125
|
+
isLocalLLM: isLocalLLM,
|
|
126
|
+
posTagCount: posTags.size,
|
|
127
|
+
transitionCount: precomputedAllowedByPos.size
|
|
128
|
+
}, surface ? {
|
|
129
|
+
surface: surface
|
|
130
|
+
} : {}));
|
|
131
|
+
if ((0, _debugMode.isAutocompleteDebugEnabled)()) {
|
|
132
|
+
// eslint-disable-next-line no-console
|
|
133
|
+
console.log('[scoring-pipeline] Grammar data loaded:', {
|
|
134
|
+
posTagCount: posTags.size,
|
|
135
|
+
ghostPosTagCount: Object.keys(ghostPosTags).length,
|
|
136
|
+
transitionCount: precomputedAllowedByPos.size
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
_context.next = 5;
|
|
140
|
+
break;
|
|
141
|
+
case 4:
|
|
142
|
+
_context.prev = 4;
|
|
143
|
+
_t = _context["catch"](1);
|
|
144
|
+
(0, _ufo.failExp)(_ufo.EXPERIENCE_NAME.LOAD_GRAMMAR, 'singleton', _objectSpread({
|
|
145
|
+
isLocalLLM: isLocalLLM,
|
|
146
|
+
errorType: 'network'
|
|
147
|
+
}, surface ? {
|
|
148
|
+
surface: surface
|
|
149
|
+
} : {}));
|
|
150
|
+
// Allow a later call to retry the load rather than caching the failure.
|
|
151
|
+
grammarDataPromise = undefined;
|
|
152
|
+
throw _t;
|
|
153
|
+
case 5:
|
|
154
|
+
case "end":
|
|
155
|
+
return _context.stop();
|
|
156
|
+
}
|
|
157
|
+
}, _callee, null, [[1, 4]]);
|
|
158
|
+
}))();
|
|
159
|
+
return grammarDataPromise;
|
|
160
|
+
};
|
|
56
161
|
|
|
57
162
|
// ─── Math ───────────────────────────────────────────────────
|
|
58
163
|
|
|
@@ -101,18 +206,15 @@ function scoreStage1(candidate, contextVector, getWordVector, maxTenantFreq) {
|
|
|
101
206
|
|
|
102
207
|
// ─── Grammar Filter ─────────────────────────────────────────
|
|
103
208
|
|
|
104
|
-
/**
|
|
105
|
-
* GHOST POS DICTIONARY
|
|
106
|
-
* A hardcoded mapping of common structural English words that were stripped
|
|
107
|
-
* from the main domain vocabulary. This allows the grammar filter to understand
|
|
108
|
-
* context without suggesting these words to the user.
|
|
109
|
-
*/
|
|
110
|
-
var ghostPosTags = _ghost_pos_tags.default;
|
|
111
209
|
function applyGrammarFilter(candidates, previousWord) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
210
|
+
// Pass everything through until loadGrammarDataAsync resolves — filtering on a
|
|
211
|
+
// partially loaded ruleset would drop valid candidates.
|
|
212
|
+
if (!previousWord || !isGrammarDataLoaded()) {
|
|
213
|
+
return {
|
|
214
|
+
filtered: candidates,
|
|
215
|
+
grammarMeta: null
|
|
216
|
+
};
|
|
217
|
+
}
|
|
116
218
|
var lowerPrev = previousWord.toLowerCase();
|
|
117
219
|
var prevTags = ghostPosTags[lowerPrev] || posTags.get(lowerPrev);
|
|
118
220
|
if (!prevTags || prevTags.length === 0) {
|