@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
|
@@ -55,6 +55,19 @@ import { isWordBoundary } from './slow-lane-client';
|
|
|
55
55
|
|
|
56
56
|
// Same return type as createSlowLaneClient for drop-in compatibility
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Why the local engine failed to load/start.
|
|
60
|
+
*
|
|
61
|
+
* The first three are user-machine limitations (WebGPU missing, no compatible
|
|
62
|
+
* GPU adapter, GPU lacks the `shader-f16` feature the model needs);
|
|
63
|
+
* `insufficient_memory` is hit when weights don't fit in VRAM. The rest cover
|
|
64
|
+
* delivery/runtime failures unrelated to hardware.
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
/** Snapshot of the machine's WebGPU support, used to explain hardware limits. */
|
|
68
|
+
|
|
69
|
+
// Minimal WebGPU shape: lib.dom types aren't guaranteed in this build target.
|
|
70
|
+
|
|
58
71
|
// ─── Constants ───────────────────────────────────────────────────────────────
|
|
59
72
|
|
|
60
73
|
var DEFAULT_DEBOUNCE_MS = 300;
|
|
@@ -601,6 +614,8 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
|
|
|
601
614
|
debounceMs = _config$debounceMs === void 0 ? DEFAULT_DEBOUNCE_MS : _config$debounceMs,
|
|
602
615
|
onUpdate = config.onUpdate,
|
|
603
616
|
onStatus = config.onStatus,
|
|
617
|
+
onLoadError = config.onLoadError,
|
|
618
|
+
onLoadSuccess = config.onLoadSuccess,
|
|
604
619
|
_config$modelId = config.modelId,
|
|
605
620
|
modelId = _config$modelId === void 0 ? LOCAL_MLC_CAUSAL_MODEL_ID : _config$modelId,
|
|
606
621
|
customModelConfig = config.customModelConfig;
|
|
@@ -647,28 +662,191 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
|
|
|
647
662
|
}
|
|
648
663
|
onStatus === null || onStatus === void 0 || onStatus(message);
|
|
649
664
|
};
|
|
650
|
-
var
|
|
665
|
+
var bytesToMB = function bytesToMB(bytes) {
|
|
666
|
+
return typeof bytes === 'number' ? Math.round(bytes / (1024 * 1024)) : undefined;
|
|
667
|
+
};
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* Inspect the machine's WebGPU support so a load failure can be attributed
|
|
671
|
+
* to a concrete hardware/browser limitation rather than a generic error.
|
|
672
|
+
*/
|
|
673
|
+
var probeWebGpuCapabilities = /*#__PURE__*/function () {
|
|
651
674
|
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
652
|
-
var
|
|
675
|
+
var gpu, _adapter$limits, _adapter$limits2, adapter, vendor, architecture, _adapter$info, _adapter$requestAdapt, info, _t, _t2, _t3;
|
|
653
676
|
return _regeneratorRuntime.wrap(function (_context2) {
|
|
654
677
|
while (1) switch (_context2.prev = _context2.next) {
|
|
655
678
|
case 0:
|
|
656
|
-
|
|
657
|
-
if (
|
|
658
|
-
// eslint-disable-next-line no-console
|
|
659
|
-
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;');
|
|
660
|
-
}
|
|
661
|
-
onStatus === null || onStatus === void 0 || onStatus("Initialising models: ".concat(modelId, " + ").concat(LOCAL_MLC_EMBEDDING_MODEL_ID, "\u2026"));
|
|
662
|
-
if ('gpu' in navigator) {
|
|
679
|
+
gpu = navigator.gpu;
|
|
680
|
+
if (gpu) {
|
|
663
681
|
_context2.next = 1;
|
|
664
682
|
break;
|
|
665
683
|
}
|
|
666
|
-
|
|
684
|
+
return _context2.abrupt("return", {
|
|
685
|
+
available: false
|
|
686
|
+
});
|
|
667
687
|
case 1:
|
|
688
|
+
_context2.prev = 1;
|
|
668
689
|
_context2.next = 2;
|
|
669
|
-
return
|
|
690
|
+
return gpu.requestAdapter();
|
|
691
|
+
case 2:
|
|
692
|
+
adapter = _context2.sent;
|
|
693
|
+
if (adapter) {
|
|
694
|
+
_context2.next = 3;
|
|
695
|
+
break;
|
|
696
|
+
}
|
|
697
|
+
return _context2.abrupt("return", {
|
|
698
|
+
available: true,
|
|
699
|
+
adapterAvailable: false
|
|
700
|
+
});
|
|
701
|
+
case 3:
|
|
702
|
+
_context2.prev = 3;
|
|
703
|
+
if (!((_adapter$info = adapter.info) !== null && _adapter$info !== void 0)) {
|
|
704
|
+
_context2.next = 4;
|
|
705
|
+
break;
|
|
706
|
+
}
|
|
707
|
+
_t = _adapter$info;
|
|
708
|
+
_context2.next = 6;
|
|
709
|
+
break;
|
|
710
|
+
case 4:
|
|
711
|
+
_context2.next = 5;
|
|
712
|
+
return (_adapter$requestAdapt = adapter.requestAdapterInfo) === null || _adapter$requestAdapt === void 0 ? void 0 : _adapter$requestAdapt.call(adapter);
|
|
713
|
+
case 5:
|
|
714
|
+
_t = _context2.sent;
|
|
715
|
+
case 6:
|
|
716
|
+
info = _t;
|
|
717
|
+
vendor = (info === null || info === void 0 ? void 0 : info.vendor) || undefined;
|
|
718
|
+
architecture = (info === null || info === void 0 ? void 0 : info.architecture) || undefined;
|
|
719
|
+
_context2.next = 8;
|
|
720
|
+
break;
|
|
721
|
+
case 7:
|
|
722
|
+
_context2.prev = 7;
|
|
723
|
+
_t2 = _context2["catch"](3);
|
|
724
|
+
case 8:
|
|
725
|
+
return _context2.abrupt("return", {
|
|
726
|
+
available: true,
|
|
727
|
+
adapterAvailable: true,
|
|
728
|
+
shaderF16Supported: adapter.features.has('shader-f16'),
|
|
729
|
+
maxBufferSizeMB: bytesToMB((_adapter$limits = adapter.limits) === null || _adapter$limits === void 0 ? void 0 : _adapter$limits.maxBufferSize),
|
|
730
|
+
maxStorageBufferBindingSizeMB: bytesToMB((_adapter$limits2 = adapter.limits) === null || _adapter$limits2 === void 0 ? void 0 : _adapter$limits2.maxStorageBufferBindingSize),
|
|
731
|
+
vendor: vendor,
|
|
732
|
+
architecture: architecture
|
|
733
|
+
});
|
|
734
|
+
case 9:
|
|
735
|
+
_context2.prev = 9;
|
|
736
|
+
_t3 = _context2["catch"](1);
|
|
737
|
+
return _context2.abrupt("return", {
|
|
738
|
+
available: true,
|
|
739
|
+
adapterAvailable: false
|
|
740
|
+
});
|
|
741
|
+
case 10:
|
|
742
|
+
case "end":
|
|
743
|
+
return _context2.stop();
|
|
744
|
+
}
|
|
745
|
+
}, _callee2, null, [[1, 9], [3, 7]]);
|
|
746
|
+
}));
|
|
747
|
+
return function probeWebGpuCapabilities() {
|
|
748
|
+
return _ref8.apply(this, arguments);
|
|
749
|
+
};
|
|
750
|
+
}();
|
|
751
|
+
|
|
752
|
+
/** Map an MLC/WebLLM engine-creation error message to a coarse reason. */
|
|
753
|
+
var classifyEngineError = function classifyEngineError(message) {
|
|
754
|
+
var lower = message.toLowerCase();
|
|
755
|
+
if (lower.includes('loading chunk') || lower.includes('dynamically imported module') || lower.includes('dynamic import')) {
|
|
756
|
+
return 'module_load_failed';
|
|
757
|
+
}
|
|
758
|
+
if (lower.includes('out of memory') ||
|
|
759
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
760
|
+
/\boom\b/.test(lower) || lower.includes('allocation') || lower.includes('exceeds') || lower.includes('buffer size') || lower.includes('not enough memory')) {
|
|
761
|
+
return 'insufficient_memory';
|
|
762
|
+
}
|
|
763
|
+
// Pre-flight already returns missing_shader_f16 when the feature is absent,
|
|
764
|
+
// so only match the exact feature token here — not bare 'shader' (compile
|
|
765
|
+
// errors) or bare 'f16' (present in model ids like q0f16-MLC).
|
|
766
|
+
if (lower.includes('shader-f16') || lower.includes('shader_f16')) {
|
|
767
|
+
return 'missing_shader_f16';
|
|
768
|
+
}
|
|
769
|
+
if (lower.includes('fetch') || lower.includes('network') || lower.includes('download') || lower.includes('http') || lower.includes('cache')) {
|
|
770
|
+
return 'model_download_failed';
|
|
771
|
+
}
|
|
772
|
+
return 'init_failed';
|
|
773
|
+
};
|
|
774
|
+
|
|
775
|
+
// Canonical, controlled failure descriptions. We never emit the raw engine
|
|
776
|
+
// error into analytics — it can embed customer-context URLs/paths (HOT-120175)
|
|
777
|
+
// — so the analytics `message` is always one of these fixed strings.
|
|
778
|
+
var LOAD_FAILURE_MESSAGE = {
|
|
779
|
+
webgpu_unavailable: 'WebGPU is not available in this browser',
|
|
780
|
+
webgpu_no_adapter: 'No compatible WebGPU adapter found',
|
|
781
|
+
missing_shader_f16: 'GPU does not support the shader-f16 feature',
|
|
782
|
+
insufficient_memory: 'Insufficient GPU memory to load the model',
|
|
783
|
+
model_download_failed: 'Failed to download model assets',
|
|
784
|
+
module_load_failed: 'Failed to load the web-llm runtime module',
|
|
785
|
+
init_failed: 'Model engine failed to initialise'
|
|
786
|
+
};
|
|
787
|
+
var handleLoadFailure = function handleLoadFailure(reason, capabilities, debugDetail) {
|
|
788
|
+
ready = false;
|
|
789
|
+
var message = LOAD_FAILURE_MESSAGE[reason];
|
|
790
|
+
if (isAutocompleteDebugEnabled()) {
|
|
791
|
+
// eslint-disable-next-line no-console
|
|
792
|
+
console.log("[LocalSlowLane] Engine initialisation failed (".concat(reason, "): ").concat(debugDetail !== null && debugDetail !== void 0 ? debugDetail : message));
|
|
793
|
+
}
|
|
794
|
+
onStatus === null || onStatus === void 0 || onStatus("Engine initialisation failed: ".concat(message));
|
|
795
|
+
onLoadError === null || onLoadError === void 0 || onLoadError({
|
|
796
|
+
reason: reason,
|
|
797
|
+
message: message,
|
|
798
|
+
modelId: modelId,
|
|
799
|
+
embeddingModelId: LOCAL_MLC_EMBEDDING_MODEL_ID,
|
|
800
|
+
capabilities: capabilities
|
|
801
|
+
});
|
|
802
|
+
engineInitPromise = null;
|
|
803
|
+
initFailed = true;
|
|
804
|
+
};
|
|
805
|
+
var initEngine = /*#__PURE__*/function () {
|
|
806
|
+
var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
807
|
+
var capabilities, startTime, _yield$Promise$all3, _yield$Promise$all4, _yield$Promise$all4$, MLCEngineCtor, prebuiltAppConfig, customModelRecord, appConfig, newEngine, loadDurationMs, errorMsg, _t4;
|
|
808
|
+
return _regeneratorRuntime.wrap(function (_context3) {
|
|
809
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
810
|
+
case 0:
|
|
811
|
+
_context3.next = 1;
|
|
812
|
+
return probeWebGpuCapabilities();
|
|
813
|
+
case 1:
|
|
814
|
+
capabilities = _context3.sent;
|
|
815
|
+
if (capabilities.available) {
|
|
816
|
+
_context3.next = 2;
|
|
817
|
+
break;
|
|
818
|
+
}
|
|
819
|
+
handleLoadFailure('webgpu_unavailable', capabilities);
|
|
820
|
+
return _context3.abrupt("return");
|
|
670
821
|
case 2:
|
|
671
|
-
|
|
822
|
+
if (!(capabilities.adapterAvailable === false)) {
|
|
823
|
+
_context3.next = 3;
|
|
824
|
+
break;
|
|
825
|
+
}
|
|
826
|
+
handleLoadFailure('webgpu_no_adapter', capabilities);
|
|
827
|
+
return _context3.abrupt("return");
|
|
828
|
+
case 3:
|
|
829
|
+
if (!(capabilities.shaderF16Supported === false)) {
|
|
830
|
+
_context3.next = 4;
|
|
831
|
+
break;
|
|
832
|
+
}
|
|
833
|
+
handleLoadFailure('missing_shader_f16', capabilities);
|
|
834
|
+
return _context3.abrupt("return");
|
|
835
|
+
case 4:
|
|
836
|
+
startTime = performance.now();
|
|
837
|
+
_context3.prev = 5;
|
|
838
|
+
if (isAutocompleteDebugEnabled()) {
|
|
839
|
+
// eslint-disable-next-line no-console
|
|
840
|
+
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;');
|
|
841
|
+
}
|
|
842
|
+
onStatus === null || onStatus === void 0 || onStatus("Initialising models: ".concat(modelId, " + ").concat(LOCAL_MLC_EMBEDDING_MODEL_ID, "\u2026"));
|
|
843
|
+
|
|
844
|
+
// Fetch the web-llm runtime and the BE-parity lookup tables in parallel;
|
|
845
|
+
// both are dynamically imported so they stay out of the main editor chunk.
|
|
846
|
+
_context3.next = 6;
|
|
847
|
+
return Promise.all([import( /* webpackChunkName: "@atlaskit-internal_editor-plugin-autocomplete-mlc-web-llm" */'@mlc-ai/web-llm'), loadBePayloadData()]);
|
|
848
|
+
case 6:
|
|
849
|
+
_yield$Promise$all3 = _context3.sent;
|
|
672
850
|
_yield$Promise$all4 = _slicedToArray(_yield$Promise$all3, 1);
|
|
673
851
|
_yield$Promise$all4$ = _yield$Promise$all4[0];
|
|
674
852
|
MLCEngineCtor = _yield$Promise$all4$.MLCEngine;
|
|
@@ -696,19 +874,20 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
|
|
|
696
874
|
initProgressCallback: initProgressCallback,
|
|
697
875
|
logitProcessorRegistry: new Map([[modelId, lmLogitsCapture]])
|
|
698
876
|
});
|
|
699
|
-
|
|
877
|
+
_context3.next = 7;
|
|
700
878
|
return newEngine.reload([modelId, LOCAL_MLC_EMBEDDING_MODEL_ID]);
|
|
701
|
-
case
|
|
879
|
+
case 7:
|
|
702
880
|
if (!destroyed) {
|
|
703
|
-
|
|
881
|
+
_context3.next = 8;
|
|
704
882
|
break;
|
|
705
883
|
}
|
|
706
884
|
// destroy() was called while we were loading — clean up
|
|
707
885
|
unloadEngine(newEngine);
|
|
708
|
-
return
|
|
709
|
-
case
|
|
886
|
+
return _context3.abrupt("return");
|
|
887
|
+
case 8:
|
|
710
888
|
engine = newEngine;
|
|
711
889
|
ready = true;
|
|
890
|
+
loadDurationMs = Math.round(performance.now() - startTime);
|
|
712
891
|
if (isAutocompleteDebugEnabled()) {
|
|
713
892
|
// eslint-disable-next-line no-console
|
|
714
893
|
console.log('%c[LocalSlowLane] %c✅ Both models loaded and ready', 'color: #9c27b0; font-weight: bold;', 'color: #4caf50;');
|
|
@@ -720,28 +899,27 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
|
|
|
720
899
|
console.log('%c[LocalSlowLane] %c🔢 Embedder →', 'color: #9c27b0; font-weight: bold;', 'color: #009688; font-weight: bold;', LOCAL_MLC_EMBEDDING_MODEL_ID);
|
|
721
900
|
}
|
|
722
901
|
onStatus === null || onStatus === void 0 || onStatus('Model loaded and ready.');
|
|
723
|
-
|
|
902
|
+
onLoadSuccess === null || onLoadSuccess === void 0 || onLoadSuccess({
|
|
903
|
+
modelId: modelId,
|
|
904
|
+
embeddingModelId: LOCAL_MLC_EMBEDDING_MODEL_ID,
|
|
905
|
+
loadDurationMs: loadDurationMs,
|
|
906
|
+
capabilities: capabilities
|
|
907
|
+
});
|
|
908
|
+
_context3.next = 10;
|
|
724
909
|
break;
|
|
725
|
-
case
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
errorMsg =
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
// eslint-disable-next-line no-console
|
|
732
|
-
console.log("[LocalSlowLane] Engine initialisation failed: ".concat(errorMsg));
|
|
733
|
-
}
|
|
734
|
-
onStatus === null || onStatus === void 0 || onStatus("Engine initialisation failed: ".concat(errorMsg));
|
|
735
|
-
engineInitPromise = null;
|
|
736
|
-
initFailed = true;
|
|
737
|
-
case 6:
|
|
910
|
+
case 9:
|
|
911
|
+
_context3.prev = 9;
|
|
912
|
+
_t4 = _context3["catch"](5);
|
|
913
|
+
errorMsg = _t4 instanceof Error ? _t4.message : String(_t4);
|
|
914
|
+
handleLoadFailure(classifyEngineError(errorMsg), capabilities, errorMsg);
|
|
915
|
+
case 10:
|
|
738
916
|
case "end":
|
|
739
|
-
return
|
|
917
|
+
return _context3.stop();
|
|
740
918
|
}
|
|
741
|
-
},
|
|
919
|
+
}, _callee3, null, [[5, 9]]);
|
|
742
920
|
}));
|
|
743
921
|
return function initEngine() {
|
|
744
|
-
return
|
|
922
|
+
return _ref9.apply(this, arguments);
|
|
745
923
|
};
|
|
746
924
|
}();
|
|
747
925
|
var ensureEngineInitialized = function ensureEngineInitialized() {
|
|
@@ -768,16 +946,16 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
|
|
|
768
946
|
* 384-d semantic vector (passage-encoded; see `wrapForArctic`).
|
|
769
947
|
*/
|
|
770
948
|
var runInference = /*#__PURE__*/function () {
|
|
771
|
-
var
|
|
772
|
-
var lmText, semanticText, arcticInput, captureCompletionTime, _data, tStart, tLmDone, tEmbDone, _yield$Promise$all5, _yield$Promise$all6, embeddingResponse, rawLogits, payload, embedding, sumSq, i, topTokens, errorMsg,
|
|
773
|
-
return _regeneratorRuntime.wrap(function (
|
|
774
|
-
while (1) switch (
|
|
949
|
+
var _ref0 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(text, requestId) {
|
|
950
|
+
var lmText, semanticText, arcticInput, captureCompletionTime, _data, tStart, tLmDone, tEmbDone, _yield$Promise$all5, _yield$Promise$all6, embeddingResponse, rawLogits, payload, embedding, sumSq, i, topTokens, errorMsg, _t5;
|
|
951
|
+
return _regeneratorRuntime.wrap(function (_context4) {
|
|
952
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
775
953
|
case 0:
|
|
776
954
|
if (!(!engine || destroyed)) {
|
|
777
|
-
|
|
955
|
+
_context4.next = 1;
|
|
778
956
|
break;
|
|
779
957
|
}
|
|
780
|
-
return
|
|
958
|
+
return _context4.abrupt("return");
|
|
781
959
|
case 1:
|
|
782
960
|
// Clear the capture buffer so we read only this pass's logits. The engine
|
|
783
961
|
// serialises per-model requests and updateContext is debounced, so the
|
|
@@ -804,11 +982,11 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
|
|
|
804
982
|
// eslint-disable-next-line no-console
|
|
805
983
|
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;');
|
|
806
984
|
}
|
|
807
|
-
|
|
985
|
+
_context4.prev = 2;
|
|
808
986
|
tStart = performance.now();
|
|
809
987
|
tLmDone = 0;
|
|
810
988
|
tEmbDone = 0;
|
|
811
|
-
|
|
989
|
+
_context4.next = 3;
|
|
812
990
|
return Promise.all([captureCompletionTime(engine.completions.create({
|
|
813
991
|
model: modelId,
|
|
814
992
|
prompt: lmText,
|
|
@@ -824,7 +1002,7 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
|
|
|
824
1002
|
tEmbDone = resolvedAt;
|
|
825
1003
|
})]);
|
|
826
1004
|
case 3:
|
|
827
|
-
_yield$Promise$all5 =
|
|
1005
|
+
_yield$Promise$all5 = _context4.sent;
|
|
828
1006
|
_yield$Promise$all6 = _slicedToArray(_yield$Promise$all5, 2);
|
|
829
1007
|
embeddingResponse = _yield$Promise$all6[1];
|
|
830
1008
|
if (isAutocompleteDebugEnabled()) {
|
|
@@ -834,10 +1012,10 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
|
|
|
834
1012
|
|
|
835
1013
|
// Discard stale results
|
|
836
1014
|
if (!(requestId < latestRequestId || destroyed)) {
|
|
837
|
-
|
|
1015
|
+
_context4.next = 4;
|
|
838
1016
|
break;
|
|
839
1017
|
}
|
|
840
|
-
return
|
|
1018
|
+
return _context4.abrupt("return");
|
|
841
1019
|
case 4:
|
|
842
1020
|
// ── LM logits: whole-word BE-parity payload ──────────────────
|
|
843
1021
|
rawLogits = lmLogitsCapture.captured;
|
|
@@ -871,17 +1049,17 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
|
|
|
871
1049
|
// eslint-disable-next-line no-console
|
|
872
1050
|
console.log(storedLmLogits ? "\u2705 lm_logits: ".concat(Object.keys(storedLmLogits).length, " words") : '❌ No lm_logits');
|
|
873
1051
|
if (storedLmLogits) {
|
|
874
|
-
topTokens = Object.entries(storedLmLogits).sort(function (
|
|
875
|
-
var _ref10 = _slicedToArray(_ref0, 2),
|
|
876
|
-
a = _ref10[1];
|
|
1052
|
+
topTokens = Object.entries(storedLmLogits).sort(function (_ref1, _ref10) {
|
|
877
1053
|
var _ref11 = _slicedToArray(_ref1, 2),
|
|
878
|
-
|
|
1054
|
+
a = _ref11[1];
|
|
1055
|
+
var _ref12 = _slicedToArray(_ref10, 2),
|
|
1056
|
+
b = _ref12[1];
|
|
879
1057
|
return b - a;
|
|
880
1058
|
}).slice(0, 10); // eslint-disable-next-line no-console
|
|
881
|
-
console.log('Top 10 predictions:', topTokens.map(function (
|
|
882
|
-
var
|
|
883
|
-
t =
|
|
884
|
-
p =
|
|
1059
|
+
console.log('Top 10 predictions:', topTokens.map(function (_ref13) {
|
|
1060
|
+
var _ref14 = _slicedToArray(_ref13, 2),
|
|
1061
|
+
t = _ref14[0],
|
|
1062
|
+
p = _ref14[1];
|
|
885
1063
|
return "".concat(t, ": ").concat((p * 100).toFixed(1), "%");
|
|
886
1064
|
}).join(', '));
|
|
887
1065
|
}
|
|
@@ -893,16 +1071,16 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
|
|
|
893
1071
|
hasVector: storedContextVector !== null,
|
|
894
1072
|
hasLmLogits: storedLmLogits !== null
|
|
895
1073
|
});
|
|
896
|
-
|
|
1074
|
+
_context4.next = 7;
|
|
897
1075
|
break;
|
|
898
1076
|
case 5:
|
|
899
|
-
|
|
900
|
-
|
|
1077
|
+
_context4.prev = 5;
|
|
1078
|
+
_t5 = _context4["catch"](2);
|
|
901
1079
|
if (!(requestId < latestRequestId || destroyed)) {
|
|
902
|
-
|
|
1080
|
+
_context4.next = 6;
|
|
903
1081
|
break;
|
|
904
1082
|
}
|
|
905
|
-
return
|
|
1083
|
+
return _context4.abrupt("return");
|
|
906
1084
|
case 6:
|
|
907
1085
|
storedContextVector = null;
|
|
908
1086
|
storedLmLogits = null;
|
|
@@ -911,19 +1089,19 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
|
|
|
911
1089
|
hasVector: false,
|
|
912
1090
|
hasLmLogits: false
|
|
913
1091
|
});
|
|
914
|
-
errorMsg =
|
|
1092
|
+
errorMsg = _t5 instanceof Error ? _t5.message : String(_t5);
|
|
915
1093
|
if (isAutocompleteDebugEnabled()) {
|
|
916
1094
|
// eslint-disable-next-line no-console
|
|
917
1095
|
console.log("%c[LocalSlowLane] %c\u274C Inference error (request #".concat(requestId, "): ").concat(errorMsg), 'color: #9c27b0; font-weight: bold;', 'color: #f44336;');
|
|
918
1096
|
}
|
|
919
1097
|
case 7:
|
|
920
1098
|
case "end":
|
|
921
|
-
return
|
|
1099
|
+
return _context4.stop();
|
|
922
1100
|
}
|
|
923
|
-
},
|
|
1101
|
+
}, _callee4, null, [[2, 5]]);
|
|
924
1102
|
}));
|
|
925
1103
|
return function runInference(_x, _x2) {
|
|
926
|
-
return
|
|
1104
|
+
return _ref0.apply(this, arguments);
|
|
927
1105
|
};
|
|
928
1106
|
}();
|
|
929
1107
|
|
|
@@ -729,7 +729,8 @@ var unwrapJsonModule = function unwrapJsonModule(mod, shape) {
|
|
|
729
729
|
};
|
|
730
730
|
export var loadVectorsAsync = /*#__PURE__*/function () {
|
|
731
731
|
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(options) {
|
|
732
|
-
var
|
|
732
|
+
var _options$isLocalLLM;
|
|
733
|
+
var isLocalLLM, url, _wordIndexOuter$index, res, buffer, float32, wordIndexModule, wordIndexOuter, wordIndex, nWords, dim, _t, _t2;
|
|
733
734
|
return _regeneratorRuntime.wrap(function (_context) {
|
|
734
735
|
while (1) switch (_context.prev = _context.next) {
|
|
735
736
|
case 0:
|
|
@@ -747,8 +748,11 @@ export var loadVectorsAsync = /*#__PURE__*/function () {
|
|
|
747
748
|
console.warn('[text-predictor] loadVectorsAsync called without a getBinaryUrl — vectors will not load. Pass getVectorsBinaryUrl via plugin options.');
|
|
748
749
|
return _context.abrupt("return");
|
|
749
750
|
case 2:
|
|
751
|
+
isLocalLLM = (_options$isLocalLLM = options === null || options === void 0 ? void 0 : options.isLocalLLM) !== null && _options$isLocalLLM !== void 0 ? _options$isLocalLLM : false;
|
|
750
752
|
vectorsLoadStarted = true;
|
|
751
|
-
startExp(EXPERIENCE_NAME.LOAD_VECTORS, 'singleton'
|
|
753
|
+
startExp(EXPERIENCE_NAME.LOAD_VECTORS, 'singleton', {
|
|
754
|
+
isLocalLLM: isLocalLLM
|
|
755
|
+
});
|
|
752
756
|
_context.prev = 3;
|
|
753
757
|
_context.next = 4;
|
|
754
758
|
return options.getBinaryUrl();
|
|
@@ -761,6 +765,7 @@ export var loadVectorsAsync = /*#__PURE__*/function () {
|
|
|
761
765
|
_t = _context["catch"](3);
|
|
762
766
|
vectorsLoadStarted = false;
|
|
763
767
|
failExp(EXPERIENCE_NAME.LOAD_VECTORS, 'singleton', {
|
|
768
|
+
isLocalLLM: isLocalLLM,
|
|
764
769
|
errorType: 'resolve_url'
|
|
765
770
|
});
|
|
766
771
|
// eslint-disable-next-line no-console
|
|
@@ -778,6 +783,7 @@ export var loadVectorsAsync = /*#__PURE__*/function () {
|
|
|
778
783
|
}
|
|
779
784
|
vectorsLoadStarted = false;
|
|
780
785
|
failExp(EXPERIENCE_NAME.LOAD_VECTORS, 'singleton', {
|
|
786
|
+
isLocalLLM: isLocalLLM,
|
|
781
787
|
status: res.status,
|
|
782
788
|
errorType: 'http_error'
|
|
783
789
|
});
|
|
@@ -810,6 +816,7 @@ export var loadVectorsAsync = /*#__PURE__*/function () {
|
|
|
810
816
|
dim: dim
|
|
811
817
|
};
|
|
812
818
|
succeedExp(EXPERIENCE_NAME.LOAD_VECTORS, 'singleton', {
|
|
819
|
+
isLocalLLM: isLocalLLM,
|
|
813
820
|
wordCount: nWords,
|
|
814
821
|
dim: dim,
|
|
815
822
|
sizeBytes: float32.byteLength
|
|
@@ -829,6 +836,7 @@ export var loadVectorsAsync = /*#__PURE__*/function () {
|
|
|
829
836
|
_t2 = _context["catch"](6);
|
|
830
837
|
vectorsLoadStarted = false;
|
|
831
838
|
failExp(EXPERIENCE_NAME.LOAD_VECTORS, 'singleton', {
|
|
839
|
+
isLocalLLM: isLocalLLM,
|
|
832
840
|
errorType: 'network'
|
|
833
841
|
});
|
|
834
842
|
// eslint-disable-next-line no-console
|
|
@@ -847,19 +855,23 @@ export var initVectors = function initVectors(store) {
|
|
|
847
855
|
vectorStore = store;
|
|
848
856
|
};
|
|
849
857
|
var vocabularyLoadPromise;
|
|
850
|
-
export var loadDefaultVocabulary = function loadDefaultVocabulary() {
|
|
858
|
+
export var loadDefaultVocabulary = function loadDefaultVocabulary(options) {
|
|
859
|
+
var _options$isLocalLLM2;
|
|
851
860
|
if (isInitialized) {
|
|
852
861
|
return Promise.resolve();
|
|
853
862
|
}
|
|
854
863
|
if (vocabularyLoadPromise) {
|
|
855
864
|
return vocabularyLoadPromise;
|
|
856
865
|
}
|
|
866
|
+
var isLocalLLM = (_options$isLocalLLM2 = options === null || options === void 0 ? void 0 : options.isLocalLLM) !== null && _options$isLocalLLM2 !== void 0 ? _options$isLocalLLM2 : false;
|
|
857
867
|
vocabularyLoadPromise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
858
868
|
var _yield$Promise$all, _yield$Promise$all2, vocabularyModule, l3VocabularyModule, vocabularyData, l3VocabularyData, terms, _t3;
|
|
859
869
|
return _regeneratorRuntime.wrap(function (_context2) {
|
|
860
870
|
while (1) switch (_context2.prev = _context2.next) {
|
|
861
871
|
case 0:
|
|
862
|
-
startExp(EXPERIENCE_NAME.LOAD_VOCABULARY, 'singleton'
|
|
872
|
+
startExp(EXPERIENCE_NAME.LOAD_VOCABULARY, 'singleton', {
|
|
873
|
+
isLocalLLM: isLocalLLM
|
|
874
|
+
});
|
|
863
875
|
_context2.prev = 1;
|
|
864
876
|
_context2.next = 2;
|
|
865
877
|
return Promise.all([import( /* webpackChunkName: "@atlaskit-internal_editor-plugin-autocomplete-vocabulary-10k" */'./data/vocabulary_10k.json'), import( /* webpackChunkName: "@atlaskit-internal_editor-plugin-autocomplete-l3-vocabulary" */'./data/l3_vocabulary.json')]);
|
|
@@ -894,6 +906,7 @@ export var loadDefaultVocabulary = function loadDefaultVocabulary() {
|
|
|
894
906
|
terms: terms
|
|
895
907
|
});
|
|
896
908
|
succeedExp(EXPERIENCE_NAME.LOAD_VOCABULARY, 'singleton', {
|
|
909
|
+
isLocalLLM: isLocalLLM,
|
|
897
910
|
l2WordCount: terms.length,
|
|
898
911
|
l3WordCount: l3VocabularyData.length
|
|
899
912
|
});
|
|
@@ -903,6 +916,7 @@ export var loadDefaultVocabulary = function loadDefaultVocabulary() {
|
|
|
903
916
|
_context2.prev = 4;
|
|
904
917
|
_t3 = _context2["catch"](1);
|
|
905
918
|
failExp(EXPERIENCE_NAME.LOAD_VOCABULARY, 'singleton', {
|
|
919
|
+
isLocalLLM: isLocalLLM,
|
|
906
920
|
errorType: 'parse_error'
|
|
907
921
|
});
|
|
908
922
|
// Allow a later call to retry the load rather than caching the failure.
|
|
@@ -60,6 +60,10 @@ export interface LocalSlowLaneClientConfig {
|
|
|
60
60
|
* `customModelConfig` with the model URL and WASM library URL.
|
|
61
61
|
*/
|
|
62
62
|
modelId?: string;
|
|
63
|
+
/** Callback fired when the engine fails to load/start. */
|
|
64
|
+
onLoadError?: (error: LocalSlowLaneLoadError) => void;
|
|
65
|
+
/** Callback fired when the engine successfully loads and is ready. */
|
|
66
|
+
onLoadSuccess?: (info: LocalSlowLaneLoadSuccess) => void;
|
|
63
67
|
/** Callback fired with status messages (model loading progress, etc.). */
|
|
64
68
|
onStatus?: (message: string) => void;
|
|
65
69
|
/** Callback fired when inference returns new results. */
|
|
@@ -81,6 +85,54 @@ export interface LocalSlowLaneClient {
|
|
|
81
85
|
setLmLogits: (logits: Record<string, number> | null) => void;
|
|
82
86
|
updateContext: (text: string) => void;
|
|
83
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Why the local engine failed to load/start.
|
|
90
|
+
*
|
|
91
|
+
* The first three are user-machine limitations (WebGPU missing, no compatible
|
|
92
|
+
* GPU adapter, GPU lacks the `shader-f16` feature the model needs);
|
|
93
|
+
* `insufficient_memory` is hit when weights don't fit in VRAM. The rest cover
|
|
94
|
+
* delivery/runtime failures unrelated to hardware.
|
|
95
|
+
*/
|
|
96
|
+
export type LocalSlowLaneLoadErrorReason = 'webgpu_unavailable' | 'webgpu_no_adapter' | 'missing_shader_f16' | 'insufficient_memory' | 'model_download_failed' | 'module_load_failed' | 'init_failed';
|
|
97
|
+
/** Snapshot of the machine's WebGPU support, used to explain hardware limits. */
|
|
98
|
+
export interface WebGpuCapabilities {
|
|
99
|
+
/** Whether `navigator.gpu.requestAdapter()` returned a usable adapter. */
|
|
100
|
+
adapterAvailable?: boolean;
|
|
101
|
+
/** GPU architecture reported by the adapter (e.g. "metal-3", "rdna2"). */
|
|
102
|
+
architecture?: string;
|
|
103
|
+
/** Whether `navigator.gpu` exists at all. */
|
|
104
|
+
available: boolean;
|
|
105
|
+
/** Largest single GPU buffer the adapter allows, in MB. */
|
|
106
|
+
maxBufferSizeMB?: number;
|
|
107
|
+
/** Largest storage-buffer binding the adapter allows, in MB. */
|
|
108
|
+
maxStorageBufferBindingSizeMB?: number;
|
|
109
|
+
/** Whether the adapter exposes the `shader-f16` feature the model requires. */
|
|
110
|
+
shaderF16Supported?: boolean;
|
|
111
|
+
/** GPU vendor reported by the adapter (e.g. "apple", "intel"). */
|
|
112
|
+
vendor?: string;
|
|
113
|
+
}
|
|
114
|
+
export interface LocalSlowLaneLoadError {
|
|
115
|
+
/** WebGPU support snapshot — explains hardware limitations behind the failure. */
|
|
116
|
+
capabilities: WebGpuCapabilities;
|
|
117
|
+
/** Semantic embedder loaded alongside the causal LM (loads atomically). */
|
|
118
|
+
embeddingModelId: string;
|
|
119
|
+
/** Canonical, controlled failure description (never raw error text). */
|
|
120
|
+
message: string;
|
|
121
|
+
/** Causal LM identifier that failed to load. */
|
|
122
|
+
modelId: string;
|
|
123
|
+
/** Coarse, privacy-safe failure category. */
|
|
124
|
+
reason: LocalSlowLaneLoadErrorReason;
|
|
125
|
+
}
|
|
126
|
+
export interface LocalSlowLaneLoadSuccess {
|
|
127
|
+
/** WebGPU support snapshot for the machine that loaded the model. */
|
|
128
|
+
capabilities: WebGpuCapabilities;
|
|
129
|
+
/** Semantic embedder loaded alongside the causal LM (loads atomically). */
|
|
130
|
+
embeddingModelId: string;
|
|
131
|
+
/** Model engine load time in ms (excludes the WebGPU capability probe). */
|
|
132
|
+
loadDurationMs: number;
|
|
133
|
+
/** Causal LM identifier that loaded. */
|
|
134
|
+
modelId: string;
|
|
135
|
+
}
|
|
84
136
|
export declare const LOCAL_MLC_CAUSAL_MODEL_ID = "SmolLM2-135M-Instruct-q0f16-MLC";
|
|
85
137
|
/**
|
|
86
138
|
* MLC ID for the semantic embedder (Snowflake Arctic Embed S, batch=4 variant).
|
|
@@ -82,7 +82,10 @@ export declare const ingestDocumentPage: (pageContent: string | undefined) => vo
|
|
|
82
82
|
export declare const predict: (textBefore: string) => string | null;
|
|
83
83
|
export declare const loadVectorsAsync: (options?: {
|
|
84
84
|
getBinaryUrl?: () => Promise<string>;
|
|
85
|
+
isLocalLLM?: boolean;
|
|
85
86
|
}) => Promise<void>;
|
|
86
87
|
export declare const initVectors: (store: VectorStore) => void;
|
|
87
|
-
export declare const loadDefaultVocabulary: (
|
|
88
|
+
export declare const loadDefaultVocabulary: (options?: {
|
|
89
|
+
isLocalLLM?: boolean;
|
|
90
|
+
}) => Promise<void>;
|
|
88
91
|
export {};
|