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