@atlaskit/editor-plugin-autocomplete 8.0.0 → 9.1.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 (79) hide show
  1. package/CHANGELOG.md +108 -0
  2. package/dist/cjs/analytics/ufo.js +2 -1
  3. package/dist/cjs/pm-plugins/artifact-loader.js +135 -0
  4. package/dist/cjs/pm-plugins/artifacts-manifest.js +3 -0
  5. package/dist/cjs/pm-plugins/autocomplete-plugin.js +498 -160
  6. package/dist/cjs/pm-plugins/canonical-lm-scoring.js +371 -0
  7. package/dist/cjs/pm-plugins/debug-mode.js +105 -7
  8. package/dist/cjs/pm-plugins/ghost-text-decoration.js +12 -3
  9. package/dist/cjs/pm-plugins/local-slow-lane-client.js +1202 -453
  10. package/dist/cjs/pm-plugins/scoring-pipeline.js +164 -19
  11. package/dist/cjs/pm-plugins/slow-lane-client.js +100 -37
  12. package/dist/cjs/pm-plugins/text-predictor.js +2099 -309
  13. package/dist/es2019/analytics/ufo.js +2 -0
  14. package/dist/es2019/pm-plugins/artifact-loader.js +70 -0
  15. package/dist/es2019/pm-plugins/artifacts-manifest.js +3 -0
  16. package/dist/es2019/pm-plugins/autocomplete-plugin.js +489 -152
  17. package/dist/es2019/pm-plugins/canonical-lm-scoring.js +270 -0
  18. package/dist/es2019/pm-plugins/debug-mode.js +102 -7
  19. package/dist/es2019/pm-plugins/ghost-text-decoration.js +12 -3
  20. package/dist/es2019/pm-plugins/local-slow-lane-client.js +940 -326
  21. package/dist/es2019/pm-plugins/scoring-pipeline.js +137 -13
  22. package/dist/es2019/pm-plugins/slow-lane-client.js +94 -37
  23. package/dist/es2019/pm-plugins/text-predictor.js +1692 -200
  24. package/dist/esm/analytics/ufo.js +2 -1
  25. package/dist/esm/pm-plugins/artifact-loader.js +128 -0
  26. package/dist/esm/pm-plugins/artifacts-manifest.js +3 -0
  27. package/dist/esm/pm-plugins/autocomplete-plugin.js +501 -163
  28. package/dist/esm/pm-plugins/canonical-lm-scoring.js +364 -0
  29. package/dist/esm/pm-plugins/debug-mode.js +104 -6
  30. package/dist/esm/pm-plugins/ghost-text-decoration.js +12 -3
  31. package/dist/esm/pm-plugins/local-slow-lane-client.js +1200 -451
  32. package/dist/esm/pm-plugins/scoring-pipeline.js +163 -18
  33. package/dist/esm/pm-plugins/slow-lane-client.js +100 -37
  34. package/dist/esm/pm-plugins/text-predictor.js +2101 -313
  35. package/dist/types/analytics/ufo.d.ts +1 -0
  36. package/dist/types/pm-plugins/artifact-loader.d.ts +44 -0
  37. package/dist/types/pm-plugins/artifacts-manifest.d.ts +3 -0
  38. package/dist/types/pm-plugins/autocomplete-plugin.d.ts +39 -0
  39. package/dist/types/pm-plugins/canonical-lm-scoring.d.ts +158 -0
  40. package/dist/types/pm-plugins/debug-mode.d.ts +55 -1
  41. package/dist/types/pm-plugins/ghost-text-decoration.d.ts +5 -2
  42. package/dist/types/pm-plugins/local-slow-lane-client.d.ts +87 -54
  43. package/dist/types/pm-plugins/scoring-pipeline.d.ts +33 -1
  44. package/dist/types/pm-plugins/slow-lane-client.d.ts +51 -3
  45. package/dist/types/pm-plugins/text-predictor.d.ts +156 -3
  46. package/package.json +2 -2
  47. package/src/analytics/ufo.ts +5 -0
  48. package/src/pm-plugins/artifact-loader.ts +92 -0
  49. package/src/pm-plugins/artifacts-manifest.ts +3 -0
  50. package/src/pm-plugins/autocomplete-plugin.ts +584 -154
  51. package/src/pm-plugins/canonical-lm-scoring.ts +412 -0
  52. package/src/pm-plugins/debug-mode.ts +134 -7
  53. package/src/pm-plugins/ghost-text-decoration.ts +13 -4
  54. package/src/pm-plugins/local-slow-lane-client.ts +1302 -386
  55. package/src/pm-plugins/scoring-pipeline.ts +167 -17
  56. package/src/pm-plugins/slow-lane-client.ts +147 -62
  57. package/src/pm-plugins/text-predictor.ts +2119 -254
  58. package/CANONICAL_FIX__DO_NOT_USE_ME_A/package.json +0 -8
  59. package/CANONICAL_FIX__DO_NOT_USE_ME_B/package.json +0 -8
  60. package/CANONICAL_FIX__DO_NOT_USE_ME_C/package.json +0 -8
  61. package/dist/cjs/entry-points/src-pm-plugins-autocomplete-plugin.js +0 -18
  62. package/dist/cjs/entry-points/src-pm-plugins-slow-lane-client.js +0 -36
  63. package/dist/cjs/entry-points/src-pm-plugins-text-predictor.js +0 -66
  64. package/dist/es2019/entry-points/src-pm-plugins-autocomplete-plugin.js +0 -2
  65. package/dist/es2019/entry-points/src-pm-plugins-slow-lane-client.js +0 -2
  66. package/dist/es2019/entry-points/src-pm-plugins-text-predictor.js +0 -2
  67. package/dist/esm/entry-points/src-pm-plugins-autocomplete-plugin.js +0 -2
  68. package/dist/esm/entry-points/src-pm-plugins-slow-lane-client.js +0 -2
  69. package/dist/esm/entry-points/src-pm-plugins-text-predictor.js +0 -2
  70. package/dist/types/entry-points/src-pm-plugins-autocomplete-plugin.d.ts +0 -2
  71. package/dist/types/entry-points/src-pm-plugins-slow-lane-client.d.ts +0 -2
  72. package/dist/types/entry-points/src-pm-plugins-text-predictor.d.ts +0 -2
  73. package/scripts/gen_first_token_to_words.py +0 -170
  74. package/src/entry-points/src-pm-plugins-autocomplete-plugin.ts +0 -7
  75. package/src/entry-points/src-pm-plugins-slow-lane-client.ts +0 -13
  76. package/src/entry-points/src-pm-plugins-text-predictor.ts +0 -14
  77. package/src/pm-plugins/autocomplete-plugin/package.json +0 -8
  78. package/src/pm-plugins/slow-lane-client/package.json +0 -8
  79. package/src/pm-plugins/text-predictor/package.json +0 -8
@@ -35,6 +35,7 @@ export var EXPERIENCE_NAME = {
35
35
  SLOW_LANE_FETCH: 'slow-lane-fetch',
36
36
  LOAD_VOCABULARY: 'load-vocabulary',
37
37
  LOAD_VECTORS: 'load-vectors',
38
+ LOAD_PHRASES: 'load-phrases',
38
39
  LOAD_GRAMMAR: 'load-grammar'
39
40
  };
40
41
  var isUfoEnabled = function isUfoEnabled() {
@@ -53,7 +54,7 @@ var operationConfig = {
53
54
  })
54
55
  }
55
56
  };
56
- var experiences = _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, EXPERIENCE_NAME.SLOW_LANE_FETCH, new ConcurrentExperience(EXPERIENCE_NAME.SLOW_LANE_FETCH, operationConfig)), EXPERIENCE_NAME.LOAD_VOCABULARY, new ConcurrentExperience(EXPERIENCE_NAME.LOAD_VOCABULARY, operationConfig)), EXPERIENCE_NAME.LOAD_VECTORS, new ConcurrentExperience(EXPERIENCE_NAME.LOAD_VECTORS, operationConfig)), EXPERIENCE_NAME.LOAD_GRAMMAR, new ConcurrentExperience(EXPERIENCE_NAME.LOAD_GRAMMAR, operationConfig));
57
+ var experiences = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, EXPERIENCE_NAME.SLOW_LANE_FETCH, new ConcurrentExperience(EXPERIENCE_NAME.SLOW_LANE_FETCH, operationConfig)), EXPERIENCE_NAME.LOAD_VOCABULARY, new ConcurrentExperience(EXPERIENCE_NAME.LOAD_VOCABULARY, operationConfig)), EXPERIENCE_NAME.LOAD_VECTORS, new ConcurrentExperience(EXPERIENCE_NAME.LOAD_VECTORS, operationConfig)), EXPERIENCE_NAME.LOAD_PHRASES, new ConcurrentExperience(EXPERIENCE_NAME.LOAD_PHRASES, operationConfig)), EXPERIENCE_NAME.LOAD_GRAMMAR, new ConcurrentExperience(EXPERIENCE_NAME.LOAD_GRAMMAR, operationConfig));
57
58
  export var startExp = function startExp(name, id, metadata) {
58
59
  if (!isUfoEnabled()) {
59
60
  return;
@@ -0,0 +1,128 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
+ /**
4
+ * Validation and diagnostics layer over the artifacts manifest.
5
+ *
6
+ * `artifacts-manifest` owns *where* a payload comes from (one manifest request,
7
+ * then a presigned CDN download). This module owns *whether the payload is
8
+ * usable*: every loader declares the shape it expects, so a mis-published
9
+ * artifact fails at the boundary with the artifact's name rather than surfacing
10
+ * later as an empty trie or a silent no-op in scoring.
11
+ */
12
+
13
+ import { fetchArtifactJson, getArtifactUrl } from './artifacts-manifest';
14
+ import { ctcTag } from './debug-mode';
15
+ var TRAILING_SLASH_REGEX = /\/$/;
16
+ var DEFAULT_BASE_URL = '';
17
+ var AUTOCOMPLETE_GATEWAY_BASE = '/gateway/api/v1/autocomplete';
18
+ /**
19
+ * Build a URL for one of the autocomplete gateway's own endpoints (e.g. the
20
+ * network slow lane). Model artifacts do NOT go through here — they are served
21
+ * from the CDN via the manifest.
22
+ */
23
+ export var buildAutocompleteGatewayUrl = function buildAutocompleteGatewayUrl(path) {
24
+ var baseUrl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_BASE_URL;
25
+ var normalizedBase = baseUrl.replace(TRAILING_SLASH_REGEX, '');
26
+ return "".concat(normalizedBase).concat(AUTOCOMPLETE_GATEWAY_BASE).concat(path);
27
+ };
28
+
29
+ /**
30
+ * Download a JSON artifact and assert its shape before handing it to a loader.
31
+ *
32
+ * :params:
33
+ * artifactName: Manifest key for the artifact
34
+ * options.label: Name used in diagnostics; defaults to the manifest key
35
+ * options.summarize: Renders a short size/count summary for the debug log
36
+ * options.validate: Type guard the payload must satisfy
37
+ * :returns:
38
+ * The parsed, validated payload
39
+ */
40
+ export var fetchAutocompleteArtifactJson = /*#__PURE__*/function () {
41
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(artifactName) {
42
+ var _options$label, _options$summarize;
43
+ var options,
44
+ label,
45
+ payload,
46
+ summary,
47
+ _args = arguments;
48
+ return _regeneratorRuntime.wrap(function (_context) {
49
+ while (1) switch (_context.prev = _context.next) {
50
+ case 0:
51
+ options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
52
+ label = (_options$label = options.label) !== null && _options$label !== void 0 ? _options$label : artifactName; // Presigned CDN URLs carry an auth token, so only the artifact name is logged.
53
+ ctcTag('init', "\u2193 loading ".concat(label));
54
+ _context.next = 1;
55
+ return fetchArtifactJson(artifactName);
56
+ case 1:
57
+ payload = _context.sent;
58
+ if (!(options.validate && !options.validate(payload))) {
59
+ _context.next = 2;
60
+ break;
61
+ }
62
+ throw new Error("[autocomplete-artifacts] ".concat(label, " payload shape was invalid"));
63
+ case 2:
64
+ summary = (_options$summarize = options.summarize) === null || _options$summarize === void 0 ? void 0 : _options$summarize.call(options, payload);
65
+ ctcTag('init', "\u2713 loaded ".concat(label).concat(summary ? " (".concat(summary, ")") : ''));
66
+ return _context.abrupt("return", payload);
67
+ case 3:
68
+ case "end":
69
+ return _context.stop();
70
+ }
71
+ }, _callee);
72
+ }));
73
+ return function fetchAutocompleteArtifactJson(_x) {
74
+ return _ref.apply(this, arguments);
75
+ };
76
+ }();
77
+
78
+ /**
79
+ * Download a binary artifact (the word-vectors blob) as an ArrayBuffer.
80
+ *
81
+ * :params:
82
+ * artifactName: Manifest key for the artifact
83
+ * label: Name used in diagnostics; defaults to the manifest key
84
+ * :returns:
85
+ * The raw bytes of the artifact
86
+ */
87
+ export var fetchAutocompleteArtifactBinary = /*#__PURE__*/function () {
88
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(artifactName) {
89
+ var label,
90
+ url,
91
+ response,
92
+ payload,
93
+ _args2 = arguments;
94
+ return _regeneratorRuntime.wrap(function (_context2) {
95
+ while (1) switch (_context2.prev = _context2.next) {
96
+ case 0:
97
+ label = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : artifactName;
98
+ ctcTag('init', "\u2193 loading ".concat(label));
99
+ _context2.next = 1;
100
+ return getArtifactUrl(artifactName);
101
+ case 1:
102
+ url = _context2.sent;
103
+ _context2.next = 2;
104
+ return fetch(url);
105
+ case 2:
106
+ response = _context2.sent;
107
+ if (response.ok) {
108
+ _context2.next = 3;
109
+ break;
110
+ }
111
+ throw new Error("[autocomplete-artifacts] Failed to fetch ".concat(label, ": ").concat(response.status));
112
+ case 3:
113
+ _context2.next = 4;
114
+ return response.arrayBuffer();
115
+ case 4:
116
+ payload = _context2.sent;
117
+ ctcTag('init', "\u2713 loaded ".concat(label, " (").concat(payload.byteLength, " bytes)"));
118
+ return _context2.abrupt("return", payload);
119
+ case 5:
120
+ case "end":
121
+ return _context2.stop();
122
+ }
123
+ }, _callee2);
124
+ }));
125
+ return function fetchAutocompleteArtifactBinary(_x2) {
126
+ return _ref2.apply(this, arguments);
127
+ };
128
+ }();
@@ -22,10 +22,13 @@ import { isAutocompleteDebugEnabled } from './debug-mode';
22
22
  * hyphenated, unlike the underscored filenames the artifacts are generated from.
23
23
  */
24
24
  export var ARTIFACT_NAME = {
25
+ BIGRAMS: 'bigrams.json',
25
26
  FIRST_TOKEN_TO_WORDS: 'first-token-to-words.json',
26
27
  GHOST_POS_TAGS: 'ghost-pos-tags.json',
27
28
  GRAMMAR_TRANSITIONS: 'grammar-transitions-10k.json',
28
29
  L3_VOCABULARY: 'l3-vocabulary.json',
30
+ PHRASE_CONTINUATION_TOKENS: 'phrase-continuation-tokens.json',
31
+ PHRASES: 'phrases.json',
29
32
  POS_TAGS: 'combined-l2-l3-pos-tags.json',
30
33
  VOCABULARY: 'vocabulary-10k.json',
31
34
  WORD_INDEX: 'word-index-10k.json',