@atlaskit/editor-plugin-autocomplete 3.5.0 → 3.6.1
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 +25 -0
- package/dist/cjs/pm-plugins/autocomplete-plugin.js +50 -7
- package/dist/cjs/pm-plugins/local-slow-lane-client.js +241 -63
- package/dist/cjs/pm-plugins/text-predictor.js +18 -4
- package/dist/es2019/pm-plugins/autocomplete-plugin.js +52 -7
- package/dist/es2019/pm-plugins/local-slow-lane-client.js +141 -11
- package/dist/es2019/pm-plugins/text-predictor.js +17 -3
- package/dist/esm/pm-plugins/autocomplete-plugin.js +50 -7
- package/dist/esm/pm-plugins/local-slow-lane-client.js +240 -62
- package/dist/esm/pm-plugins/text-predictor.js +18 -4
- package/dist/types/pm-plugins/local-slow-lane-client.d.ts +52 -0
- package/dist/types/pm-plugins/text-predictor.d.ts +4 -1
- package/dist/types-ts4.5/pm-plugins/local-slow-lane-client.d.ts +52 -0
- package/dist/types-ts4.5/pm-plugins/text-predictor.d.ts +4 -1
- package/package.json +2 -2
- package/src/pm-plugins/autocomplete-plugin.ts +57 -10
- package/src/pm-plugins/local-slow-lane-client.ts +224 -12
- package/src/pm-plugins/text-predictor.ts +12 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-autocomplete
|
|
2
2
|
|
|
3
|
+
## 3.6.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`2d57d65205edd`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2d57d65205edd) -
|
|
8
|
+
[ASIMO] Add `isLocalLLM` attribute to `load-vectors` and `load-vocabulary` UFO experiences.
|
|
9
|
+
|
|
10
|
+
Both experiences now include an `isLocalLLM: boolean` attribute on every event (start, succeed,
|
|
11
|
+
fail) so analysts can segment loading performance and reliability by whether the user is on the
|
|
12
|
+
local on-device model setup vs the standard network-based slow-lane backend.
|
|
13
|
+
|
|
14
|
+
## 3.6.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- [`9f6b6c9fffc50`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/9f6b6c9fffc50) -
|
|
19
|
+
Add analytics for the on-device (local LLM) autocomplete slow lane: fire a `localModelLoaded`
|
|
20
|
+
track event when the engine initialises successfully (with load duration and GPU info) and a
|
|
21
|
+
`localModelLoadFailed` track event when it fails, categorising the reason and capturing WebGPU
|
|
22
|
+
capability diagnostics to surface user-machine limitations.
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Updated dependencies
|
|
27
|
+
|
|
3
28
|
## 3.5.0
|
|
4
29
|
|
|
5
30
|
### Minor Changes
|
|
@@ -247,12 +247,49 @@ var createAutocompletePlugin = exports.createAutocompletePlugin = function creat
|
|
|
247
247
|
}
|
|
248
248
|
});
|
|
249
249
|
};
|
|
250
|
-
var
|
|
250
|
+
var fireLocalModelLoadedAnalytics = function fireLocalModelLoadedAnalytics(info) {
|
|
251
251
|
var _api$analytics2;
|
|
252
|
+
api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || _api$analytics2.actions.fireAnalyticsEvent({
|
|
253
|
+
action: _analytics.ACTION.LOCAL_MODEL_LOADED,
|
|
254
|
+
actionSubject: _analytics.ACTION_SUBJECT.CONTEXTUAL_TYPEAHEAD,
|
|
255
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
256
|
+
attributes: {
|
|
257
|
+
modelId: info.modelId,
|
|
258
|
+
embeddingModelId: info.embeddingModelId,
|
|
259
|
+
loadDurationMs: info.loadDurationMs,
|
|
260
|
+
gpuVendor: info.capabilities.vendor,
|
|
261
|
+
gpuArchitecture: info.capabilities.architecture
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
};
|
|
265
|
+
var fireLocalModelLoadFailedAnalytics = function fireLocalModelLoadFailedAnalytics(error) {
|
|
266
|
+
var _api$analytics3;
|
|
267
|
+
var capabilities = error.capabilities;
|
|
268
|
+
api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 || _api$analytics3.actions.fireAnalyticsEvent({
|
|
269
|
+
action: _analytics.ACTION.LOCAL_MODEL_LOAD_FAILED,
|
|
270
|
+
actionSubject: _analytics.ACTION_SUBJECT.CONTEXTUAL_TYPEAHEAD,
|
|
271
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
272
|
+
attributes: {
|
|
273
|
+
reason: error.reason,
|
|
274
|
+
message: error.message,
|
|
275
|
+
modelId: error.modelId,
|
|
276
|
+
embeddingModelId: error.embeddingModelId,
|
|
277
|
+
webgpuAvailable: capabilities.available,
|
|
278
|
+
adapterAvailable: capabilities.adapterAvailable,
|
|
279
|
+
shaderF16Supported: capabilities.shaderF16Supported,
|
|
280
|
+
maxBufferSizeMB: capabilities.maxBufferSizeMB,
|
|
281
|
+
maxStorageBufferBindingSizeMB: capabilities.maxStorageBufferBindingSizeMB,
|
|
282
|
+
gpuVendor: capabilities.vendor,
|
|
283
|
+
gpuArchitecture: capabilities.architecture
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
};
|
|
287
|
+
var fireSuggestionInsertedAnalytics = function fireSuggestionInsertedAnalytics(ghostText) {
|
|
288
|
+
var _api$analytics4;
|
|
252
289
|
var typedLength = lastSuggestionTypedLength;
|
|
253
290
|
var suggestionLength = lastSuggestionLength || typedLength + ghostText.length;
|
|
254
291
|
var kssDelta = suggestionLength - typedLength;
|
|
255
|
-
api === null || api === void 0 || (_api$
|
|
292
|
+
api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 || _api$analytics4.actions.fireAnalyticsEvent({
|
|
256
293
|
action: _analytics.ACTION.SUGGESTION_INSERTED,
|
|
257
294
|
actionSubject: _analytics.ACTION_SUBJECT.CONTEXTUAL_TYPEAHEAD,
|
|
258
295
|
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
@@ -265,7 +302,9 @@ var createAutocompletePlugin = exports.createAutocompletePlugin = function creat
|
|
|
265
302
|
});
|
|
266
303
|
};
|
|
267
304
|
var slowLaneClient = options !== null && options !== void 0 && options.useLocalModel ? (0, _localSlowLaneClient.createLocalSlowLaneClient)({
|
|
268
|
-
debounceMs: LOCAL_SLOW_LANE_DEBOUNCE_MS
|
|
305
|
+
debounceMs: LOCAL_SLOW_LANE_DEBOUNCE_MS,
|
|
306
|
+
onLoadSuccess: fireLocalModelLoadedAnalytics,
|
|
307
|
+
onLoadError: fireLocalModelLoadFailedAnalytics
|
|
269
308
|
}) : (0, _slowLaneClient.createSlowLaneClient)({
|
|
270
309
|
baseUrl: '',
|
|
271
310
|
debounceMs: NETWORK_SLOW_LANE_DEBOUNCE_MS
|
|
@@ -419,9 +458,9 @@ var createAutocompletePlugin = exports.createAutocompletePlugin = function creat
|
|
|
419
458
|
lastSuggestionLength = typedLength + prediction.length;
|
|
420
459
|
showGhostText(view, prediction, selection.from);
|
|
421
460
|
if (prediction !== lastShownGhostText) {
|
|
422
|
-
var _api$
|
|
461
|
+
var _api$analytics5;
|
|
423
462
|
lastShownGhostText = prediction;
|
|
424
|
-
api === null || api === void 0 || (_api$
|
|
463
|
+
api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 || _api$analytics5.actions.fireAnalyticsEvent({
|
|
425
464
|
action: _analytics.ACTION.SUGGESTION_VIEWED,
|
|
426
465
|
actionSubject: _analytics.ACTION_SUBJECT.CONTEXTUAL_TYPEAHEAD,
|
|
427
466
|
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
@@ -544,13 +583,17 @@ var createAutocompletePlugin = exports.createAutocompletePlugin = function creat
|
|
|
544
583
|
return false;
|
|
545
584
|
},
|
|
546
585
|
focus: function focus() {
|
|
547
|
-
|
|
586
|
+
var _options$useLocalMode, _options$useLocalMode2;
|
|
587
|
+
(0, _textPredictor.loadDefaultVocabulary)({
|
|
588
|
+
isLocalLLM: (_options$useLocalMode = options === null || options === void 0 ? void 0 : options.useLocalModel) !== null && _options$useLocalMode !== void 0 ? _options$useLocalMode : false
|
|
589
|
+
}).catch(function (error) {
|
|
548
590
|
(0, _monitoring.logException)(error, {
|
|
549
591
|
location: 'editor-plugin-autocomplete/loadDefaultVocabulary'
|
|
550
592
|
});
|
|
551
593
|
});
|
|
552
594
|
(0, _textPredictor.loadVectorsAsync)({
|
|
553
|
-
getBinaryUrl: options === null || options === void 0 ? void 0 : options.getVectorsBinaryUrl
|
|
595
|
+
getBinaryUrl: options === null || options === void 0 ? void 0 : options.getVectorsBinaryUrl,
|
|
596
|
+
isLocalLLM: (_options$useLocalMode2 = options === null || options === void 0 ? void 0 : options.useLocalModel) !== null && _options$useLocalMode2 !== void 0 ? _options$useLocalMode2 : false
|
|
554
597
|
}).catch(function (error) {
|
|
555
598
|
(0, _monitoring.logException)(error, {
|
|
556
599
|
location: 'editor-plugin-autocomplete/loadVectorsAsync'
|
|
@@ -18,7 +18,7 @@ var _debugMode = require("./debug-mode");
|
|
|
18
18
|
var _slowLaneClient = require("./slow-lane-client");
|
|
19
19
|
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; }
|
|
20
20
|
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; }
|
|
21
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var
|
|
21
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t6 in e) "default" !== _t6 && {}.hasOwnProperty.call(e, _t6) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t6)) && (i.get || i.set) ? o(f, _t6, i) : f[_t6] = e[_t6]); return f; })(e, t); }
|
|
22
22
|
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; } } }; }
|
|
23
23
|
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; } }
|
|
24
24
|
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; } /**
|
|
@@ -61,6 +61,19 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
|
|
|
61
61
|
|
|
62
62
|
// Same return type as createSlowLaneClient for drop-in compatibility
|
|
63
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Why the local engine failed to load/start.
|
|
66
|
+
*
|
|
67
|
+
* The first three are user-machine limitations (WebGPU missing, no compatible
|
|
68
|
+
* GPU adapter, GPU lacks the `shader-f16` feature the model needs);
|
|
69
|
+
* `insufficient_memory` is hit when weights don't fit in VRAM. The rest cover
|
|
70
|
+
* delivery/runtime failures unrelated to hardware.
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
/** Snapshot of the machine's WebGPU support, used to explain hardware limits. */
|
|
74
|
+
|
|
75
|
+
// Minimal WebGPU shape: lib.dom types aren't guaranteed in this build target.
|
|
76
|
+
|
|
64
77
|
// ─── Constants ───────────────────────────────────────────────────────────────
|
|
65
78
|
|
|
66
79
|
var DEFAULT_DEBOUNCE_MS = 300;
|
|
@@ -611,6 +624,8 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
|
|
|
611
624
|
debounceMs = _config$debounceMs === void 0 ? DEFAULT_DEBOUNCE_MS : _config$debounceMs,
|
|
612
625
|
onUpdate = config.onUpdate,
|
|
613
626
|
onStatus = config.onStatus,
|
|
627
|
+
onLoadError = config.onLoadError,
|
|
628
|
+
onLoadSuccess = config.onLoadSuccess,
|
|
614
629
|
_config$modelId = config.modelId,
|
|
615
630
|
modelId = _config$modelId === void 0 ? LOCAL_MLC_CAUSAL_MODEL_ID : _config$modelId,
|
|
616
631
|
customModelConfig = config.customModelConfig;
|
|
@@ -657,30 +672,193 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
|
|
|
657
672
|
}
|
|
658
673
|
onStatus === null || onStatus === void 0 || onStatus(message);
|
|
659
674
|
};
|
|
660
|
-
var
|
|
675
|
+
var bytesToMB = function bytesToMB(bytes) {
|
|
676
|
+
return typeof bytes === 'number' ? Math.round(bytes / (1024 * 1024)) : undefined;
|
|
677
|
+
};
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* Inspect the machine's WebGPU support so a load failure can be attributed
|
|
681
|
+
* to a concrete hardware/browser limitation rather than a generic error.
|
|
682
|
+
*/
|
|
683
|
+
var probeWebGpuCapabilities = /*#__PURE__*/function () {
|
|
661
684
|
var _ref8 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
|
|
662
|
-
var
|
|
685
|
+
var gpu, _adapter$limits, _adapter$limits2, adapter, vendor, architecture, _adapter$info, _adapter$requestAdapt, info, _t, _t2, _t3;
|
|
663
686
|
return _regenerator.default.wrap(function (_context2) {
|
|
664
687
|
while (1) switch (_context2.prev = _context2.next) {
|
|
665
688
|
case 0:
|
|
666
|
-
|
|
667
|
-
if (
|
|
668
|
-
// eslint-disable-next-line no-console
|
|
669
|
-
console.log("%c[LocalSlowLane] %c\uD83D\uDE80 Initialising MLC engine with models: ".concat(modelId, " (LM) + ").concat(LOCAL_MLC_EMBEDDING_MODEL_ID, " (embedder)"), 'color: #9c27b0; font-weight: bold;', 'color: inherit;');
|
|
670
|
-
}
|
|
671
|
-
onStatus === null || onStatus === void 0 || onStatus("Initialising models: ".concat(modelId, " + ").concat(LOCAL_MLC_EMBEDDING_MODEL_ID, "\u2026"));
|
|
672
|
-
if ('gpu' in navigator) {
|
|
689
|
+
gpu = navigator.gpu;
|
|
690
|
+
if (gpu) {
|
|
673
691
|
_context2.next = 1;
|
|
674
692
|
break;
|
|
675
693
|
}
|
|
676
|
-
|
|
694
|
+
return _context2.abrupt("return", {
|
|
695
|
+
available: false
|
|
696
|
+
});
|
|
677
697
|
case 1:
|
|
698
|
+
_context2.prev = 1;
|
|
678
699
|
_context2.next = 2;
|
|
700
|
+
return gpu.requestAdapter();
|
|
701
|
+
case 2:
|
|
702
|
+
adapter = _context2.sent;
|
|
703
|
+
if (adapter) {
|
|
704
|
+
_context2.next = 3;
|
|
705
|
+
break;
|
|
706
|
+
}
|
|
707
|
+
return _context2.abrupt("return", {
|
|
708
|
+
available: true,
|
|
709
|
+
adapterAvailable: false
|
|
710
|
+
});
|
|
711
|
+
case 3:
|
|
712
|
+
_context2.prev = 3;
|
|
713
|
+
if (!((_adapter$info = adapter.info) !== null && _adapter$info !== void 0)) {
|
|
714
|
+
_context2.next = 4;
|
|
715
|
+
break;
|
|
716
|
+
}
|
|
717
|
+
_t = _adapter$info;
|
|
718
|
+
_context2.next = 6;
|
|
719
|
+
break;
|
|
720
|
+
case 4:
|
|
721
|
+
_context2.next = 5;
|
|
722
|
+
return (_adapter$requestAdapt = adapter.requestAdapterInfo) === null || _adapter$requestAdapt === void 0 ? void 0 : _adapter$requestAdapt.call(adapter);
|
|
723
|
+
case 5:
|
|
724
|
+
_t = _context2.sent;
|
|
725
|
+
case 6:
|
|
726
|
+
info = _t;
|
|
727
|
+
vendor = (info === null || info === void 0 ? void 0 : info.vendor) || undefined;
|
|
728
|
+
architecture = (info === null || info === void 0 ? void 0 : info.architecture) || undefined;
|
|
729
|
+
_context2.next = 8;
|
|
730
|
+
break;
|
|
731
|
+
case 7:
|
|
732
|
+
_context2.prev = 7;
|
|
733
|
+
_t2 = _context2["catch"](3);
|
|
734
|
+
case 8:
|
|
735
|
+
return _context2.abrupt("return", {
|
|
736
|
+
available: true,
|
|
737
|
+
adapterAvailable: true,
|
|
738
|
+
shaderF16Supported: adapter.features.has('shader-f16'),
|
|
739
|
+
maxBufferSizeMB: bytesToMB((_adapter$limits = adapter.limits) === null || _adapter$limits === void 0 ? void 0 : _adapter$limits.maxBufferSize),
|
|
740
|
+
maxStorageBufferBindingSizeMB: bytesToMB((_adapter$limits2 = adapter.limits) === null || _adapter$limits2 === void 0 ? void 0 : _adapter$limits2.maxStorageBufferBindingSize),
|
|
741
|
+
vendor: vendor,
|
|
742
|
+
architecture: architecture
|
|
743
|
+
});
|
|
744
|
+
case 9:
|
|
745
|
+
_context2.prev = 9;
|
|
746
|
+
_t3 = _context2["catch"](1);
|
|
747
|
+
return _context2.abrupt("return", {
|
|
748
|
+
available: true,
|
|
749
|
+
adapterAvailable: false
|
|
750
|
+
});
|
|
751
|
+
case 10:
|
|
752
|
+
case "end":
|
|
753
|
+
return _context2.stop();
|
|
754
|
+
}
|
|
755
|
+
}, _callee2, null, [[1, 9], [3, 7]]);
|
|
756
|
+
}));
|
|
757
|
+
return function probeWebGpuCapabilities() {
|
|
758
|
+
return _ref8.apply(this, arguments);
|
|
759
|
+
};
|
|
760
|
+
}();
|
|
761
|
+
|
|
762
|
+
/** Map an MLC/WebLLM engine-creation error message to a coarse reason. */
|
|
763
|
+
var classifyEngineError = function classifyEngineError(message) {
|
|
764
|
+
var lower = message.toLowerCase();
|
|
765
|
+
if (lower.includes('loading chunk') || lower.includes('dynamically imported module') || lower.includes('dynamic import')) {
|
|
766
|
+
return 'module_load_failed';
|
|
767
|
+
}
|
|
768
|
+
if (lower.includes('out of memory') ||
|
|
769
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
770
|
+
/\boom\b/.test(lower) || lower.includes('allocation') || lower.includes('exceeds') || lower.includes('buffer size') || lower.includes('not enough memory')) {
|
|
771
|
+
return 'insufficient_memory';
|
|
772
|
+
}
|
|
773
|
+
// Pre-flight already returns missing_shader_f16 when the feature is absent,
|
|
774
|
+
// so only match the exact feature token here — not bare 'shader' (compile
|
|
775
|
+
// errors) or bare 'f16' (present in model ids like q0f16-MLC).
|
|
776
|
+
if (lower.includes('shader-f16') || lower.includes('shader_f16')) {
|
|
777
|
+
return 'missing_shader_f16';
|
|
778
|
+
}
|
|
779
|
+
if (lower.includes('fetch') || lower.includes('network') || lower.includes('download') || lower.includes('http') || lower.includes('cache')) {
|
|
780
|
+
return 'model_download_failed';
|
|
781
|
+
}
|
|
782
|
+
return 'init_failed';
|
|
783
|
+
};
|
|
784
|
+
|
|
785
|
+
// Canonical, controlled failure descriptions. We never emit the raw engine
|
|
786
|
+
// error into analytics — it can embed customer-context URLs/paths (HOT-120175)
|
|
787
|
+
// — so the analytics `message` is always one of these fixed strings.
|
|
788
|
+
var LOAD_FAILURE_MESSAGE = {
|
|
789
|
+
webgpu_unavailable: 'WebGPU is not available in this browser',
|
|
790
|
+
webgpu_no_adapter: 'No compatible WebGPU adapter found',
|
|
791
|
+
missing_shader_f16: 'GPU does not support the shader-f16 feature',
|
|
792
|
+
insufficient_memory: 'Insufficient GPU memory to load the model',
|
|
793
|
+
model_download_failed: 'Failed to download model assets',
|
|
794
|
+
module_load_failed: 'Failed to load the web-llm runtime module',
|
|
795
|
+
init_failed: 'Model engine failed to initialise'
|
|
796
|
+
};
|
|
797
|
+
var handleLoadFailure = function handleLoadFailure(reason, capabilities, debugDetail) {
|
|
798
|
+
ready = false;
|
|
799
|
+
var message = LOAD_FAILURE_MESSAGE[reason];
|
|
800
|
+
if ((0, _debugMode.isAutocompleteDebugEnabled)()) {
|
|
801
|
+
// eslint-disable-next-line no-console
|
|
802
|
+
console.log("[LocalSlowLane] Engine initialisation failed (".concat(reason, "): ").concat(debugDetail !== null && debugDetail !== void 0 ? debugDetail : message));
|
|
803
|
+
}
|
|
804
|
+
onStatus === null || onStatus === void 0 || onStatus("Engine initialisation failed: ".concat(message));
|
|
805
|
+
onLoadError === null || onLoadError === void 0 || onLoadError({
|
|
806
|
+
reason: reason,
|
|
807
|
+
message: message,
|
|
808
|
+
modelId: modelId,
|
|
809
|
+
embeddingModelId: LOCAL_MLC_EMBEDDING_MODEL_ID,
|
|
810
|
+
capabilities: capabilities
|
|
811
|
+
});
|
|
812
|
+
engineInitPromise = null;
|
|
813
|
+
initFailed = true;
|
|
814
|
+
};
|
|
815
|
+
var initEngine = /*#__PURE__*/function () {
|
|
816
|
+
var _ref9 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
|
|
817
|
+
var capabilities, startTime, _yield$Promise$all3, _yield$Promise$all4, _yield$Promise$all4$, MLCEngineCtor, prebuiltAppConfig, customModelRecord, appConfig, newEngine, loadDurationMs, errorMsg, _t4;
|
|
818
|
+
return _regenerator.default.wrap(function (_context3) {
|
|
819
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
820
|
+
case 0:
|
|
821
|
+
_context3.next = 1;
|
|
822
|
+
return probeWebGpuCapabilities();
|
|
823
|
+
case 1:
|
|
824
|
+
capabilities = _context3.sent;
|
|
825
|
+
if (capabilities.available) {
|
|
826
|
+
_context3.next = 2;
|
|
827
|
+
break;
|
|
828
|
+
}
|
|
829
|
+
handleLoadFailure('webgpu_unavailable', capabilities);
|
|
830
|
+
return _context3.abrupt("return");
|
|
831
|
+
case 2:
|
|
832
|
+
if (!(capabilities.adapterAvailable === false)) {
|
|
833
|
+
_context3.next = 3;
|
|
834
|
+
break;
|
|
835
|
+
}
|
|
836
|
+
handleLoadFailure('webgpu_no_adapter', capabilities);
|
|
837
|
+
return _context3.abrupt("return");
|
|
838
|
+
case 3:
|
|
839
|
+
if (!(capabilities.shaderF16Supported === false)) {
|
|
840
|
+
_context3.next = 4;
|
|
841
|
+
break;
|
|
842
|
+
}
|
|
843
|
+
handleLoadFailure('missing_shader_f16', capabilities);
|
|
844
|
+
return _context3.abrupt("return");
|
|
845
|
+
case 4:
|
|
846
|
+
startTime = performance.now();
|
|
847
|
+
_context3.prev = 5;
|
|
848
|
+
if ((0, _debugMode.isAutocompleteDebugEnabled)()) {
|
|
849
|
+
// eslint-disable-next-line no-console
|
|
850
|
+
console.log("%c[LocalSlowLane] %c\uD83D\uDE80 Initialising MLC engine with models: ".concat(modelId, " (LM) + ").concat(LOCAL_MLC_EMBEDDING_MODEL_ID, " (embedder)"), 'color: #9c27b0; font-weight: bold;', 'color: inherit;');
|
|
851
|
+
}
|
|
852
|
+
onStatus === null || onStatus === void 0 || onStatus("Initialising models: ".concat(modelId, " + ").concat(LOCAL_MLC_EMBEDDING_MODEL_ID, "\u2026"));
|
|
853
|
+
|
|
854
|
+
// Fetch the web-llm runtime and the BE-parity lookup tables in parallel;
|
|
855
|
+
// both are dynamically imported so they stay out of the main editor chunk.
|
|
856
|
+
_context3.next = 6;
|
|
679
857
|
return Promise.all([Promise.resolve().then(function () {
|
|
680
858
|
return _interopRequireWildcard(require( /* webpackChunkName: "@atlaskit-internal_editor-plugin-autocomplete-mlc-web-llm" */'@mlc-ai/web-llm'));
|
|
681
859
|
}), loadBePayloadData()]);
|
|
682
|
-
case
|
|
683
|
-
_yield$Promise$all3 =
|
|
860
|
+
case 6:
|
|
861
|
+
_yield$Promise$all3 = _context3.sent;
|
|
684
862
|
_yield$Promise$all4 = (0, _slicedToArray2.default)(_yield$Promise$all3, 1);
|
|
685
863
|
_yield$Promise$all4$ = _yield$Promise$all4[0];
|
|
686
864
|
MLCEngineCtor = _yield$Promise$all4$.MLCEngine;
|
|
@@ -708,19 +886,20 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
|
|
|
708
886
|
initProgressCallback: initProgressCallback,
|
|
709
887
|
logitProcessorRegistry: new Map([[modelId, lmLogitsCapture]])
|
|
710
888
|
});
|
|
711
|
-
|
|
889
|
+
_context3.next = 7;
|
|
712
890
|
return newEngine.reload([modelId, LOCAL_MLC_EMBEDDING_MODEL_ID]);
|
|
713
|
-
case
|
|
891
|
+
case 7:
|
|
714
892
|
if (!destroyed) {
|
|
715
|
-
|
|
893
|
+
_context3.next = 8;
|
|
716
894
|
break;
|
|
717
895
|
}
|
|
718
896
|
// destroy() was called while we were loading — clean up
|
|
719
897
|
unloadEngine(newEngine);
|
|
720
|
-
return
|
|
721
|
-
case
|
|
898
|
+
return _context3.abrupt("return");
|
|
899
|
+
case 8:
|
|
722
900
|
engine = newEngine;
|
|
723
901
|
ready = true;
|
|
902
|
+
loadDurationMs = Math.round(performance.now() - startTime);
|
|
724
903
|
if ((0, _debugMode.isAutocompleteDebugEnabled)()) {
|
|
725
904
|
// eslint-disable-next-line no-console
|
|
726
905
|
console.log('%c[LocalSlowLane] %c✅ Both models loaded and ready', 'color: #9c27b0; font-weight: bold;', 'color: #4caf50;');
|
|
@@ -732,28 +911,27 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
|
|
|
732
911
|
console.log('%c[LocalSlowLane] %c🔢 Embedder →', 'color: #9c27b0; font-weight: bold;', 'color: #009688; font-weight: bold;', LOCAL_MLC_EMBEDDING_MODEL_ID);
|
|
733
912
|
}
|
|
734
913
|
onStatus === null || onStatus === void 0 || onStatus('Model loaded and ready.');
|
|
735
|
-
|
|
914
|
+
onLoadSuccess === null || onLoadSuccess === void 0 || onLoadSuccess({
|
|
915
|
+
modelId: modelId,
|
|
916
|
+
embeddingModelId: LOCAL_MLC_EMBEDDING_MODEL_ID,
|
|
917
|
+
loadDurationMs: loadDurationMs,
|
|
918
|
+
capabilities: capabilities
|
|
919
|
+
});
|
|
920
|
+
_context3.next = 10;
|
|
736
921
|
break;
|
|
737
|
-
case
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
errorMsg =
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
// eslint-disable-next-line no-console
|
|
744
|
-
console.log("[LocalSlowLane] Engine initialisation failed: ".concat(errorMsg));
|
|
745
|
-
}
|
|
746
|
-
onStatus === null || onStatus === void 0 || onStatus("Engine initialisation failed: ".concat(errorMsg));
|
|
747
|
-
engineInitPromise = null;
|
|
748
|
-
initFailed = true;
|
|
749
|
-
case 6:
|
|
922
|
+
case 9:
|
|
923
|
+
_context3.prev = 9;
|
|
924
|
+
_t4 = _context3["catch"](5);
|
|
925
|
+
errorMsg = _t4 instanceof Error ? _t4.message : String(_t4);
|
|
926
|
+
handleLoadFailure(classifyEngineError(errorMsg), capabilities, errorMsg);
|
|
927
|
+
case 10:
|
|
750
928
|
case "end":
|
|
751
|
-
return
|
|
929
|
+
return _context3.stop();
|
|
752
930
|
}
|
|
753
|
-
},
|
|
931
|
+
}, _callee3, null, [[5, 9]]);
|
|
754
932
|
}));
|
|
755
933
|
return function initEngine() {
|
|
756
|
-
return
|
|
934
|
+
return _ref9.apply(this, arguments);
|
|
757
935
|
};
|
|
758
936
|
}();
|
|
759
937
|
var ensureEngineInitialized = function ensureEngineInitialized() {
|
|
@@ -780,16 +958,16 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
|
|
|
780
958
|
* 384-d semantic vector (passage-encoded; see `wrapForArctic`).
|
|
781
959
|
*/
|
|
782
960
|
var runInference = /*#__PURE__*/function () {
|
|
783
|
-
var
|
|
784
|
-
var lmText, semanticText, arcticInput, captureCompletionTime, _data, tStart, tLmDone, tEmbDone, _yield$Promise$all5, _yield$Promise$all6, embeddingResponse, rawLogits, payload, embedding, sumSq, i, topTokens, errorMsg,
|
|
785
|
-
return _regenerator.default.wrap(function (
|
|
786
|
-
while (1) switch (
|
|
961
|
+
var _ref0 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(text, requestId) {
|
|
962
|
+
var lmText, semanticText, arcticInput, captureCompletionTime, _data, tStart, tLmDone, tEmbDone, _yield$Promise$all5, _yield$Promise$all6, embeddingResponse, rawLogits, payload, embedding, sumSq, i, topTokens, errorMsg, _t5;
|
|
963
|
+
return _regenerator.default.wrap(function (_context4) {
|
|
964
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
787
965
|
case 0:
|
|
788
966
|
if (!(!engine || destroyed)) {
|
|
789
|
-
|
|
967
|
+
_context4.next = 1;
|
|
790
968
|
break;
|
|
791
969
|
}
|
|
792
|
-
return
|
|
970
|
+
return _context4.abrupt("return");
|
|
793
971
|
case 1:
|
|
794
972
|
// Clear the capture buffer so we read only this pass's logits. The engine
|
|
795
973
|
// serialises per-model requests and updateContext is debounced, so the
|
|
@@ -816,11 +994,11 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
|
|
|
816
994
|
// eslint-disable-next-line no-console
|
|
817
995
|
console.log("%c[LocalSlowLane] %c\uD83E\uDDE0 LM input (".concat(lmText.length, " chars, ").concat(splitOnWhitespace(lmText).length, " words): \"").concat(lmText.length > 100 ? "".concat(lmText.slice(0, 100), "\u2026") : lmText, "\""), 'color: #9c27b0; font-weight: bold;', 'color: #2196f3;');
|
|
818
996
|
}
|
|
819
|
-
|
|
997
|
+
_context4.prev = 2;
|
|
820
998
|
tStart = performance.now();
|
|
821
999
|
tLmDone = 0;
|
|
822
1000
|
tEmbDone = 0;
|
|
823
|
-
|
|
1001
|
+
_context4.next = 3;
|
|
824
1002
|
return Promise.all([captureCompletionTime(engine.completions.create({
|
|
825
1003
|
model: modelId,
|
|
826
1004
|
prompt: lmText,
|
|
@@ -836,7 +1014,7 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
|
|
|
836
1014
|
tEmbDone = resolvedAt;
|
|
837
1015
|
})]);
|
|
838
1016
|
case 3:
|
|
839
|
-
_yield$Promise$all5 =
|
|
1017
|
+
_yield$Promise$all5 = _context4.sent;
|
|
840
1018
|
_yield$Promise$all6 = (0, _slicedToArray2.default)(_yield$Promise$all5, 2);
|
|
841
1019
|
embeddingResponse = _yield$Promise$all6[1];
|
|
842
1020
|
if ((0, _debugMode.isAutocompleteDebugEnabled)()) {
|
|
@@ -846,10 +1024,10 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
|
|
|
846
1024
|
|
|
847
1025
|
// Discard stale results
|
|
848
1026
|
if (!(requestId < latestRequestId || destroyed)) {
|
|
849
|
-
|
|
1027
|
+
_context4.next = 4;
|
|
850
1028
|
break;
|
|
851
1029
|
}
|
|
852
|
-
return
|
|
1030
|
+
return _context4.abrupt("return");
|
|
853
1031
|
case 4:
|
|
854
1032
|
// ── LM logits: whole-word BE-parity payload ──────────────────
|
|
855
1033
|
rawLogits = lmLogitsCapture.captured;
|
|
@@ -883,17 +1061,17 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
|
|
|
883
1061
|
// eslint-disable-next-line no-console
|
|
884
1062
|
console.log(storedLmLogits ? "\u2705 lm_logits: ".concat(Object.keys(storedLmLogits).length, " words") : '❌ No lm_logits');
|
|
885
1063
|
if (storedLmLogits) {
|
|
886
|
-
topTokens = Object.entries(storedLmLogits).sort(function (
|
|
887
|
-
var _ref10 = (0, _slicedToArray2.default)(_ref0, 2),
|
|
888
|
-
a = _ref10[1];
|
|
1064
|
+
topTokens = Object.entries(storedLmLogits).sort(function (_ref1, _ref10) {
|
|
889
1065
|
var _ref11 = (0, _slicedToArray2.default)(_ref1, 2),
|
|
890
|
-
|
|
1066
|
+
a = _ref11[1];
|
|
1067
|
+
var _ref12 = (0, _slicedToArray2.default)(_ref10, 2),
|
|
1068
|
+
b = _ref12[1];
|
|
891
1069
|
return b - a;
|
|
892
1070
|
}).slice(0, 10); // eslint-disable-next-line no-console
|
|
893
|
-
console.log('Top 10 predictions:', topTokens.map(function (
|
|
894
|
-
var
|
|
895
|
-
t =
|
|
896
|
-
p =
|
|
1071
|
+
console.log('Top 10 predictions:', topTokens.map(function (_ref13) {
|
|
1072
|
+
var _ref14 = (0, _slicedToArray2.default)(_ref13, 2),
|
|
1073
|
+
t = _ref14[0],
|
|
1074
|
+
p = _ref14[1];
|
|
897
1075
|
return "".concat(t, ": ").concat((p * 100).toFixed(1), "%");
|
|
898
1076
|
}).join(', '));
|
|
899
1077
|
}
|
|
@@ -905,16 +1083,16 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
|
|
|
905
1083
|
hasVector: storedContextVector !== null,
|
|
906
1084
|
hasLmLogits: storedLmLogits !== null
|
|
907
1085
|
});
|
|
908
|
-
|
|
1086
|
+
_context4.next = 7;
|
|
909
1087
|
break;
|
|
910
1088
|
case 5:
|
|
911
|
-
|
|
912
|
-
|
|
1089
|
+
_context4.prev = 5;
|
|
1090
|
+
_t5 = _context4["catch"](2);
|
|
913
1091
|
if (!(requestId < latestRequestId || destroyed)) {
|
|
914
|
-
|
|
1092
|
+
_context4.next = 6;
|
|
915
1093
|
break;
|
|
916
1094
|
}
|
|
917
|
-
return
|
|
1095
|
+
return _context4.abrupt("return");
|
|
918
1096
|
case 6:
|
|
919
1097
|
storedContextVector = null;
|
|
920
1098
|
storedLmLogits = null;
|
|
@@ -923,19 +1101,19 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
|
|
|
923
1101
|
hasVector: false,
|
|
924
1102
|
hasLmLogits: false
|
|
925
1103
|
});
|
|
926
|
-
errorMsg =
|
|
1104
|
+
errorMsg = _t5 instanceof Error ? _t5.message : String(_t5);
|
|
927
1105
|
if ((0, _debugMode.isAutocompleteDebugEnabled)()) {
|
|
928
1106
|
// eslint-disable-next-line no-console
|
|
929
1107
|
console.log("%c[LocalSlowLane] %c\u274C Inference error (request #".concat(requestId, "): ").concat(errorMsg), 'color: #9c27b0; font-weight: bold;', 'color: #f44336;');
|
|
930
1108
|
}
|
|
931
1109
|
case 7:
|
|
932
1110
|
case "end":
|
|
933
|
-
return
|
|
1111
|
+
return _context4.stop();
|
|
934
1112
|
}
|
|
935
|
-
},
|
|
1113
|
+
}, _callee4, null, [[2, 5]]);
|
|
936
1114
|
}));
|
|
937
1115
|
return function runInference(_x, _x2) {
|
|
938
|
-
return
|
|
1116
|
+
return _ref0.apply(this, arguments);
|
|
939
1117
|
};
|
|
940
1118
|
}();
|
|
941
1119
|
|