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