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