@atlaskit/editor-plugin-autocomplete 0.1.0 → 0.3.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 (58) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/afm-cc/tsconfig.json +2 -1
  3. package/afm-jira/tsconfig.json +2 -1
  4. package/afm-products/tsconfig.json +2 -1
  5. package/build/tsconfig.json +20 -0
  6. package/build/url-module.d.ts +8 -0
  7. package/dist/cjs/autocompletePlugin.js +18 -5
  8. package/dist/cjs/autocompletePluginType.js +5 -1
  9. package/dist/cjs/pm-plugins/autocomplete-plugin.js +368 -0
  10. package/dist/cjs/pm-plugins/ghost-text-decoration.js +39 -0
  11. package/dist/cjs/pm-plugins/scoring-pipeline.js +256 -0
  12. package/dist/cjs/pm-plugins/slow-lane-client.js +199 -0
  13. package/dist/cjs/pm-plugins/text-predictor.js +796 -0
  14. package/dist/es2019/autocompletePlugin.js +20 -6
  15. package/dist/es2019/autocompletePluginType.js +1 -0
  16. package/dist/es2019/pm-plugins/autocomplete-plugin.js +368 -0
  17. package/dist/es2019/pm-plugins/ghost-text-decoration.js +33 -0
  18. package/dist/es2019/pm-plugins/scoring-pipeline.js +221 -0
  19. package/dist/es2019/pm-plugins/slow-lane-client.js +157 -0
  20. package/dist/es2019/pm-plugins/text-predictor.js +631 -0
  21. package/dist/esm/autocompletePlugin.js +18 -5
  22. package/dist/esm/autocompletePluginType.js +1 -0
  23. package/dist/esm/pm-plugins/autocomplete-plugin.js +362 -0
  24. package/dist/esm/pm-plugins/ghost-text-decoration.js +33 -0
  25. package/dist/esm/pm-plugins/scoring-pipeline.js +252 -0
  26. package/dist/esm/pm-plugins/slow-lane-client.js +192 -0
  27. package/dist/esm/pm-plugins/text-predictor.js +793 -0
  28. package/dist/types/autocompletePluginType.d.ts +6 -3
  29. package/dist/types/pm-plugins/autocomplete-plugin.d.ts +36 -0
  30. package/dist/types/pm-plugins/ghost-text-decoration.d.ts +7 -0
  31. package/dist/types/pm-plugins/scoring-pipeline.d.ts +33 -0
  32. package/dist/types/pm-plugins/slow-lane-client.d.ts +46 -0
  33. package/dist/types/pm-plugins/text-predictor.d.ts +90 -0
  34. package/dist/types-ts4.5/autocompletePluginType.d.ts +6 -3
  35. package/dist/types-ts4.5/pm-plugins/autocomplete-plugin.d.ts +36 -0
  36. package/dist/types-ts4.5/pm-plugins/ghost-text-decoration.d.ts +7 -0
  37. package/dist/types-ts4.5/pm-plugins/scoring-pipeline.d.ts +33 -0
  38. package/dist/types-ts4.5/pm-plugins/slow-lane-client.d.ts +46 -0
  39. package/dist/types-ts4.5/pm-plugins/text-predictor.d.ts +90 -0
  40. package/package.json +2 -2
  41. package/src/autocompletePlugin.tsx +25 -5
  42. package/src/autocompletePluginType.ts +14 -3
  43. package/src/pm-plugins/autocomplete-plugin/package.json +15 -0
  44. package/src/pm-plugins/autocomplete-plugin.ts +443 -0
  45. package/src/pm-plugins/data/combined_l2_l3_pos_tags.json +73571 -3
  46. package/src/pm-plugins/data/ghost_pos_tags.json +43 -3
  47. package/src/pm-plugins/data/grammar_transitions_10k.json +46 -3
  48. package/src/pm-plugins/data/l3_vocabulary.json +20002 -3
  49. package/src/pm-plugins/data/vocabulary_10k.json +38794 -3
  50. package/src/pm-plugins/data/word_index_10k.json +7760 -3
  51. package/src/pm-plugins/ghost-text-decoration.ts +44 -0
  52. package/src/pm-plugins/scoring-pipeline.ts +294 -0
  53. package/src/pm-plugins/slow-lane-client/package.json +15 -0
  54. package/src/pm-plugins/slow-lane-client.ts +222 -0
  55. package/src/pm-plugins/text-predictor/package.json +15 -0
  56. package/src/pm-plugins/text-predictor.ts +780 -0
  57. package/tsconfig.app.json +12 -3
  58. package/tsconfig.json +4 -1
@@ -0,0 +1,192 @@
1
+ import _typeof from "@babel/runtime/helpers/typeof";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
4
+ /**
5
+ * Slow Lane Client: Backend context encoding for autocomplete.
6
+ *
7
+ * Fires a BE request on word boundaries to encode document context.
8
+ * Expects the typeahead-encodings API format:
9
+ * Request: { text, session_id }
10
+ * Response: { semantic_vector: number[], lm_logits: Record<string, number> }
11
+ */
12
+
13
+ // ─── Types ───────────────────────────────────────────────────────────────────
14
+
15
+ /** Request payload for typeahead-encodings endpoint. */
16
+
17
+ /** Response from typeahead-encodings endpoint. */
18
+
19
+ // ─── Constants ───────────────────────────────────────────────────────────────
20
+
21
+ // eslint-disable-next-line require-unicode-regexp
22
+ var WORD_BOUNDARY_CHARS = /[\s.,;:!?]/;
23
+ var DEFAULT_DEBOUNCE_MS = 300;
24
+
25
+ /**
26
+ * Check if text ends with a word boundary character (space or punctuation).
27
+ */
28
+ export var isWordBoundary = function isWordBoundary(text) {
29
+ if (!text || text.length === 0) {
30
+ return false;
31
+ }
32
+ var lastChar = text[text.length - 1];
33
+ return WORD_BOUNDARY_CHARS.test(lastChar);
34
+ };
35
+
36
+ // ─── Slow Lane Client ────────────────────────────────────────────────────────
37
+
38
+ export var createSlowLaneClient = function createSlowLaneClient(config) {
39
+ var baseUrl = config.baseUrl,
40
+ configSessionId = config.sessionId,
41
+ _config$productKey = config.productKey,
42
+ productKey = _config$productKey === void 0 ? 'confluence' : _config$productKey,
43
+ _config$endpoint = config.endpoint,
44
+ endpoint = _config$endpoint === void 0 ? '/gateway/api/v1/autocomplete/typeahead-encodings' : _config$endpoint,
45
+ _config$debounceMs = config.debounceMs,
46
+ debounceMs = _config$debounceMs === void 0 ? DEFAULT_DEBOUNCE_MS : _config$debounceMs,
47
+ _config$fetchFn = config.fetchFn,
48
+ fetchFn = _config$fetchFn === void 0 ? fetch : _config$fetchFn,
49
+ onUpdate = config.onUpdate;
50
+ var sessionId = configSessionId !== null && configSessionId !== void 0 ? configSessionId : crypto.randomUUID();
51
+ var headers = {
52
+ 'Content-Type': 'application/json',
53
+ 'x-experience-id': 'confluence-smart-typeahead-encodings',
54
+ 'x-product': productKey
55
+ };
56
+ var debounceTimer = null;
57
+ var lastRequestedText = '';
58
+ var storedContextVector = null;
59
+ var storedLmLogits = null;
60
+ var doUpdateContext = /*#__PURE__*/function () {
61
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(text) {
62
+ var url, payload, res, data;
63
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
64
+ while (1) switch (_context.prev = _context.next) {
65
+ case 0:
66
+ if (!(!text || text.trim().length === 0)) {
67
+ _context.next = 2;
68
+ break;
69
+ }
70
+ return _context.abrupt("return");
71
+ case 2:
72
+ // eslint-disable-next-line require-unicode-regexp
73
+ url = "".concat(baseUrl.replace(/\/$/, '')).concat(endpoint);
74
+ payload = {
75
+ text: text,
76
+ session_id: sessionId
77
+ }; // Log the exact payload being sent so the comment/reply structure is visible
78
+ // eslint-disable-next-line no-console
79
+ console.groupCollapsed("%c[SlowLane] %c\uD83D\uDCE4 Sending context | ".concat(text.length, " chars"), 'color: #9c27b0; font-weight: bold;', 'color: inherit;');
80
+ text.split('\n').forEach(function (line, i, arr) {
81
+ // eslint-disable-next-line no-console
82
+ console.log(" ".concat(i === arr.length - 1 ? '▶' : ' ', " ").concat(line));
83
+ });
84
+ // eslint-disable-next-line no-console
85
+ console.groupEnd();
86
+ _context.prev = 7;
87
+ _context.next = 10;
88
+ return fetchFn(url, {
89
+ method: 'POST',
90
+ headers: headers,
91
+ body: JSON.stringify(payload)
92
+ });
93
+ case 10:
94
+ res = _context.sent;
95
+ if (res.ok) {
96
+ _context.next = 16;
97
+ break;
98
+ }
99
+ storedContextVector = null;
100
+ storedLmLogits = null;
101
+ // eslint-disable-next-line no-console
102
+ console.log("%c[SlowLane] %c\u274C Request failed (".concat(res.status, ")"), 'color: #9c27b0; font-weight: bold;', 'color: #f44336;');
103
+ return _context.abrupt("return");
104
+ case 16:
105
+ _context.next = 18;
106
+ return res.json();
107
+ case 18:
108
+ data = _context.sent;
109
+ if (data.semantic_vector && Array.isArray(data.semantic_vector)) {
110
+ storedContextVector = new Float32Array(data.semantic_vector);
111
+ } else {
112
+ storedContextVector = null;
113
+ }
114
+ if (data.lm_logits && _typeof(data.lm_logits) === 'object') {
115
+ storedLmLogits = data.lm_logits;
116
+ } else {
117
+ storedLmLogits = null;
118
+ }
119
+
120
+ // Log what came back so it can be correlated with the next prediction group
121
+ // eslint-disable-next-line no-console
122
+ console.groupCollapsed("%c[SlowLane] %c\uD83D\uDCE5 Response received", 'color: #9c27b0; font-weight: bold;', 'color: inherit;');
123
+ // eslint-disable-next-line no-console
124
+ console.log(storedContextVector ? "\u2705 semantic_vector: ".concat(storedContextVector.length, " dims") : '❌ No semantic_vector');
125
+ // eslint-disable-next-line no-console
126
+ console.log(storedLmLogits ? "\u2705 lm_logits: ".concat(Object.keys(storedLmLogits).length, " tokens") : '❌ No lm_logits');
127
+ // eslint-disable-next-line no-console
128
+ console.groupEnd();
129
+ onUpdate === null || onUpdate === void 0 || onUpdate({
130
+ textLength: text.length,
131
+ hasVector: storedContextVector !== null,
132
+ hasLmLogits: storedLmLogits !== null
133
+ });
134
+ // eslint-disable-next-line no-unused-vars
135
+ _context.next = 33;
136
+ break;
137
+ case 28:
138
+ _context.prev = 28;
139
+ _context.t0 = _context["catch"](7);
140
+ storedContextVector = null;
141
+ storedLmLogits = null;
142
+ // eslint-disable-next-line no-console
143
+ console.log('%c[SlowLane] %c❌ Network error — context cleared', 'color: #9c27b0; font-weight: bold;', 'color: #f44336;');
144
+ case 33:
145
+ case "end":
146
+ return _context.stop();
147
+ }
148
+ }, _callee, null, [[7, 28]]);
149
+ }));
150
+ return function doUpdateContext(_x) {
151
+ return _ref.apply(this, arguments);
152
+ };
153
+ }();
154
+ var updateContextDebounced = function updateContextDebounced(text) {
155
+ if (debounceTimer) {
156
+ clearTimeout(debounceTimer);
157
+ }
158
+ lastRequestedText = text;
159
+ debounceTimer = setTimeout(function () {
160
+ debounceTimer = null;
161
+ doUpdateContext(lastRequestedText);
162
+ }, debounceMs);
163
+ };
164
+ return {
165
+ updateContext: updateContextDebounced,
166
+ getContextVector: function getContextVector() {
167
+ return storedContextVector;
168
+ },
169
+ getLmLogits: function getLmLogits() {
170
+ return storedLmLogits;
171
+ },
172
+ setContextVector: function setContextVector(vector) {
173
+ storedContextVector = vector;
174
+ },
175
+ setLmLogits: function setLmLogits(logits) {
176
+ storedLmLogits = logits;
177
+ },
178
+ isWordBoundary: isWordBoundary
179
+ };
180
+ };
181
+ var defaultSlowLaneClient = null;
182
+ export var setDefaultSlowLaneClient = function setDefaultSlowLaneClient(client) {
183
+ defaultSlowLaneClient = client;
184
+ };
185
+ export var getStoredContextVector = function getStoredContextVector() {
186
+ var _defaultSlowLaneClien, _defaultSlowLaneClien2;
187
+ return (_defaultSlowLaneClien = (_defaultSlowLaneClien2 = defaultSlowLaneClient) === null || _defaultSlowLaneClien2 === void 0 ? void 0 : _defaultSlowLaneClien2.getContextVector()) !== null && _defaultSlowLaneClien !== void 0 ? _defaultSlowLaneClien : null;
188
+ };
189
+ export var getStoredLmLogits = function getStoredLmLogits() {
190
+ var _defaultSlowLaneClien3, _defaultSlowLaneClien4;
191
+ return (_defaultSlowLaneClien3 = (_defaultSlowLaneClien4 = defaultSlowLaneClient) === null || _defaultSlowLaneClien4 === void 0 ? void 0 : _defaultSlowLaneClien4.getLmLogits()) !== null && _defaultSlowLaneClien3 !== void 0 ? _defaultSlowLaneClien3 : null;
192
+ };