@atlaskit/editor-plugin-autocomplete 2.2.0 → 2.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.
- package/CHANGELOG.md +11 -0
- package/afm-cc/tsconfig.json +0 -1
- package/afm-products/tsconfig.json +0 -1
- package/build/tsconfig.json +0 -1
- package/dist/cjs/pm-plugins/autocomplete-plugin.js +41 -14
- package/dist/cjs/pm-plugins/debug-mode.js +24 -0
- package/dist/cjs/pm-plugins/slow-lane-client.js +42 -35
- package/dist/cjs/pm-plugins/text-predictor.js +12 -32
- package/dist/es2019/pm-plugins/autocomplete-plugin.js +41 -14
- package/dist/es2019/pm-plugins/debug-mode.js +18 -0
- package/dist/es2019/pm-plugins/slow-lane-client.js +29 -23
- package/dist/es2019/pm-plugins/text-predictor.js +6 -26
- package/dist/esm/pm-plugins/autocomplete-plugin.js +41 -14
- package/dist/esm/pm-plugins/debug-mode.js +18 -0
- package/dist/esm/pm-plugins/slow-lane-client.js +43 -35
- package/dist/esm/pm-plugins/text-predictor.js +11 -31
- package/dist/types/pm-plugins/autocomplete-plugin.d.ts +1 -1
- package/dist/types/pm-plugins/debug-mode.d.ts +12 -0
- package/dist/types/pm-plugins/text-predictor.d.ts +0 -2
- package/dist/types-ts4.5/pm-plugins/autocomplete-plugin.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/debug-mode.d.ts +12 -0
- package/dist/types-ts4.5/pm-plugins/text-predictor.d.ts +0 -2
- package/package.json +2 -2
- package/src/pm-plugins/autocomplete-plugin.ts +48 -12
- package/src/pm-plugins/debug-mode.ts +18 -0
- package/src/pm-plugins/slow-lane-client.ts +53 -45
- package/src/pm-plugins/text-predictor.ts +6 -30
- package/tsconfig.app.json +3 -1
- package/tsconfig.dev.json +2 -1
- package/afm-jira/tsconfig.json +0 -30
|
@@ -21,6 +21,7 @@ import l3VocabularyData from './data/l3_vocabulary.json';
|
|
|
21
21
|
import vocabularyData from './data/vocabulary_10k.json';
|
|
22
22
|
import wordIndexData from './data/word_index_10k.json';
|
|
23
23
|
// import { rankCandidates, isGrammarAllowed } from './scoring-pipeline';
|
|
24
|
+
import { isAutocompleteDebugEnabled } from './debug-mode';
|
|
24
25
|
import { rankCandidates, STAGE1_WEIGHT, STAGE2_WEIGHT, MIN_STAGE1_SCORE } from './scoring-pipeline';
|
|
25
26
|
import { getStoredContextVector, getStoredLmLogits } from './slow-lane-client';
|
|
26
27
|
|
|
@@ -161,7 +162,7 @@ export const initL3Vocabulary = l3Words => {
|
|
|
161
162
|
// loses to any domain word in Stage 1, but still scores above 0.
|
|
162
163
|
l3Trie.insert(word, L3_BASELINE_FREQ, 0, 0);
|
|
163
164
|
}
|
|
164
|
-
if (
|
|
165
|
+
if (isAutocompleteDebugEnabled()) {
|
|
165
166
|
// eslint-disable-next-line no-console
|
|
166
167
|
console.log(`[text-predictor] L3 General English loaded: ${l3Words.length} words`);
|
|
167
168
|
}
|
|
@@ -174,9 +175,7 @@ export const initL3Vocabulary = l3Words => {
|
|
|
174
175
|
let isInitialized = false;
|
|
175
176
|
let vectorStore = null;
|
|
176
177
|
let vectorsLoadStarted = false;
|
|
177
|
-
let debugMode = true;
|
|
178
178
|
let lastPredictionDebug = null;
|
|
179
|
-
let hasLoggedSemanticActive = false;
|
|
180
179
|
|
|
181
180
|
/** Get vector for a word from the store. */
|
|
182
181
|
const getWordVector = word => {
|
|
@@ -263,25 +262,12 @@ const extractPreviousWord = text => {
|
|
|
263
262
|
|
|
264
263
|
// ─── Debug Helpers ───────────────────────────────────────────────────────────
|
|
265
264
|
|
|
266
|
-
/** Enable or disable debug logging. Also checks localStorage key `autocomplete-debug`. */
|
|
267
|
-
export const setDebugMode = enabled => {
|
|
268
|
-
debugMode = enabled;
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
/** Check localStorage for autocomplete-debug on first access. */
|
|
272
|
-
const ensureDebugModeFromStorage = () => {
|
|
273
|
-
if (typeof localStorage !== 'undefined' && localStorage.getItem('autocomplete-debug') === '1') {
|
|
274
|
-
debugMode = true;
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
|
|
278
265
|
/**
|
|
279
266
|
* Get predictor status for debugging.
|
|
280
267
|
* vectorsLoaded: true when semantic scoring is active
|
|
281
268
|
* wordCount: number of words in vector store (0 if not loaded)
|
|
282
269
|
*/
|
|
283
270
|
export const getPredictorStatus = () => {
|
|
284
|
-
ensureDebugModeFromStorage();
|
|
285
271
|
return {
|
|
286
272
|
vectorsLoaded: vectorStore !== null,
|
|
287
273
|
wordCount: vectorStore ? Object.keys(vectorStore.wordIndex).length : 0,
|
|
@@ -295,7 +281,6 @@ export const getPredictorStatus = () => {
|
|
|
295
281
|
* Returns null if no prediction has run yet or debug was off.
|
|
296
282
|
*/
|
|
297
283
|
export const getLastPredictionDebug = () => {
|
|
298
|
-
ensureDebugModeFromStorage();
|
|
299
284
|
return lastPredictionDebug;
|
|
300
285
|
};
|
|
301
286
|
export const initVocabulary = vocabulary => {
|
|
@@ -336,7 +321,7 @@ export const ingestDocumentPage = pageContent => {
|
|
|
336
321
|
validBoostedWords.add(word);
|
|
337
322
|
}
|
|
338
323
|
}
|
|
339
|
-
if (
|
|
324
|
+
if (isAutocompleteDebugEnabled() && validBoostedWords.size > 0) {
|
|
340
325
|
// eslint-disable-next-line no-console
|
|
341
326
|
console.groupCollapsed(`%c[L1 Session] %cPrimed ${validBoostedWords.size} valid dictionary words from page`, 'color: #00b8d9; font-weight: bold;', 'color: inherit; font-style: italic;');
|
|
342
327
|
// eslint-disable-next-line no-console
|
|
@@ -346,7 +331,6 @@ export const ingestDocumentPage = pageContent => {
|
|
|
346
331
|
}
|
|
347
332
|
};
|
|
348
333
|
export const predict = textBefore => {
|
|
349
|
-
ensureDebugModeFromStorage();
|
|
350
334
|
if (!isInitialized) {
|
|
351
335
|
loadDefaultVocabulary();
|
|
352
336
|
}
|
|
@@ -428,7 +412,7 @@ export const predict = textBefore => {
|
|
|
428
412
|
const lmLogits = getStoredLmLogits();
|
|
429
413
|
|
|
430
414
|
// Raw LM Output Logger
|
|
431
|
-
if (
|
|
415
|
+
if (isAutocompleteDebugEnabled() && lmLogits && Object.keys(lmLogits).length > 0) {
|
|
432
416
|
const rawLmTop = Object.entries(lmLogits).sort((a, b) => b[1] - a[1]).slice(0, 5).map(([word, score]) => ({
|
|
433
417
|
Word: word,
|
|
434
418
|
Prob: Number(score.toFixed(5))
|
|
@@ -437,9 +421,6 @@ export const predict = textBefore => {
|
|
|
437
421
|
console.log('%c[Raw LM Prediction]🧠', 'color: #e83e8c; font-weight: bold;', rawLmTop);
|
|
438
422
|
}
|
|
439
423
|
const mode = contextVector ? 'warm' : 'cold';
|
|
440
|
-
if (debugMode && contextVector && !hasLoggedSemanticActive) {
|
|
441
|
-
hasLoggedSemanticActive = true;
|
|
442
|
-
}
|
|
443
424
|
|
|
444
425
|
// Build ScoringCandidate array from TrieNodes
|
|
445
426
|
const scoringCandidates = candidates.map(({
|
|
@@ -464,7 +445,7 @@ export const predict = textBefore => {
|
|
|
464
445
|
} = rankCandidates(scoringCandidates, contextVector, w => getWordVector(w), prefixLmLogits, wordTrie.maxTenantFreq, previousWord);
|
|
465
446
|
const best = ranked[0];
|
|
466
447
|
const suggestion = best && best.finalScore >= MIN_SCORE_THRESHOLD ? best.word.slice(currentWord.length) : null;
|
|
467
|
-
if (
|
|
448
|
+
if (isAutocompleteDebugEnabled()) {
|
|
468
449
|
const latencyMs = performance.now() - t0;
|
|
469
450
|
const tokens = tokenize(trimmed);
|
|
470
451
|
const contextWords = tokens.slice(-CONTEXT_WORDS);
|
|
@@ -612,8 +593,7 @@ export const loadVectorsAsync = async options => {
|
|
|
612
593
|
wordIndex,
|
|
613
594
|
dim
|
|
614
595
|
};
|
|
615
|
-
|
|
616
|
-
if (debugMode) {
|
|
596
|
+
if (isAutocompleteDebugEnabled()) {
|
|
617
597
|
// eslint-disable-next-line no-console
|
|
618
598
|
console.log('[text-predictor] Vectors loaded:', {
|
|
619
599
|
wordCount: nWords,
|
|
@@ -141,6 +141,16 @@ var buildSlowLaneText = function buildSlowLaneText(docText, context) {
|
|
|
141
141
|
lines.push("reply ".concat(nextReplyNumber, ": ").concat(docText));
|
|
142
142
|
return lines.join('\n');
|
|
143
143
|
};
|
|
144
|
+
var getTypedLengthForPrediction = function getTypedLengthForPrediction(textBefore) {
|
|
145
|
+
var _textBefore$match$, _textBefore$match;
|
|
146
|
+
if (isWordBoundary(textBefore)) {
|
|
147
|
+
return 0;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
151
|
+
var trailingToken = (_textBefore$match$ = (_textBefore$match = textBefore.match(/([^\s.,;:!?]*)$/)) === null || _textBefore$match === void 0 ? void 0 : _textBefore$match[1]) !== null && _textBefore$match$ !== void 0 ? _textBefore$match$ : '';
|
|
152
|
+
return trailingToken.length;
|
|
153
|
+
};
|
|
144
154
|
export var createAutocompletePlugin = function createAutocompletePlugin(options, api) {
|
|
145
155
|
var debounceTimer = null;
|
|
146
156
|
var hasIngestedPage = false;
|
|
@@ -158,6 +168,24 @@ export var createAutocompletePlugin = function createAutocompletePlugin(options,
|
|
|
158
168
|
* re-showing the same suggestion. Resets to null as soon as the text changes.
|
|
159
169
|
*/
|
|
160
170
|
var dismissedContext = null;
|
|
171
|
+
var lastSuggestionTypedLength = 0;
|
|
172
|
+
var lastSuggestionLength = 0;
|
|
173
|
+
var fireSuggestionInsertedAnalytics = function fireSuggestionInsertedAnalytics(ghostText) {
|
|
174
|
+
var _api$analytics;
|
|
175
|
+
var typedLength = lastSuggestionTypedLength;
|
|
176
|
+
var suggestionLength = lastSuggestionLength || typedLength + ghostText.length;
|
|
177
|
+
var kssDelta = suggestionLength - typedLength;
|
|
178
|
+
api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
|
|
179
|
+
action: ACTION.SUGGESTION_INSERTED,
|
|
180
|
+
actionSubject: ACTION_SUBJECT.CONTEXTUAL_TYPEAHEAD,
|
|
181
|
+
eventType: EVENT_TYPE.TRACK,
|
|
182
|
+
attributes: {
|
|
183
|
+
suggestionLength: suggestionLength,
|
|
184
|
+
typedLength: typedLength,
|
|
185
|
+
kssDelta: kssDelta
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
};
|
|
161
189
|
var slowLaneClient = createSlowLaneClient({
|
|
162
190
|
baseUrl: '',
|
|
163
191
|
endpoint: SLOW_LANE_ENDPOINT
|
|
@@ -198,11 +226,14 @@ export var createAutocompletePlugin = function createAutocompletePlugin(options,
|
|
|
198
226
|
// Tier 1 prediction is synchronous -- no async needed
|
|
199
227
|
var prediction = predict(textBefore);
|
|
200
228
|
if (prediction && prediction.length > 0) {
|
|
229
|
+
var typedLength = getTypedLengthForPrediction(textBefore);
|
|
230
|
+
lastSuggestionTypedLength = typedLength;
|
|
231
|
+
lastSuggestionLength = typedLength + prediction.length;
|
|
201
232
|
showGhostText(view, prediction, selection.from);
|
|
202
233
|
if (prediction !== lastShownGhostText) {
|
|
203
|
-
var _api$
|
|
234
|
+
var _api$analytics2;
|
|
204
235
|
lastShownGhostText = prediction;
|
|
205
|
-
api === null || api === void 0 || (_api$
|
|
236
|
+
api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || _api$analytics2.actions.fireAnalyticsEvent({
|
|
206
237
|
action: ACTION.SUGGESTION_VIEWED,
|
|
207
238
|
actionSubject: ACTION_SUBJECT.CONTEXTUAL_TYPEAHEAD,
|
|
208
239
|
eventType: EVENT_TYPE.TRACK
|
|
@@ -278,30 +309,26 @@ export var createAutocompletePlugin = function createAutocompletePlugin(options,
|
|
|
278
309
|
},
|
|
279
310
|
handleKeyDown: keydownHandler({
|
|
280
311
|
Tab: function Tab(state, dispatch) {
|
|
312
|
+
var _pluginState$ghostTex;
|
|
313
|
+
var pluginState = autocompletePluginKey.getState(state);
|
|
314
|
+
var ghostText = (_pluginState$ghostTex = pluginState === null || pluginState === void 0 ? void 0 : pluginState.ghostText) !== null && _pluginState$ghostTex !== void 0 ? _pluginState$ghostTex : '';
|
|
281
315
|
var accepted = acceptGhostText(state, dispatch);
|
|
282
316
|
if (accepted) {
|
|
283
|
-
var _api$analytics2;
|
|
284
317
|
justAccepted = true;
|
|
285
318
|
lastShownGhostText = '';
|
|
286
|
-
|
|
287
|
-
action: ACTION.SUGGESTION_INSERTED,
|
|
288
|
-
actionSubject: ACTION_SUBJECT.CONTEXTUAL_TYPEAHEAD,
|
|
289
|
-
eventType: EVENT_TYPE.TRACK
|
|
290
|
-
});
|
|
319
|
+
fireSuggestionInsertedAnalytics(ghostText);
|
|
291
320
|
}
|
|
292
321
|
return accepted;
|
|
293
322
|
},
|
|
294
323
|
ArrowRight: function ArrowRight(state, dispatch) {
|
|
324
|
+
var _pluginState$ghostTex2;
|
|
325
|
+
var pluginState = autocompletePluginKey.getState(state);
|
|
326
|
+
var ghostText = (_pluginState$ghostTex2 = pluginState === null || pluginState === void 0 ? void 0 : pluginState.ghostText) !== null && _pluginState$ghostTex2 !== void 0 ? _pluginState$ghostTex2 : '';
|
|
295
327
|
var accepted = acceptGhostText(state, dispatch);
|
|
296
328
|
if (accepted) {
|
|
297
|
-
var _api$analytics3;
|
|
298
329
|
justAccepted = true;
|
|
299
330
|
lastShownGhostText = '';
|
|
300
|
-
|
|
301
|
-
action: ACTION.SUGGESTION_INSERTED,
|
|
302
|
-
actionSubject: ACTION_SUBJECT.CONTEXTUAL_TYPEAHEAD,
|
|
303
|
-
eventType: EVENT_TYPE.TRACK
|
|
304
|
-
});
|
|
331
|
+
fireSuggestionInsertedAnalytics(ghostText);
|
|
305
332
|
}
|
|
306
333
|
return accepted;
|
|
307
334
|
},
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contextual Typeahead Completions (CTC) debug logging utility.
|
|
3
|
+
*
|
|
4
|
+
* Logs are silent by default. To enable in any environment (dev, staging, prod):
|
|
5
|
+
*
|
|
6
|
+
* localStorage.setItem('atl-ctc-dbg', '1')
|
|
7
|
+
*
|
|
8
|
+
* Then reload the page. To disable:
|
|
9
|
+
*
|
|
10
|
+
* localStorage.removeItem('atl-ctc-dbg')
|
|
11
|
+
*/
|
|
12
|
+
export var isAutocompleteDebugEnabled = function isAutocompleteDebugEnabled() {
|
|
13
|
+
try {
|
|
14
|
+
return typeof localStorage !== 'undefined' && localStorage.getItem('atl-ctc-dbg') === '1';
|
|
15
|
+
} catch (_unused) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
@@ -10,6 +10,8 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
|
10
10
|
* Response: { semantic_vector: number[], lm_logits: Record<string, number> }
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
import { isAutocompleteDebugEnabled } from './debug-mode';
|
|
14
|
+
|
|
13
15
|
// ─── Types ───────────────────────────────────────────────────────────────────
|
|
14
16
|
|
|
15
17
|
/** Request payload for typeahead-encodings endpoint. */
|
|
@@ -74,37 +76,41 @@ export var createSlowLaneClient = function createSlowLaneClient(config) {
|
|
|
74
76
|
payload = {
|
|
75
77
|
text: text,
|
|
76
78
|
session_id: sessionId
|
|
77
|
-
};
|
|
78
|
-
|
|
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) {
|
|
79
|
+
};
|
|
80
|
+
if (isAutocompleteDebugEnabled()) {
|
|
81
81
|
// eslint-disable-next-line no-console
|
|
82
|
-
console.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
82
|
+
console.groupCollapsed("%c[SlowLane] %c\uD83D\uDCE4 Sending context | ".concat(text.length, " chars"), 'color: #9c27b0; font-weight: bold;', 'color: inherit;');
|
|
83
|
+
text.split('\n').forEach(function (line, i, arr) {
|
|
84
|
+
// eslint-disable-next-line no-console
|
|
85
|
+
console.log(" ".concat(i === arr.length - 1 ? '▶' : ' ', " ").concat(line));
|
|
86
|
+
});
|
|
87
|
+
// eslint-disable-next-line no-console
|
|
88
|
+
console.groupEnd();
|
|
89
|
+
}
|
|
90
|
+
_context.prev = 5;
|
|
91
|
+
_context.next = 8;
|
|
88
92
|
return fetchFn(url, {
|
|
89
93
|
method: 'POST',
|
|
90
94
|
headers: headers,
|
|
91
95
|
body: JSON.stringify(payload)
|
|
92
96
|
});
|
|
93
|
-
case
|
|
97
|
+
case 8:
|
|
94
98
|
res = _context.sent;
|
|
95
99
|
if (res.ok) {
|
|
96
|
-
_context.next =
|
|
100
|
+
_context.next = 14;
|
|
97
101
|
break;
|
|
98
102
|
}
|
|
99
103
|
storedContextVector = null;
|
|
100
104
|
storedLmLogits = null;
|
|
101
|
-
|
|
102
|
-
|
|
105
|
+
if (isAutocompleteDebugEnabled()) {
|
|
106
|
+
// eslint-disable-next-line no-console
|
|
107
|
+
console.log("%c[SlowLane] %c\u274C Request failed (".concat(res.status, ")"), 'color: #9c27b0; font-weight: bold;', 'color: #f44336;');
|
|
108
|
+
}
|
|
103
109
|
return _context.abrupt("return");
|
|
104
|
-
case
|
|
105
|
-
_context.next =
|
|
110
|
+
case 14:
|
|
111
|
+
_context.next = 16;
|
|
106
112
|
return res.json();
|
|
107
|
-
case
|
|
113
|
+
case 16:
|
|
108
114
|
data = _context.sent;
|
|
109
115
|
if (data.semantic_vector && Array.isArray(data.semantic_vector)) {
|
|
110
116
|
storedContextVector = new Float32Array(data.semantic_vector);
|
|
@@ -116,36 +122,38 @@ export var createSlowLaneClient = function createSlowLaneClient(config) {
|
|
|
116
122
|
} else {
|
|
117
123
|
storedLmLogits = null;
|
|
118
124
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
if (isAutocompleteDebugEnabled()) {
|
|
126
|
+
// eslint-disable-next-line no-console
|
|
127
|
+
console.groupCollapsed("%c[SlowLane] %c\uD83D\uDCE5 Response received", 'color: #9c27b0; font-weight: bold;', 'color: inherit;');
|
|
128
|
+
// eslint-disable-next-line no-console
|
|
129
|
+
console.log(storedContextVector ? "\u2705 semantic_vector: ".concat(storedContextVector.length, " dims") : '❌ No semantic_vector');
|
|
130
|
+
// eslint-disable-next-line no-console
|
|
131
|
+
console.log(storedLmLogits ? "\u2705 lm_logits: ".concat(Object.keys(storedLmLogits).length, " tokens") : '❌ No lm_logits');
|
|
132
|
+
// eslint-disable-next-line no-console
|
|
133
|
+
console.groupEnd();
|
|
134
|
+
}
|
|
129
135
|
onUpdate === null || onUpdate === void 0 || onUpdate({
|
|
130
136
|
textLength: text.length,
|
|
131
137
|
hasVector: storedContextVector !== null,
|
|
132
138
|
hasLmLogits: storedLmLogits !== null
|
|
133
139
|
});
|
|
134
140
|
// eslint-disable-next-line no-unused-vars
|
|
135
|
-
_context.next =
|
|
141
|
+
_context.next = 28;
|
|
136
142
|
break;
|
|
137
|
-
case
|
|
138
|
-
_context.prev =
|
|
139
|
-
_context.t0 = _context["catch"](
|
|
143
|
+
case 23:
|
|
144
|
+
_context.prev = 23;
|
|
145
|
+
_context.t0 = _context["catch"](5);
|
|
140
146
|
storedContextVector = null;
|
|
141
147
|
storedLmLogits = null;
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
148
|
+
if (isAutocompleteDebugEnabled()) {
|
|
149
|
+
// eslint-disable-next-line no-console
|
|
150
|
+
console.log('%c[SlowLane] %c❌ Network error — context cleared', 'color: #9c27b0; font-weight: bold;', 'color: #f44336;');
|
|
151
|
+
}
|
|
152
|
+
case 28:
|
|
145
153
|
case "end":
|
|
146
154
|
return _context.stop();
|
|
147
155
|
}
|
|
148
|
-
}, _callee, null, [[
|
|
156
|
+
}, _callee, null, [[5, 23]]);
|
|
149
157
|
}));
|
|
150
158
|
return function doUpdateContext(_x) {
|
|
151
159
|
return _ref.apply(this, arguments);
|
|
@@ -29,6 +29,7 @@ import l3VocabularyData from './data/l3_vocabulary.json';
|
|
|
29
29
|
import vocabularyData from './data/vocabulary_10k.json';
|
|
30
30
|
import wordIndexData from './data/word_index_10k.json';
|
|
31
31
|
// import { rankCandidates, isGrammarAllowed } from './scoring-pipeline';
|
|
32
|
+
import { isAutocompleteDebugEnabled } from './debug-mode';
|
|
32
33
|
import { rankCandidates, STAGE1_WEIGHT, STAGE2_WEIGHT, MIN_STAGE1_SCORE } from './scoring-pipeline';
|
|
33
34
|
import { getStoredContextVector, getStoredLmLogits } from './slow-lane-client';
|
|
34
35
|
|
|
@@ -223,7 +224,7 @@ export var initL3Vocabulary = function initL3Vocabulary(l3Words) {
|
|
|
223
224
|
} finally {
|
|
224
225
|
_iterator5.f();
|
|
225
226
|
}
|
|
226
|
-
if (
|
|
227
|
+
if (isAutocompleteDebugEnabled()) {
|
|
227
228
|
// eslint-disable-next-line no-console
|
|
228
229
|
console.log("[text-predictor] L3 General English loaded: ".concat(l3Words.length, " words"));
|
|
229
230
|
}
|
|
@@ -236,9 +237,7 @@ export var initL3Vocabulary = function initL3Vocabulary(l3Words) {
|
|
|
236
237
|
var isInitialized = false;
|
|
237
238
|
var vectorStore = null;
|
|
238
239
|
var vectorsLoadStarted = false;
|
|
239
|
-
var debugMode = true;
|
|
240
240
|
var lastPredictionDebug = null;
|
|
241
|
-
var hasLoggedSemanticActive = false;
|
|
242
241
|
|
|
243
242
|
/** Get vector for a word from the store. */
|
|
244
243
|
var getWordVector = function getWordVector(word) {
|
|
@@ -344,25 +343,12 @@ var extractPreviousWord = function extractPreviousWord(text) {
|
|
|
344
343
|
|
|
345
344
|
// ─── Debug Helpers ───────────────────────────────────────────────────────────
|
|
346
345
|
|
|
347
|
-
/** Enable or disable debug logging. Also checks localStorage key `autocomplete-debug`. */
|
|
348
|
-
export var setDebugMode = function setDebugMode(enabled) {
|
|
349
|
-
debugMode = enabled;
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
/** Check localStorage for autocomplete-debug on first access. */
|
|
353
|
-
var ensureDebugModeFromStorage = function ensureDebugModeFromStorage() {
|
|
354
|
-
if (typeof localStorage !== 'undefined' && localStorage.getItem('autocomplete-debug') === '1') {
|
|
355
|
-
debugMode = true;
|
|
356
|
-
}
|
|
357
|
-
};
|
|
358
|
-
|
|
359
346
|
/**
|
|
360
347
|
* Get predictor status for debugging.
|
|
361
348
|
* vectorsLoaded: true when semantic scoring is active
|
|
362
349
|
* wordCount: number of words in vector store (0 if not loaded)
|
|
363
350
|
*/
|
|
364
351
|
export var getPredictorStatus = function getPredictorStatus() {
|
|
365
|
-
ensureDebugModeFromStorage();
|
|
366
352
|
return {
|
|
367
353
|
vectorsLoaded: vectorStore !== null,
|
|
368
354
|
wordCount: vectorStore ? Object.keys(vectorStore.wordIndex).length : 0,
|
|
@@ -376,7 +362,6 @@ export var getPredictorStatus = function getPredictorStatus() {
|
|
|
376
362
|
* Returns null if no prediction has run yet or debug was off.
|
|
377
363
|
*/
|
|
378
364
|
export var getLastPredictionDebug = function getLastPredictionDebug() {
|
|
379
|
-
ensureDebugModeFromStorage();
|
|
380
365
|
return lastPredictionDebug;
|
|
381
366
|
};
|
|
382
367
|
export var initVocabulary = function initVocabulary(vocabulary) {
|
|
@@ -435,7 +420,7 @@ export var ingestDocumentPage = function ingestDocumentPage(pageContent) {
|
|
|
435
420
|
} finally {
|
|
436
421
|
_iterator9.f();
|
|
437
422
|
}
|
|
438
|
-
if (
|
|
423
|
+
if (isAutocompleteDebugEnabled() && validBoostedWords.size > 0) {
|
|
439
424
|
// eslint-disable-next-line no-console
|
|
440
425
|
console.groupCollapsed("%c[L1 Session] %cPrimed ".concat(validBoostedWords.size, " valid dictionary words from page"), 'color: #00b8d9; font-weight: bold;', 'color: inherit; font-style: italic;');
|
|
441
426
|
// eslint-disable-next-line no-console
|
|
@@ -445,7 +430,6 @@ export var ingestDocumentPage = function ingestDocumentPage(pageContent) {
|
|
|
445
430
|
}
|
|
446
431
|
};
|
|
447
432
|
export var predict = function predict(textBefore) {
|
|
448
|
-
ensureDebugModeFromStorage();
|
|
449
433
|
if (!isInitialized) {
|
|
450
434
|
loadDefaultVocabulary();
|
|
451
435
|
}
|
|
@@ -538,7 +522,7 @@ export var predict = function predict(textBefore) {
|
|
|
538
522
|
var lmLogits = getStoredLmLogits();
|
|
539
523
|
|
|
540
524
|
// Raw LM Output Logger
|
|
541
|
-
if (
|
|
525
|
+
if (isAutocompleteDebugEnabled() && lmLogits && Object.keys(lmLogits).length > 0) {
|
|
542
526
|
var rawLmTop = Object.entries(lmLogits).sort(function (a, b) {
|
|
543
527
|
return b[1] - a[1];
|
|
544
528
|
}).slice(0, 5).map(function (_ref) {
|
|
@@ -554,9 +538,6 @@ export var predict = function predict(textBefore) {
|
|
|
554
538
|
console.log('%c[Raw LM Prediction]🧠', 'color: #e83e8c; font-weight: bold;', rawLmTop);
|
|
555
539
|
}
|
|
556
540
|
var mode = contextVector ? 'warm' : 'cold';
|
|
557
|
-
if (debugMode && contextVector && !hasLoggedSemanticActive) {
|
|
558
|
-
hasLoggedSemanticActive = true;
|
|
559
|
-
}
|
|
560
541
|
|
|
561
542
|
// Build ScoringCandidate array from TrieNodes
|
|
562
543
|
var scoringCandidates = candidates.map(function (_ref3) {
|
|
@@ -587,7 +568,7 @@ export var predict = function predict(textBefore) {
|
|
|
587
568
|
pipelineDebug = _rankCandidates.pipelineDebug;
|
|
588
569
|
var best = ranked[0];
|
|
589
570
|
var suggestion = best && best.finalScore >= MIN_SCORE_THRESHOLD ? best.word.slice(currentWord.length) : null;
|
|
590
|
-
if (
|
|
571
|
+
if (isAutocompleteDebugEnabled()) {
|
|
591
572
|
var latencyMs = performance.now() - t0;
|
|
592
573
|
var tokens = tokenize(trimmed);
|
|
593
574
|
var contextWords = tokens.slice(-CONTEXT_WORDS);
|
|
@@ -767,8 +748,7 @@ export var loadVectorsAsync = /*#__PURE__*/function () {
|
|
|
767
748
|
wordIndex: wordIndex,
|
|
768
749
|
dim: dim
|
|
769
750
|
};
|
|
770
|
-
|
|
771
|
-
if (debugMode) {
|
|
751
|
+
if (isAutocompleteDebugEnabled()) {
|
|
772
752
|
// eslint-disable-next-line no-console
|
|
773
753
|
console.log('[text-predictor] Vectors loaded:', {
|
|
774
754
|
wordCount: nWords,
|
|
@@ -776,19 +756,19 @@ export var loadVectorsAsync = /*#__PURE__*/function () {
|
|
|
776
756
|
sizeBytes: float32.byteLength
|
|
777
757
|
});
|
|
778
758
|
}
|
|
779
|
-
_context.next =
|
|
759
|
+
_context.next = 40;
|
|
780
760
|
break;
|
|
781
|
-
case
|
|
782
|
-
_context.prev =
|
|
761
|
+
case 36:
|
|
762
|
+
_context.prev = 36;
|
|
783
763
|
_context.t1 = _context["catch"](17);
|
|
784
764
|
vectorsLoadStarted = false;
|
|
785
765
|
// eslint-disable-next-line no-console
|
|
786
766
|
console.warn('[text-predictor] Failed to load vectors:', _context.t1);
|
|
787
|
-
case
|
|
767
|
+
case 40:
|
|
788
768
|
case "end":
|
|
789
769
|
return _context.stop();
|
|
790
770
|
}
|
|
791
|
-
}, _callee, null, [[6, 12], [17,
|
|
771
|
+
}, _callee, null, [[6, 12], [17, 36]]);
|
|
792
772
|
}));
|
|
793
773
|
return function loadVectorsAsync(_x) {
|
|
794
774
|
return _ref6.apply(this, arguments);
|
|
@@ -3,7 +3,7 @@ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
|
3
3
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
5
5
|
import type { AutocompletePlugin } from '../autocompletePluginType';
|
|
6
|
-
export declare const autocompletePluginKey: PluginKey
|
|
6
|
+
export declare const autocompletePluginKey: PluginKey;
|
|
7
7
|
export interface AutocompletePluginState {
|
|
8
8
|
/** The decoration set containing the ghost text widget */
|
|
9
9
|
decorationSet: DecorationSet;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contextual Typeahead Completions (CTC) debug logging utility.
|
|
3
|
+
*
|
|
4
|
+
* Logs are silent by default. To enable in any environment (dev, staging, prod):
|
|
5
|
+
*
|
|
6
|
+
* localStorage.setItem('atl-ctc-dbg', '1')
|
|
7
|
+
*
|
|
8
|
+
* Then reload the page. To disable:
|
|
9
|
+
*
|
|
10
|
+
* localStorage.removeItem('atl-ctc-dbg')
|
|
11
|
+
*/
|
|
12
|
+
export declare const isAutocompleteDebugEnabled: () => boolean;
|
|
@@ -33,8 +33,6 @@ interface VectorStore {
|
|
|
33
33
|
* expects a simple array of strings: ["about", "above", "actually", ...]
|
|
34
34
|
*/
|
|
35
35
|
export declare const initL3Vocabulary: (l3Words: string[]) => void;
|
|
36
|
-
/** Enable or disable debug logging. Also checks localStorage key `autocomplete-debug`. */
|
|
37
|
-
export declare const setDebugMode: (enabled: boolean) => void;
|
|
38
36
|
/**
|
|
39
37
|
* Get predictor status for debugging.
|
|
40
38
|
* vectorsLoaded: true when semantic scoring is active
|
|
@@ -3,7 +3,7 @@ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
|
3
3
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
5
5
|
import type { AutocompletePlugin } from '../autocompletePluginType';
|
|
6
|
-
export declare const autocompletePluginKey: PluginKey
|
|
6
|
+
export declare const autocompletePluginKey: PluginKey;
|
|
7
7
|
export interface AutocompletePluginState {
|
|
8
8
|
/** The decoration set containing the ghost text widget */
|
|
9
9
|
decorationSet: DecorationSet;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contextual Typeahead Completions (CTC) debug logging utility.
|
|
3
|
+
*
|
|
4
|
+
* Logs are silent by default. To enable in any environment (dev, staging, prod):
|
|
5
|
+
*
|
|
6
|
+
* localStorage.setItem('atl-ctc-dbg', '1')
|
|
7
|
+
*
|
|
8
|
+
* Then reload the page. To disable:
|
|
9
|
+
*
|
|
10
|
+
* localStorage.removeItem('atl-ctc-dbg')
|
|
11
|
+
*/
|
|
12
|
+
export declare const isAutocompleteDebugEnabled: () => boolean;
|
|
@@ -33,8 +33,6 @@ interface VectorStore {
|
|
|
33
33
|
* expects a simple array of strings: ["about", "above", "actually", ...]
|
|
34
34
|
*/
|
|
35
35
|
export declare const initL3Vocabulary: (l3Words: string[]) => void;
|
|
36
|
-
/** Enable or disable debug logging. Also checks localStorage key `autocomplete-debug`. */
|
|
37
|
-
export declare const setDebugMode: (enabled: boolean) => void;
|
|
38
36
|
/**
|
|
39
37
|
* Get predictor status for debugging.
|
|
40
38
|
* vectorsLoaded: true when semantic scoring is active
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-autocomplete",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Client-side text autocomplete plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"wink-nlp": "^2.4.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@atlaskit/editor-common": "^114.
|
|
36
|
+
"@atlaskit/editor-common": "^114.22.0",
|
|
37
37
|
"@atlaskit/editor-plugin-analytics": "^10.0.0",
|
|
38
38
|
"react": "^18.2.0"
|
|
39
39
|
},
|