@atlaskit/editor-plugin-autocomplete 8.0.0 → 9.0.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 +80 -0
- package/dist/cjs/analytics/ufo.js +2 -1
- package/dist/cjs/pm-plugins/artifact-loader.js +135 -0
- package/dist/cjs/pm-plugins/artifacts-manifest.js +3 -0
- package/dist/cjs/pm-plugins/autocomplete-plugin.js +416 -129
- package/dist/cjs/pm-plugins/canonical-lm-scoring.js +371 -0
- package/dist/cjs/pm-plugins/debug-mode.js +90 -7
- package/dist/cjs/pm-plugins/ghost-text-decoration.js +12 -3
- package/dist/cjs/pm-plugins/local-slow-lane-client.js +1202 -453
- package/dist/cjs/pm-plugins/scoring-pipeline.js +164 -19
- package/dist/cjs/pm-plugins/slow-lane-client.js +100 -37
- package/dist/cjs/pm-plugins/text-predictor.js +1951 -273
- package/dist/es2019/analytics/ufo.js +2 -0
- package/dist/es2019/pm-plugins/artifact-loader.js +70 -0
- package/dist/es2019/pm-plugins/artifacts-manifest.js +3 -0
- package/dist/es2019/pm-plugins/autocomplete-plugin.js +425 -130
- package/dist/es2019/pm-plugins/canonical-lm-scoring.js +270 -0
- package/dist/es2019/pm-plugins/debug-mode.js +87 -7
- package/dist/es2019/pm-plugins/ghost-text-decoration.js +12 -3
- package/dist/es2019/pm-plugins/local-slow-lane-client.js +940 -326
- package/dist/es2019/pm-plugins/scoring-pipeline.js +137 -13
- package/dist/es2019/pm-plugins/slow-lane-client.js +94 -37
- package/dist/es2019/pm-plugins/text-predictor.js +1603 -199
- package/dist/esm/analytics/ufo.js +2 -1
- package/dist/esm/pm-plugins/artifact-loader.js +128 -0
- package/dist/esm/pm-plugins/artifacts-manifest.js +3 -0
- package/dist/esm/pm-plugins/autocomplete-plugin.js +419 -132
- package/dist/esm/pm-plugins/canonical-lm-scoring.js +364 -0
- package/dist/esm/pm-plugins/debug-mode.js +89 -6
- package/dist/esm/pm-plugins/ghost-text-decoration.js +12 -3
- package/dist/esm/pm-plugins/local-slow-lane-client.js +1200 -451
- package/dist/esm/pm-plugins/scoring-pipeline.js +163 -18
- package/dist/esm/pm-plugins/slow-lane-client.js +100 -37
- package/dist/esm/pm-plugins/text-predictor.js +1953 -277
- package/dist/types/analytics/ufo.d.ts +1 -0
- package/dist/types/pm-plugins/artifact-loader.d.ts +44 -0
- package/dist/types/pm-plugins/artifacts-manifest.d.ts +3 -0
- package/dist/types/pm-plugins/autocomplete-plugin.d.ts +39 -0
- package/dist/types/pm-plugins/canonical-lm-scoring.d.ts +158 -0
- package/dist/types/pm-plugins/debug-mode.d.ts +36 -1
- package/dist/types/pm-plugins/ghost-text-decoration.d.ts +5 -2
- package/dist/types/pm-plugins/local-slow-lane-client.d.ts +87 -54
- package/dist/types/pm-plugins/scoring-pipeline.d.ts +33 -1
- package/dist/types/pm-plugins/slow-lane-client.d.ts +51 -3
- package/dist/types/pm-plugins/text-predictor.d.ts +120 -2
- package/package.json +2 -2
- package/src/analytics/ufo.ts +5 -0
- package/src/pm-plugins/artifact-loader.ts +92 -0
- package/src/pm-plugins/artifacts-manifest.ts +3 -0
- package/src/pm-plugins/autocomplete-plugin.ts +517 -133
- package/src/pm-plugins/canonical-lm-scoring.ts +412 -0
- package/src/pm-plugins/debug-mode.ts +109 -7
- package/src/pm-plugins/ghost-text-decoration.ts +13 -4
- package/src/pm-plugins/local-slow-lane-client.ts +1302 -386
- package/src/pm-plugins/scoring-pipeline.ts +167 -17
- package/src/pm-plugins/slow-lane-client.ts +147 -62
- package/src/pm-plugins/text-predictor.ts +2006 -255
- package/CANONICAL_FIX__DO_NOT_USE_ME_A/package.json +0 -8
- package/CANONICAL_FIX__DO_NOT_USE_ME_B/package.json +0 -8
- package/CANONICAL_FIX__DO_NOT_USE_ME_C/package.json +0 -8
- package/dist/cjs/entry-points/src-pm-plugins-autocomplete-plugin.js +0 -18
- package/dist/cjs/entry-points/src-pm-plugins-slow-lane-client.js +0 -36
- package/dist/cjs/entry-points/src-pm-plugins-text-predictor.js +0 -66
- package/dist/es2019/entry-points/src-pm-plugins-autocomplete-plugin.js +0 -2
- package/dist/es2019/entry-points/src-pm-plugins-slow-lane-client.js +0 -2
- package/dist/es2019/entry-points/src-pm-plugins-text-predictor.js +0 -2
- package/dist/esm/entry-points/src-pm-plugins-autocomplete-plugin.js +0 -2
- package/dist/esm/entry-points/src-pm-plugins-slow-lane-client.js +0 -2
- package/dist/esm/entry-points/src-pm-plugins-text-predictor.js +0 -2
- package/dist/types/entry-points/src-pm-plugins-autocomplete-plugin.d.ts +0 -2
- package/dist/types/entry-points/src-pm-plugins-slow-lane-client.d.ts +0 -2
- package/dist/types/entry-points/src-pm-plugins-text-predictor.d.ts +0 -2
- package/scripts/gen_first_token_to_words.py +0 -170
- package/src/entry-points/src-pm-plugins-autocomplete-plugin.ts +0 -7
- package/src/entry-points/src-pm-plugins-slow-lane-client.ts +0 -13
- package/src/entry-points/src-pm-plugins-text-predictor.ts +0 -14
- package/src/pm-plugins/autocomplete-plugin/package.json +0 -8
- package/src/pm-plugins/slow-lane-client/package.json +0 -8
- package/src/pm-plugins/text-predictor/package.json +0 -8
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.selectBoundaryPrimeRequests = exports.logSumExp = exports.logSoftmaxAt = exports.deriveWhitespaceBoundaryContext = exports.deriveCanonicalCandidateContext = exports.createCanonicalContextPositionCache = exports.CanonicalSurfaceTokenTrie = exports.CanonicalLogitProcessor = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
12
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
14
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
15
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
16
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
17
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
18
|
+
var createTokenTrieNode = function createTokenTrieNode() {
|
|
19
|
+
return {
|
|
20
|
+
children: new Map()
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Token trie for the producer's canonical leading-space token sequences.
|
|
26
|
+
* It lets the scorer expand a shared token prefix once for every surface below
|
|
27
|
+
* that node (`root cause`, `root directory`, ...), rather than guessing two
|
|
28
|
+
* arbitrary full surfaces from a broad one-character string prefix.
|
|
29
|
+
*/
|
|
30
|
+
var CanonicalSurfaceTokenTrie = exports.CanonicalSurfaceTokenTrie = /*#__PURE__*/function () {
|
|
31
|
+
function CanonicalSurfaceTokenTrie() {
|
|
32
|
+
var entries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
33
|
+
(0, _classCallCheck2.default)(this, CanonicalSurfaceTokenTrie);
|
|
34
|
+
(0, _defineProperty2.default)(this, "root", createTokenTrieNode());
|
|
35
|
+
(0, _defineProperty2.default)(this, "tokenIdsBySurface", new Map());
|
|
36
|
+
var _iterator = _createForOfIteratorHelper(entries),
|
|
37
|
+
_step;
|
|
38
|
+
try {
|
|
39
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
40
|
+
var _step$value = (0, _slicedToArray2.default)(_step.value, 2),
|
|
41
|
+
surface = _step$value[0],
|
|
42
|
+
tokenIds = _step$value[1];
|
|
43
|
+
this.insert(surface, tokenIds);
|
|
44
|
+
}
|
|
45
|
+
} catch (err) {
|
|
46
|
+
_iterator.e(err);
|
|
47
|
+
} finally {
|
|
48
|
+
_iterator.f();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return (0, _createClass2.default)(CanonicalSurfaceTokenTrie, [{
|
|
52
|
+
key: "insert",
|
|
53
|
+
value: function insert(surface, tokenIds) {
|
|
54
|
+
if (tokenIds.length === 0) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
var normalizedSurface = surface.toLowerCase();
|
|
58
|
+
this.tokenIdsBySurface.set(normalizedSurface, (0, _toConsumableArray2.default)(tokenIds));
|
|
59
|
+
var node = this.root;
|
|
60
|
+
var _iterator2 = _createForOfIteratorHelper(tokenIds),
|
|
61
|
+
_step2;
|
|
62
|
+
try {
|
|
63
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
64
|
+
var tokenId = _step2.value;
|
|
65
|
+
var child = node.children.get(tokenId);
|
|
66
|
+
if (!child) {
|
|
67
|
+
child = createTokenTrieNode();
|
|
68
|
+
node.children.set(tokenId, child);
|
|
69
|
+
}
|
|
70
|
+
node = child;
|
|
71
|
+
}
|
|
72
|
+
} catch (err) {
|
|
73
|
+
_iterator2.e(err);
|
|
74
|
+
} finally {
|
|
75
|
+
_iterator2.f();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}, {
|
|
79
|
+
key: "getTokenIds",
|
|
80
|
+
value: function getTokenIds(surface) {
|
|
81
|
+
var tokenIds = this.tokenIdsBySurface.get(surface.toLowerCase());
|
|
82
|
+
return tokenIds ? (0, _toConsumableArray2.default)(tokenIds) : null;
|
|
83
|
+
}
|
|
84
|
+
}, {
|
|
85
|
+
key: "groupByScoredPrefix",
|
|
86
|
+
value: function groupByScoredPrefix(candidates) {
|
|
87
|
+
var groups = new Map();
|
|
88
|
+
var _iterator3 = _createForOfIteratorHelper(candidates),
|
|
89
|
+
_step3;
|
|
90
|
+
try {
|
|
91
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
92
|
+
var _groups$get;
|
|
93
|
+
var candidate = _step3.value;
|
|
94
|
+
if (candidate.scoredTokenCount <= 0 || candidate.scoredTokenCount >= candidate.tokenIds.length) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
var tokenPrefix = candidate.tokenIds.slice(0, candidate.scoredTokenCount);
|
|
98
|
+
var node = this.root;
|
|
99
|
+
var _iterator4 = _createForOfIteratorHelper(tokenPrefix),
|
|
100
|
+
_step4;
|
|
101
|
+
try {
|
|
102
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
103
|
+
var tokenId = _step4.value;
|
|
104
|
+
node = node.children.get(tokenId);
|
|
105
|
+
if (!node) {
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
} catch (err) {
|
|
110
|
+
_iterator4.e(err);
|
|
111
|
+
} finally {
|
|
112
|
+
_iterator4.f();
|
|
113
|
+
}
|
|
114
|
+
if (!node) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
var key = tokenPrefix.join(',');
|
|
118
|
+
var group = (_groups$get = groups.get(key)) !== null && _groups$get !== void 0 ? _groups$get : {
|
|
119
|
+
surfaces: [],
|
|
120
|
+
tokenPrefix: tokenPrefix
|
|
121
|
+
};
|
|
122
|
+
group.surfaces.push(candidate.surface);
|
|
123
|
+
groups.set(key, group);
|
|
124
|
+
}
|
|
125
|
+
} catch (err) {
|
|
126
|
+
_iterator3.e(err);
|
|
127
|
+
} finally {
|
|
128
|
+
_iterator3.f();
|
|
129
|
+
}
|
|
130
|
+
return Array.from(groups.values());
|
|
131
|
+
}
|
|
132
|
+
}]);
|
|
133
|
+
}();
|
|
134
|
+
var WHITESPACE_REGEX = /[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]/;
|
|
135
|
+
var makeContextKey = function makeContextKey(prompt, separatorKind) {
|
|
136
|
+
return "".concat(separatorKind, "\0").concat(prompt);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/** The part of a candidate's context that depends only on where its surface starts. */
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Per-pass store for the position-derived half of a candidate's context.
|
|
143
|
+
*
|
|
144
|
+
* Every unigram candidate for a keystroke shares one surface start, and the
|
|
145
|
+
* phrase candidates share a handful more, so without this the same slice,
|
|
146
|
+
* `trimEnd` and context key are rebuilt for each of the couple of hundred
|
|
147
|
+
* candidates. Valid only for a single `textBeforeCursor`.
|
|
148
|
+
*/
|
|
149
|
+
|
|
150
|
+
var createCanonicalContextPositionCache = exports.createCanonicalContextPositionCache = function createCanonicalContextPositionCache() {
|
|
151
|
+
return new Map();
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Derive the causal prompt and artifact eligibility from the exact, untrimmed
|
|
156
|
+
* pre-cursor text. The shipped artifact contains only tokenizations of
|
|
157
|
+
* `" " + surface`, so it is valid only when the surface is actually preceded
|
|
158
|
+
* by whitespace.
|
|
159
|
+
*/
|
|
160
|
+
var deriveCanonicalCandidateContext = exports.deriveCanonicalCandidateContext = function deriveCanonicalCandidateContext(textBeforeCursor, matchedPrefixLen, surface, getTokenIds, surfaceStartOverride, positionCache) {
|
|
161
|
+
var derivedSurfaceStart = textBeforeCursor.length - matchedPrefixLen;
|
|
162
|
+
var surfaceStart = Math.max(0, Math.min(textBeforeCursor.length, surfaceStartOverride !== null && surfaceStartOverride !== void 0 ? surfaceStartOverride : derivedSurfaceStart));
|
|
163
|
+
var position = positionCache === null || positionCache === void 0 ? void 0 : positionCache.get(surfaceStart);
|
|
164
|
+
if (position === undefined) {
|
|
165
|
+
var precedingChar = surfaceStart > 0 ? textBeforeCursor[surfaceStart - 1] : null;
|
|
166
|
+
var separatorKind = precedingChar === null ? 'document-start' : WHITESPACE_REGEX.test(precedingChar) ? 'whitespace' : 'non-space';
|
|
167
|
+
var contextBeforeSurface = textBeforeCursor.slice(0, surfaceStart).trimEnd();
|
|
168
|
+
position = {
|
|
169
|
+
contextBeforeSurface: contextBeforeSurface,
|
|
170
|
+
contextKey: makeContextKey(contextBeforeSurface, separatorKind),
|
|
171
|
+
separatorKind: separatorKind,
|
|
172
|
+
surfaceStart: surfaceStart
|
|
173
|
+
};
|
|
174
|
+
positionCache === null || positionCache === void 0 || positionCache.set(surfaceStart, position);
|
|
175
|
+
}
|
|
176
|
+
return _objectSpread(_objectSpread({}, position), {}, {
|
|
177
|
+
canonicalTokenIds: position.separatorKind === 'whitespace' ? getTokenIds(surface) : null
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Derive the next surface's leading-space context at an actual word boundary.
|
|
183
|
+
* This lets the local LM start its one-token prime on the space keystroke,
|
|
184
|
+
* before the user has typed the first character of the next word.
|
|
185
|
+
*/
|
|
186
|
+
var deriveWhitespaceBoundaryContext = exports.deriveWhitespaceBoundaryContext = function deriveWhitespaceBoundaryContext(textBeforeCursor) {
|
|
187
|
+
var _textBeforeCursor$at;
|
|
188
|
+
if (textBeforeCursor.length === 0 || !WHITESPACE_REGEX.test((_textBeforeCursor$at = textBeforeCursor.at(-1)) !== null && _textBeforeCursor$at !== void 0 ? _textBeforeCursor$at : '')) {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
var prompt = textBeforeCursor.trimEnd();
|
|
192
|
+
if (prompt.length === 0) {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
contextKey: makeContextKey(prompt, 'whitespace'),
|
|
197
|
+
prompt: prompt
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Return one prime per exact context, ordered from the latest surface start
|
|
203
|
+
* (normally the unigram window) to wider phrase windows.
|
|
204
|
+
*/
|
|
205
|
+
var selectBoundaryPrimeRequests = exports.selectBoundaryPrimeRequests = function selectBoundaryPrimeRequests(familyKey, candidates, maxPrimes) {
|
|
206
|
+
var byContext = new Map();
|
|
207
|
+
var _iterator5 = _createForOfIteratorHelper(candidates),
|
|
208
|
+
_step5;
|
|
209
|
+
try {
|
|
210
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
211
|
+
var candidate = _step5.value;
|
|
212
|
+
if (candidate.canonicalTokenIds === null) {
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
var current = byContext.get(candidate.contextKey);
|
|
216
|
+
if (!current || candidate.surfaceStart > current.surfaceStart) {
|
|
217
|
+
byContext.set(candidate.contextKey, candidate);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
} catch (err) {
|
|
221
|
+
_iterator5.e(err);
|
|
222
|
+
} finally {
|
|
223
|
+
_iterator5.f();
|
|
224
|
+
}
|
|
225
|
+
return Array.from(byContext.values()).sort(function (a, b) {
|
|
226
|
+
return b.surfaceStart - a.surfaceStart;
|
|
227
|
+
}).slice(0, Math.max(0, maxPrimes)).map(function (candidate, priority) {
|
|
228
|
+
return {
|
|
229
|
+
familyKey: familyKey,
|
|
230
|
+
contextKey: candidate.contextKey,
|
|
231
|
+
prompt: candidate.contextBeforeSurface,
|
|
232
|
+
priority: priority
|
|
233
|
+
};
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* `log(sum(exp(values)))`, shifted by the maximum so the sum cannot overflow or
|
|
239
|
+
* underflow to zero for the sequence log-likelihoods this is called with.
|
|
240
|
+
*
|
|
241
|
+
* Returns `-Infinity` for an empty or wholly non-finite input, which makes
|
|
242
|
+
* `exp(value - logSumExp(values))` evaluate to zero rather than `NaN`.
|
|
243
|
+
*/
|
|
244
|
+
var logSumExp = exports.logSumExp = function logSumExp(values) {
|
|
245
|
+
var max = -Infinity;
|
|
246
|
+
var _iterator6 = _createForOfIteratorHelper(values),
|
|
247
|
+
_step6;
|
|
248
|
+
try {
|
|
249
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
250
|
+
var value = _step6.value;
|
|
251
|
+
if (Number.isFinite(value) && value > max) {
|
|
252
|
+
max = value;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
} catch (err) {
|
|
256
|
+
_iterator6.e(err);
|
|
257
|
+
} finally {
|
|
258
|
+
_iterator6.f();
|
|
259
|
+
}
|
|
260
|
+
if (!Number.isFinite(max)) {
|
|
261
|
+
return -Infinity;
|
|
262
|
+
}
|
|
263
|
+
var sumExp = 0;
|
|
264
|
+
var _iterator7 = _createForOfIteratorHelper(values),
|
|
265
|
+
_step7;
|
|
266
|
+
try {
|
|
267
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
268
|
+
var _value = _step7.value;
|
|
269
|
+
if (Number.isFinite(_value)) {
|
|
270
|
+
sumExp += Math.exp(_value - max);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
} catch (err) {
|
|
274
|
+
_iterator7.e(err);
|
|
275
|
+
} finally {
|
|
276
|
+
_iterator7.f();
|
|
277
|
+
}
|
|
278
|
+
return sumExp > 0 ? max + Math.log(sumExp) : -Infinity;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
/** The two shift-and-sum terms of a distribution's log-partition. */
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* The log-partition depends only on the buffer, but scoring reads the same
|
|
285
|
+
* buffer once per candidate — so without this the two full-vocabulary passes
|
|
286
|
+
* below run N times per boundary for an answer that cannot change.
|
|
287
|
+
*
|
|
288
|
+
* Keying on the buffer itself is safe because captured logits are never
|
|
289
|
+
* written to again (see `CanonicalLogitProcessor.processLogits`, which copies
|
|
290
|
+
* out of WebLLM's reused buffer), and the weak reference lets a retired
|
|
291
|
+
* boundary's entry go with it.
|
|
292
|
+
*/
|
|
293
|
+
var logPartitionTermsCache = new WeakMap();
|
|
294
|
+
var getLogPartitionTerms = function getLogPartitionTerms(logits) {
|
|
295
|
+
var cached = logPartitionTermsCache.get(logits);
|
|
296
|
+
if (cached !== undefined) {
|
|
297
|
+
return cached;
|
|
298
|
+
}
|
|
299
|
+
var maxLogit = -Infinity;
|
|
300
|
+
for (var i = 0; i < logits.length; i++) {
|
|
301
|
+
if (logits[i] > maxLogit) {
|
|
302
|
+
maxLogit = logits[i];
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
var terms = null;
|
|
306
|
+
if (Number.isFinite(maxLogit)) {
|
|
307
|
+
var sumExp = 0;
|
|
308
|
+
for (var _i = 0; _i < logits.length; _i++) {
|
|
309
|
+
sumExp += Math.exp(logits[_i] - maxLogit);
|
|
310
|
+
}
|
|
311
|
+
if (sumExp > 0) {
|
|
312
|
+
terms = {
|
|
313
|
+
maxLogit: maxLogit,
|
|
314
|
+
logSumTerm: Math.log(sumExp)
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
logPartitionTermsCache.set(logits, terms);
|
|
319
|
+
return terms;
|
|
320
|
+
};
|
|
321
|
+
var logSoftmaxAt = exports.logSoftmaxAt = function logSoftmaxAt(logits, target) {
|
|
322
|
+
if (target < 0 || target >= logits.length) {
|
|
323
|
+
return -Infinity;
|
|
324
|
+
}
|
|
325
|
+
var terms = getLogPartitionTerms(logits);
|
|
326
|
+
if (terms === null) {
|
|
327
|
+
return -Infinity;
|
|
328
|
+
}
|
|
329
|
+
return logits[target] - terms.maxLogit - terms.logSumTerm;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* One processor is registered for the causal model so the scheduler can read
|
|
334
|
+
* the next-token distribution off any forward pass.
|
|
335
|
+
*
|
|
336
|
+
* The scheduler drives decoding token by token — it prefills a prompt, then
|
|
337
|
+
* feeds each continuation token itself — so the processor never has to force
|
|
338
|
+
* the model onto a target path. It only has to hand back the distribution the
|
|
339
|
+
* forward pass produced, which it does without altering the logits.
|
|
340
|
+
*/
|
|
341
|
+
var CanonicalLogitProcessor = exports.CanonicalLogitProcessor = /*#__PURE__*/(0, _createClass2.default)(function CanonicalLogitProcessor() {
|
|
342
|
+
var _this = this;
|
|
343
|
+
(0, _classCallCheck2.default)(this, CanonicalLogitProcessor);
|
|
344
|
+
(0, _defineProperty2.default)(this, "captured", null);
|
|
345
|
+
(0, _defineProperty2.default)(this, "processLogits", function (logits) {
|
|
346
|
+
// WebLLM reuses its logits buffer between forwards, so keep a private copy.
|
|
347
|
+
_this.captured = new Float32Array(logits);
|
|
348
|
+
return logits;
|
|
349
|
+
});
|
|
350
|
+
(0, _defineProperty2.default)(this, "processSampledToken", function () {
|
|
351
|
+
// The scheduler chooses the next token; WebLLM's sample is discarded.
|
|
352
|
+
});
|
|
353
|
+
(0, _defineProperty2.default)(this, "resetState", function () {
|
|
354
|
+
// WebLLM resets the processor after the caller has armed a capture and
|
|
355
|
+
// immediately before it prefills a completion prompt, so this only ever
|
|
356
|
+
// clears a stale reading from the previous run.
|
|
357
|
+
_this.captured = null;
|
|
358
|
+
});
|
|
359
|
+
(0, _defineProperty2.default)(this, "startCapture", function () {
|
|
360
|
+
_this.captured = null;
|
|
361
|
+
});
|
|
362
|
+
/**
|
|
363
|
+
* The captured distribution, or null when the forward pass never ran.
|
|
364
|
+
*
|
|
365
|
+
* `processLogits` already copied it, and every capture allocates afresh, so
|
|
366
|
+
* the buffer handed out here is never written to again.
|
|
367
|
+
*/
|
|
368
|
+
(0, _defineProperty2.default)(this, "getCapturedLogits", function () {
|
|
369
|
+
return _this.captured;
|
|
370
|
+
});
|
|
371
|
+
});
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isAutocompleteDebugEnabled = void 0;
|
|
6
|
+
exports.isAutocompleteDebugVerbose = exports.isAutocompleteDebugEnabled = exports.ctcTag = exports.ctcSection = exports.CTC_STYLES = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* Contextual Typeahead Completions (CTC) debug logging utility.
|
|
9
9
|
*
|
|
@@ -22,16 +22,84 @@ exports.isAutocompleteDebugEnabled = void 0;
|
|
|
22
22
|
* block uncategorized localStorage/sessionStorage/cookie writes in some products.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Shared `%c` styles for all CTC console output, so every log — lifecycle,
|
|
27
|
+
* async signals, and per-prediction groups — reads consistently.
|
|
28
|
+
*/
|
|
29
|
+
var CTC_STYLES = exports.CTC_STYLES = {
|
|
30
|
+
brand: 'color: #00b8d9; font-weight: bold;',
|
|
31
|
+
section: 'color: #9c27b0; font-weight: bold;',
|
|
32
|
+
dim: 'color: #888; font-style: italic;',
|
|
33
|
+
good: 'color: #4caf50; font-weight: bold;',
|
|
34
|
+
warn: 'color: #ff9800; font-weight: bold;',
|
|
35
|
+
bad: 'color: #f44336; font-weight: bold;',
|
|
36
|
+
cold: 'color: #9e9e9e; font-weight: bold;',
|
|
37
|
+
lm: 'color: #e83e8c; font-weight: bold;',
|
|
38
|
+
body: 'color: inherit; font-weight: normal;'
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Log one aligned section line inside a per-prediction group, e.g.
|
|
43
|
+
* `INPUT raw: "…"`. Label is padded so the bodies line up. No-ops unless
|
|
44
|
+
* debug is enabled, so callers don't need to guard.
|
|
45
|
+
*/
|
|
46
|
+
var ctcSection = exports.ctcSection = function ctcSection(label, body) {
|
|
47
|
+
if (!isAutocompleteDebugEnabled()) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
// eslint-disable-next-line no-console
|
|
51
|
+
console.log("%c".concat(label.padEnd(10), "%c").concat(body), CTC_STYLES.section, CTC_STYLES.body);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Log a lifecycle / async-signal line (outside the per-prediction groups),
|
|
56
|
+
* tagged `[CTC:<tag>]`. No-ops unless debug is enabled, so callers don't need to
|
|
57
|
+
* guard. Use tags like `init` (loads) and `signal` (slow-lane arrivals).
|
|
58
|
+
*/
|
|
59
|
+
var ctcTag = exports.ctcTag = function ctcTag(tag, body) {
|
|
60
|
+
var tagStyle = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : CTC_STYLES.brand;
|
|
61
|
+
if (!isAutocompleteDebugEnabled()) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
// eslint-disable-next-line no-console
|
|
65
|
+
console.log("%c[CTC:".concat(tag, "]%c ").concat(body), tagStyle, CTC_STYLES.body);
|
|
66
|
+
};
|
|
67
|
+
var readUrlDebugFlag = function readUrlDebugFlag() {
|
|
26
68
|
if (typeof window === 'undefined') {
|
|
27
|
-
return
|
|
69
|
+
return {
|
|
70
|
+
enabled: false,
|
|
71
|
+
verbose: false
|
|
72
|
+
};
|
|
28
73
|
}
|
|
29
74
|
try {
|
|
30
|
-
|
|
75
|
+
var value = new URLSearchParams(window.location.search).get('atlCtcDebug');
|
|
76
|
+
return {
|
|
77
|
+
enabled: value === '1' || value === 'verbose',
|
|
78
|
+
verbose: value === 'verbose'
|
|
79
|
+
};
|
|
31
80
|
} catch (_unused) {
|
|
32
|
-
return
|
|
81
|
+
return {
|
|
82
|
+
enabled: false,
|
|
83
|
+
verbose: false
|
|
84
|
+
};
|
|
33
85
|
}
|
|
34
86
|
};
|
|
87
|
+
var printLegend = function printLegend(verbose) {
|
|
88
|
+
// eslint-disable-next-line no-console
|
|
89
|
+
console.groupCollapsed("%c[CTC]%c debug enabled".concat(verbose ? ' (verbose)' : '', " \u2014 Contextual Typeahead Completion"), CTC_STYLES.brand, CTC_STYLES.body);
|
|
90
|
+
// eslint-disable-next-line no-console
|
|
91
|
+
console.log('%cPipeline%c INPUT → SIGNALS → CANONICAL → GENERATE → SCORE → ARBITRATE → STABILIZE → CANDIDATES', CTC_STYLES.section, CTC_STYLES.body);
|
|
92
|
+
// eslint-disable-next-line no-console
|
|
93
|
+
console.log('%cEvidence%c Tier A = exact-context first token · prefix = one more decoded token · exact = every token of the surface scored · absent = Stage 1', CTC_STYLES.section, CTC_STYLES.body);
|
|
94
|
+
// eslint-disable-next-line no-console
|
|
95
|
+
console.log('%cLM queue%c one serialised GPU queue drains both: prompt prefills and single-token decode steps', CTC_STYLES.section, CTC_STYLES.body);
|
|
96
|
+
// eslint-disable-next-line no-console
|
|
97
|
+
console.log('%cPlanes%c [CTC:init] loads · [CTC:signal] semantic/network · [CTC:model] primes/exact · [CTC:model-cost] prefill/decode · [CTC:readiness] deadline progress', CTC_STYLES.section, CTC_STYLES.body);
|
|
98
|
+
// eslint-disable-next-line no-console
|
|
99
|
+
console.log('%cInspect%c __atlCtcDebug__.enable("verbose") · .disable()', CTC_STYLES.section, CTC_STYLES.body);
|
|
100
|
+
// eslint-disable-next-line no-console
|
|
101
|
+
console.groupEnd();
|
|
102
|
+
};
|
|
35
103
|
|
|
36
104
|
// State lives on the window object (not a module closure) so duplicate copies of this
|
|
37
105
|
// module across separate bundles/realms share one source of truth and the console API
|
|
@@ -41,16 +109,27 @@ var getDebugApi = function getDebugApi() {
|
|
|
41
109
|
return undefined;
|
|
42
110
|
}
|
|
43
111
|
if (!window.__atlCtcDebug__) {
|
|
44
|
-
var
|
|
112
|
+
var initial = readUrlDebugFlag();
|
|
113
|
+
var debugEnabled = initial.enabled;
|
|
114
|
+
var debugVerbose = initial.verbose;
|
|
115
|
+
if (debugEnabled) {
|
|
116
|
+
printLegend(debugVerbose);
|
|
117
|
+
}
|
|
45
118
|
window.__atlCtcDebug__ = {
|
|
46
|
-
enable: function enable() {
|
|
119
|
+
enable: function enable(level) {
|
|
47
120
|
debugEnabled = true;
|
|
121
|
+
debugVerbose = level === 'verbose';
|
|
122
|
+
printLegend(debugVerbose);
|
|
48
123
|
},
|
|
49
124
|
disable: function disable() {
|
|
50
125
|
debugEnabled = false;
|
|
126
|
+
debugVerbose = false;
|
|
51
127
|
},
|
|
52
128
|
isEnabled: function isEnabled() {
|
|
53
129
|
return debugEnabled;
|
|
130
|
+
},
|
|
131
|
+
isVerbose: function isVerbose() {
|
|
132
|
+
return debugEnabled && debugVerbose;
|
|
54
133
|
}
|
|
55
134
|
};
|
|
56
135
|
}
|
|
@@ -60,6 +139,10 @@ var isAutocompleteDebugEnabled = exports.isAutocompleteDebugEnabled = function i
|
|
|
60
139
|
var _getDebugApi$isEnable, _getDebugApi;
|
|
61
140
|
return (_getDebugApi$isEnable = (_getDebugApi = getDebugApi()) === null || _getDebugApi === void 0 ? void 0 : _getDebugApi.isEnabled()) !== null && _getDebugApi$isEnable !== void 0 ? _getDebugApi$isEnable : false;
|
|
62
141
|
};
|
|
142
|
+
var isAutocompleteDebugVerbose = exports.isAutocompleteDebugVerbose = function isAutocompleteDebugVerbose() {
|
|
143
|
+
var _getDebugApi$isVerbos, _getDebugApi2;
|
|
144
|
+
return (_getDebugApi$isVerbos = (_getDebugApi2 = getDebugApi()) === null || _getDebugApi2 === void 0 ? void 0 : _getDebugApi2.isVerbose()) !== null && _getDebugApi$isVerbos !== void 0 ? _getDebugApi$isVerbos : false;
|
|
145
|
+
};
|
|
63
146
|
|
|
64
147
|
// Eagerly install so the console API is available on load, regardless of call order.
|
|
65
148
|
getDebugApi();
|
|
@@ -10,8 +10,11 @@ var GHOST_TEXT_CLASS = 'autocomplete-ghost-text';
|
|
|
10
10
|
/**
|
|
11
11
|
* Creates a DecorationSet containing a ghost text widget at the given position.
|
|
12
12
|
* The ghost text is rendered as a styled <span> that appears after the cursor.
|
|
13
|
+
*
|
|
14
|
+
* Takes the document rather than the whole state so it can also be called from
|
|
15
|
+
* `apply`, where only the post-transaction doc exists.
|
|
13
16
|
*/
|
|
14
|
-
var createGhostTextDecorationSet = exports.createGhostTextDecorationSet = function createGhostTextDecorationSet(
|
|
17
|
+
var createGhostTextDecorationSet = exports.createGhostTextDecorationSet = function createGhostTextDecorationSet(doc, position, text) {
|
|
15
18
|
if (!text) {
|
|
16
19
|
return _view.DecorationSet.empty;
|
|
17
20
|
}
|
|
@@ -36,7 +39,13 @@ var createGhostTextDecorationSet = exports.createGhostTextDecorationSet = functi
|
|
|
36
39
|
}, {
|
|
37
40
|
side: 1,
|
|
38
41
|
// Render after content at this position
|
|
39
|
-
key
|
|
42
|
+
// A matching key short-circuits `WidgetType.eq`, so ProseMirror reuses
|
|
43
|
+
// the rendered node and never calls `toDOM` again. Keying on the text
|
|
44
|
+
// keeps that reuse when nothing changed while still forcing a redraw
|
|
45
|
+
// when the ghost advances through a keystroke that confirmed it —
|
|
46
|
+
// otherwise the stale tail stays on screen and Tab inserts a
|
|
47
|
+
// character the user already typed.
|
|
48
|
+
key: "autocomplete-ghost-text:".concat(text)
|
|
40
49
|
});
|
|
41
|
-
return _view.DecorationSet.create(
|
|
50
|
+
return _view.DecorationSet.create(doc, [decoration]);
|
|
42
51
|
};
|