@atlaskit/editor-plugin-autocomplete 2.5.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CANONICAL_FIX__DO_NOT_USE_ME_A/package.json +15 -0
- package/CANONICAL_FIX__DO_NOT_USE_ME_B/package.json +15 -0
- package/CANONICAL_FIX__DO_NOT_USE_ME_C/package.json +15 -0
- package/CHANGELOG.md +14 -0
- package/dist/cjs/pm-plugins/local-slow-lane-client.js +40 -45
- package/dist/cjs/pm-plugins/slow-lane-client.js +20 -20
- package/dist/cjs/pm-plugins/text-predictor.js +29 -29
- package/dist/es2019/pm-plugins/local-slow-lane-client.js +4 -8
- package/dist/esm/pm-plugins/local-slow-lane-client.js +39 -43
- package/dist/esm/pm-plugins/slow-lane-client.js +20 -20
- package/dist/esm/pm-plugins/text-predictor.js +29 -29
- package/package.json +3 -3
- package/src/pm-plugins/local-slow-lane-client.ts +4 -9
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atlaskit/editor-plugin-autocomplete/CANONICAL_FIX__DO_NOT_USE_ME_A",
|
|
3
|
+
"main": "../dist/cjs/pm-plugins/autocomplete-plugin.js",
|
|
4
|
+
"module": "../dist/esm/pm-plugins/autocomplete-plugin.js",
|
|
5
|
+
"module:es2019": "../dist/es2019/pm-plugins/autocomplete-plugin.js",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"types": "../dist/types/pm-plugins/autocomplete-plugin.d.ts",
|
|
8
|
+
"typesVersions": {
|
|
9
|
+
">=4.5 <5.9": {
|
|
10
|
+
"*": [
|
|
11
|
+
"../dist/types-ts4.5/pm-plugins/autocomplete-plugin.d.ts"
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atlaskit/editor-plugin-autocomplete/CANONICAL_FIX__DO_NOT_USE_ME_B",
|
|
3
|
+
"main": "../dist/cjs/pm-plugins/slow-lane-client.js",
|
|
4
|
+
"module": "../dist/esm/pm-plugins/slow-lane-client.js",
|
|
5
|
+
"module:es2019": "../dist/es2019/pm-plugins/slow-lane-client.js",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"types": "../dist/types/pm-plugins/slow-lane-client.d.ts",
|
|
8
|
+
"typesVersions": {
|
|
9
|
+
">=4.5 <5.9": {
|
|
10
|
+
"*": [
|
|
11
|
+
"../dist/types-ts4.5/pm-plugins/slow-lane-client.d.ts"
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atlaskit/editor-plugin-autocomplete/CANONICAL_FIX__DO_NOT_USE_ME_C",
|
|
3
|
+
"main": "../dist/cjs/pm-plugins/text-predictor.js",
|
|
4
|
+
"module": "../dist/esm/pm-plugins/text-predictor.js",
|
|
5
|
+
"module:es2019": "../dist/es2019/pm-plugins/text-predictor.js",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"types": "../dist/types/pm-plugins/text-predictor.d.ts",
|
|
8
|
+
"typesVersions": {
|
|
9
|
+
">=4.5 <5.9": {
|
|
10
|
+
"*": [
|
|
11
|
+
"../dist/types-ts4.5/pm-plugins/text-predictor.d.ts"
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-autocomplete
|
|
2
2
|
|
|
3
|
+
## 3.0.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 2.5.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`a87ba03d22d27`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a87ba03d22d27) -
|
|
14
|
+
Fix typecheck
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
|
|
3
17
|
## 2.5.1
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -18,7 +18,7 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
|
|
|
18
18
|
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; }
|
|
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" != _typeof(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" != _typeof(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 _t3 in e) "default" !== _t3 && {}.hasOwnProperty.call(e, _t3) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t3)) && (i.get || i.set) ? o(f, _t3, i) : f[_t3] = e[_t3]); return f; })(e, t); } /**
|
|
22
22
|
* Local Slow Lane Client: On-device inference via @mlc-ai/web-llm.
|
|
23
23
|
*
|
|
24
24
|
* Drop-in replacement for the network-based slow-lane-client. Instead of
|
|
@@ -45,11 +45,6 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
|
|
|
45
45
|
* The client exposes getContextVector() and getLmLogits() which are populated
|
|
46
46
|
* asynchronously after each updateContext() call.
|
|
47
47
|
*/
|
|
48
|
-
var startsWithAsciiLetter = function startsWithAsciiLetter(value) {
|
|
49
|
-
var firstChar = value.charCodeAt(0);
|
|
50
|
-
return firstChar >= 65 && firstChar <= 90 || firstChar >= 97 && firstChar <= 122;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
48
|
// ─── Types ───────────────────────────────────────────────────────────────────
|
|
54
49
|
|
|
55
50
|
// Same return type as createSlowLaneClient for drop-in compatibility
|
|
@@ -132,8 +127,8 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
|
|
|
132
127
|
};
|
|
133
128
|
var initEngine = /*#__PURE__*/function () {
|
|
134
129
|
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
135
|
-
var _yield$import, CreateMLCEngine, prebuiltAppConfig, customModelRecord, appConfig, errorMsg;
|
|
136
|
-
return _regenerator.default.wrap(function
|
|
130
|
+
var _yield$import, CreateMLCEngine, prebuiltAppConfig, customModelRecord, appConfig, errorMsg, _t;
|
|
131
|
+
return _regenerator.default.wrap(function (_context) {
|
|
137
132
|
while (1) switch (_context.prev = _context.next) {
|
|
138
133
|
case 0:
|
|
139
134
|
_context.prev = 0;
|
|
@@ -143,16 +138,16 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
|
|
|
143
138
|
}
|
|
144
139
|
onStatus === null || onStatus === void 0 || onStatus("Initialising model: ".concat(modelId, "\u2026"));
|
|
145
140
|
if ('gpu' in navigator) {
|
|
146
|
-
_context.next =
|
|
141
|
+
_context.next = 1;
|
|
147
142
|
break;
|
|
148
143
|
}
|
|
149
144
|
throw new Error('WebGPU not supported');
|
|
150
|
-
case
|
|
151
|
-
_context.next =
|
|
145
|
+
case 1:
|
|
146
|
+
_context.next = 2;
|
|
152
147
|
return Promise.resolve().then(function () {
|
|
153
148
|
return _interopRequireWildcard(require( /* webpackChunkName: "@atlaskit-internal_editor-plugin-autocomplete-mlc-web-llm" */'@mlc-ai/web-llm'));
|
|
154
149
|
});
|
|
155
|
-
case
|
|
150
|
+
case 2:
|
|
156
151
|
_yield$import = _context.sent;
|
|
157
152
|
CreateMLCEngine = _yield$import.CreateMLCEngine;
|
|
158
153
|
prebuiltAppConfig = _yield$import.prebuiltAppConfig;
|
|
@@ -172,34 +167,34 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
|
|
|
172
167
|
appConfig = {
|
|
173
168
|
model_list: [].concat((0, _toConsumableArray2.default)(prebuiltAppConfig.model_list), (0, _toConsumableArray2.default)(customModelRecord ? [customModelRecord] : []))
|
|
174
169
|
};
|
|
175
|
-
_context.next =
|
|
170
|
+
_context.next = 3;
|
|
176
171
|
return CreateMLCEngine(modelId, {
|
|
177
172
|
appConfig: appConfig,
|
|
178
173
|
initProgressCallback: initProgressCallback
|
|
179
174
|
});
|
|
180
|
-
case
|
|
175
|
+
case 3:
|
|
181
176
|
engine = _context.sent;
|
|
182
177
|
if (!destroyed) {
|
|
183
|
-
_context.next =
|
|
178
|
+
_context.next = 4;
|
|
184
179
|
break;
|
|
185
180
|
}
|
|
186
181
|
// destroy() was called while we were loading — clean up
|
|
187
182
|
unloadEngine(engine);
|
|
188
183
|
engine = null;
|
|
189
184
|
return _context.abrupt("return");
|
|
190
|
-
case
|
|
185
|
+
case 4:
|
|
191
186
|
ready = true;
|
|
192
187
|
if ((0, _debugMode.isAutocompleteDebugEnabled)()) {
|
|
193
188
|
// eslint-disable-next-line no-console
|
|
194
189
|
console.log('%c[LocalSlowLane] %c✅ MLC engine loaded and ready', 'color: #9c27b0; font-weight: bold;', 'color: #4caf50;');
|
|
195
190
|
}
|
|
196
191
|
onStatus === null || onStatus === void 0 || onStatus('Model loaded and ready.');
|
|
197
|
-
_context.next =
|
|
192
|
+
_context.next = 6;
|
|
198
193
|
break;
|
|
199
|
-
case
|
|
200
|
-
_context.prev =
|
|
201
|
-
|
|
202
|
-
errorMsg =
|
|
194
|
+
case 5:
|
|
195
|
+
_context.prev = 5;
|
|
196
|
+
_t = _context["catch"](0);
|
|
197
|
+
errorMsg = _t instanceof Error ? _t.message : String(_t);
|
|
203
198
|
ready = false;
|
|
204
199
|
if ((0, _debugMode.isAutocompleteDebugEnabled)()) {
|
|
205
200
|
// eslint-disable-next-line no-console
|
|
@@ -208,11 +203,11 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
|
|
|
208
203
|
onStatus === null || onStatus === void 0 || onStatus("Engine initialisation failed: ".concat(errorMsg));
|
|
209
204
|
engineInitPromise = null;
|
|
210
205
|
initFailed = true;
|
|
211
|
-
case
|
|
206
|
+
case 6:
|
|
212
207
|
case "end":
|
|
213
208
|
return _context.stop();
|
|
214
209
|
}
|
|
215
|
-
}, _callee, null, [[0,
|
|
210
|
+
}, _callee, null, [[0, 5]]);
|
|
216
211
|
}));
|
|
217
212
|
return function initEngine() {
|
|
218
213
|
return _ref.apply(this, arguments);
|
|
@@ -239,18 +234,18 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
|
|
|
239
234
|
*/
|
|
240
235
|
var runInference = /*#__PURE__*/function () {
|
|
241
236
|
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(text, requestId) {
|
|
242
|
-
var _response$choices, response, lmLogits, logprobsContent, tokenLogprobs, token, _iterator, _step, alt, _token, logitValues, topTokens, errorMsg;
|
|
243
|
-
return _regenerator.default.wrap(function
|
|
237
|
+
var _response$choices, response, lmLogits, logprobsContent, tokenLogprobs, token, _iterator, _step, alt, _token, logitValues, topTokens, errorMsg, _t2;
|
|
238
|
+
return _regenerator.default.wrap(function (_context2) {
|
|
244
239
|
while (1) switch (_context2.prev = _context2.next) {
|
|
245
240
|
case 0:
|
|
246
241
|
if (!(!engine || destroyed)) {
|
|
247
|
-
_context2.next =
|
|
242
|
+
_context2.next = 1;
|
|
248
243
|
break;
|
|
249
244
|
}
|
|
250
245
|
return _context2.abrupt("return");
|
|
251
|
-
case
|
|
252
|
-
_context2.prev =
|
|
253
|
-
_context2.next =
|
|
246
|
+
case 1:
|
|
247
|
+
_context2.prev = 1;
|
|
248
|
+
_context2.next = 2;
|
|
254
249
|
return engine.chat.completions.create({
|
|
255
250
|
messages: [{
|
|
256
251
|
role: 'user',
|
|
@@ -261,22 +256,22 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
|
|
|
261
256
|
top_logprobs: 5,
|
|
262
257
|
temperature: 0
|
|
263
258
|
});
|
|
264
|
-
case
|
|
259
|
+
case 2:
|
|
265
260
|
response = _context2.sent;
|
|
266
261
|
if (!(requestId < latestRequestId || destroyed)) {
|
|
267
|
-
_context2.next =
|
|
262
|
+
_context2.next = 3;
|
|
268
263
|
break;
|
|
269
264
|
}
|
|
270
265
|
return _context2.abrupt("return");
|
|
271
|
-
case
|
|
266
|
+
case 3:
|
|
272
267
|
// ── Extract LM logits ───────────────────────────────────────
|
|
273
268
|
lmLogits = {};
|
|
274
269
|
logprobsContent = (_response$choices = response.choices) === null || _response$choices === void 0 || (_response$choices = _response$choices[0]) === null || _response$choices === void 0 || (_response$choices = _response$choices.logprobs) === null || _response$choices === void 0 ? void 0 : _response$choices.content;
|
|
275
270
|
if (logprobsContent && logprobsContent.length > 0) {
|
|
276
271
|
tokenLogprobs = logprobsContent[0]; // Add the top token
|
|
277
272
|
if (tokenLogprobs.token) {
|
|
278
|
-
token = tokenLogprobs.token.trim().toLowerCase();
|
|
279
|
-
if (token.length > 0 &&
|
|
273
|
+
token = tokenLogprobs.token.trim().toLowerCase(); // @ts-ignore TS1501: Unicode regex flag requires a newer TS target than the declaration build uses.
|
|
274
|
+
if (token.length > 0 && /^[a-z\u017F\u212A]/i.test(token)) {
|
|
280
275
|
lmLogits[token] = Math.exp(tokenLogprobs.logprob);
|
|
281
276
|
}
|
|
282
277
|
}
|
|
@@ -287,8 +282,8 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
|
|
|
287
282
|
try {
|
|
288
283
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
289
284
|
alt = _step.value;
|
|
290
|
-
_token = alt.token.trim().toLowerCase();
|
|
291
|
-
if (_token.length > 0 &&
|
|
285
|
+
_token = alt.token.trim().toLowerCase(); // @ts-ignore TS1501: Unicode regex flag requires a newer TS target than the declaration build uses.
|
|
286
|
+
if (_token.length > 0 && /^[a-z\u017F\u212A]/i.test(_token)) {
|
|
292
287
|
lmLogits[_token] = Math.exp(alt.logprob);
|
|
293
288
|
}
|
|
294
289
|
}
|
|
@@ -346,17 +341,17 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
|
|
|
346
341
|
hasVector: storedContextVector !== null,
|
|
347
342
|
hasLmLogits: storedLmLogits !== null
|
|
348
343
|
});
|
|
349
|
-
_context2.next =
|
|
344
|
+
_context2.next = 6;
|
|
350
345
|
break;
|
|
351
|
-
case
|
|
352
|
-
_context2.prev =
|
|
353
|
-
|
|
346
|
+
case 4:
|
|
347
|
+
_context2.prev = 4;
|
|
348
|
+
_t2 = _context2["catch"](1);
|
|
354
349
|
if (!(requestId < latestRequestId)) {
|
|
355
|
-
_context2.next =
|
|
350
|
+
_context2.next = 5;
|
|
356
351
|
break;
|
|
357
352
|
}
|
|
358
353
|
return _context2.abrupt("return");
|
|
359
|
-
case
|
|
354
|
+
case 5:
|
|
360
355
|
storedContextVector = null;
|
|
361
356
|
storedLmLogits = null;
|
|
362
357
|
onUpdate === null || onUpdate === void 0 || onUpdate({
|
|
@@ -364,16 +359,16 @@ var createLocalSlowLaneClient = exports.createLocalSlowLaneClient = function cre
|
|
|
364
359
|
hasVector: false,
|
|
365
360
|
hasLmLogits: false
|
|
366
361
|
});
|
|
367
|
-
errorMsg =
|
|
362
|
+
errorMsg = _t2 instanceof Error ? _t2.message : String(_t2);
|
|
368
363
|
if ((0, _debugMode.isAutocompleteDebugEnabled)()) {
|
|
369
364
|
// eslint-disable-next-line no-console
|
|
370
365
|
console.log("%c[LocalSlowLane] %c\u274C Inference error (request #".concat(requestId, "): ").concat(errorMsg), 'color: #9c27b0; font-weight: bold;', 'color: #f44336;');
|
|
371
366
|
}
|
|
372
|
-
case
|
|
367
|
+
case 6:
|
|
373
368
|
case "end":
|
|
374
369
|
return _context2.stop();
|
|
375
370
|
}
|
|
376
|
-
}, _callee2, null, [[
|
|
371
|
+
}, _callee2, null, [[1, 4]]);
|
|
377
372
|
}));
|
|
378
373
|
return function runInference(_x, _x2) {
|
|
379
374
|
return _ref2.apply(this, arguments);
|
|
@@ -70,16 +70,16 @@ var createSlowLaneClient = exports.createSlowLaneClient = function createSlowLan
|
|
|
70
70
|
var inflightRequestId = null;
|
|
71
71
|
var doUpdateContext = /*#__PURE__*/function () {
|
|
72
72
|
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(text, requestId) {
|
|
73
|
-
var url, payload, res, data;
|
|
74
|
-
return _regenerator.default.wrap(function
|
|
73
|
+
var url, payload, res, data, _t;
|
|
74
|
+
return _regenerator.default.wrap(function (_context) {
|
|
75
75
|
while (1) switch (_context.prev = _context.next) {
|
|
76
76
|
case 0:
|
|
77
77
|
if (!(!text || text.trim().length === 0)) {
|
|
78
|
-
_context.next =
|
|
78
|
+
_context.next = 1;
|
|
79
79
|
break;
|
|
80
80
|
}
|
|
81
81
|
return _context.abrupt("return");
|
|
82
|
-
case
|
|
82
|
+
case 1:
|
|
83
83
|
// eslint-disable-next-line require-unicode-regexp
|
|
84
84
|
url = "".concat(baseUrl.replace(/\/$/, '')).concat(endpoint);
|
|
85
85
|
payload = {
|
|
@@ -99,17 +99,17 @@ var createSlowLaneClient = exports.createSlowLaneClient = function createSlowLan
|
|
|
99
99
|
// eslint-disable-next-line no-console
|
|
100
100
|
console.groupEnd();
|
|
101
101
|
}
|
|
102
|
-
_context.prev =
|
|
103
|
-
_context.next =
|
|
102
|
+
_context.prev = 2;
|
|
103
|
+
_context.next = 3;
|
|
104
104
|
return fetchFn(url, {
|
|
105
105
|
method: 'POST',
|
|
106
106
|
headers: headers,
|
|
107
107
|
body: JSON.stringify(payload)
|
|
108
108
|
});
|
|
109
|
-
case
|
|
109
|
+
case 3:
|
|
110
110
|
res = _context.sent;
|
|
111
111
|
if (res.ok) {
|
|
112
|
-
_context.next =
|
|
112
|
+
_context.next = 4;
|
|
113
113
|
break;
|
|
114
114
|
}
|
|
115
115
|
storedContextVector = null;
|
|
@@ -123,10 +123,10 @@ var createSlowLaneClient = exports.createSlowLaneClient = function createSlowLan
|
|
|
123
123
|
console.log("%c[SlowLane] %c\u274C Request failed (".concat(res.status, ")"), 'color: #9c27b0; font-weight: bold;', 'color: #f44336;');
|
|
124
124
|
}
|
|
125
125
|
return _context.abrupt("return");
|
|
126
|
-
case
|
|
127
|
-
_context.next =
|
|
126
|
+
case 4:
|
|
127
|
+
_context.next = 5;
|
|
128
128
|
return res.json();
|
|
129
|
-
case
|
|
129
|
+
case 5:
|
|
130
130
|
data = _context.sent;
|
|
131
131
|
if (data.semantic_vector && Array.isArray(data.semantic_vector)) {
|
|
132
132
|
storedContextVector = new Float32Array(data.semantic_vector);
|
|
@@ -159,11 +159,11 @@ var createSlowLaneClient = exports.createSlowLaneClient = function createSlowLan
|
|
|
159
159
|
hasLmLogits: storedLmLogits !== null
|
|
160
160
|
});
|
|
161
161
|
// eslint-disable-next-line no-unused-vars
|
|
162
|
-
_context.next =
|
|
162
|
+
_context.next = 7;
|
|
163
163
|
break;
|
|
164
|
-
case
|
|
165
|
-
_context.prev =
|
|
166
|
-
|
|
164
|
+
case 6:
|
|
165
|
+
_context.prev = 6;
|
|
166
|
+
_t = _context["catch"](2);
|
|
167
167
|
storedContextVector = null;
|
|
168
168
|
storedLmLogits = null;
|
|
169
169
|
(0, _ufo.failExp)(_ufo.EXPERIENCE_NAME.SLOW_LANE_FETCH, requestId, {
|
|
@@ -173,17 +173,17 @@ var createSlowLaneClient = exports.createSlowLaneClient = function createSlowLan
|
|
|
173
173
|
// eslint-disable-next-line no-console
|
|
174
174
|
console.log('%c[SlowLane] %c❌ Network error — context cleared', 'color: #9c27b0; font-weight: bold;', 'color: #f44336;');
|
|
175
175
|
}
|
|
176
|
-
case
|
|
177
|
-
_context.prev =
|
|
176
|
+
case 7:
|
|
177
|
+
_context.prev = 7;
|
|
178
178
|
if (inflightRequestId === requestId) {
|
|
179
179
|
inflightRequestId = null;
|
|
180
180
|
}
|
|
181
|
-
return _context.finish(
|
|
182
|
-
case
|
|
181
|
+
return _context.finish(7);
|
|
182
|
+
case 8:
|
|
183
183
|
case "end":
|
|
184
184
|
return _context.stop();
|
|
185
185
|
}
|
|
186
|
-
}, _callee, null, [[
|
|
186
|
+
}, _callee, null, [[2, 6, 7, 8]]);
|
|
187
187
|
}));
|
|
188
188
|
return function doUpdateContext(_x, _x2) {
|
|
189
189
|
return _ref.apply(this, arguments);
|
|
@@ -691,51 +691,51 @@ var predict = exports.predict = function predict(textBefore) {
|
|
|
691
691
|
|
|
692
692
|
var loadVectorsAsync = exports.loadVectorsAsync = /*#__PURE__*/function () {
|
|
693
693
|
var _ref6 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(options) {
|
|
694
|
-
var url, res, buffer, float32, wordIndex, nWords, dim;
|
|
695
|
-
return _regenerator.default.wrap(function
|
|
694
|
+
var url, res, buffer, float32, wordIndex, nWords, dim, _t, _t2;
|
|
695
|
+
return _regenerator.default.wrap(function (_context) {
|
|
696
696
|
while (1) switch (_context.prev = _context.next) {
|
|
697
697
|
case 0:
|
|
698
698
|
if (!(vectorStore || vectorsLoadStarted)) {
|
|
699
|
-
_context.next =
|
|
699
|
+
_context.next = 1;
|
|
700
700
|
break;
|
|
701
701
|
}
|
|
702
702
|
return _context.abrupt("return");
|
|
703
|
-
case
|
|
703
|
+
case 1:
|
|
704
704
|
if (options !== null && options !== void 0 && options.getBinaryUrl) {
|
|
705
|
-
_context.next =
|
|
705
|
+
_context.next = 2;
|
|
706
706
|
break;
|
|
707
707
|
}
|
|
708
708
|
// eslint-disable-next-line no-console
|
|
709
709
|
console.warn('[text-predictor] loadVectorsAsync called without a getBinaryUrl — vectors will not load. Pass getVectorsBinaryUrl via plugin options.');
|
|
710
710
|
return _context.abrupt("return");
|
|
711
|
-
case
|
|
711
|
+
case 2:
|
|
712
712
|
vectorsLoadStarted = true;
|
|
713
713
|
(0, _ufo.startExp)(_ufo.EXPERIENCE_NAME.LOAD_VECTORS, 'singleton');
|
|
714
|
-
_context.prev =
|
|
715
|
-
_context.next =
|
|
714
|
+
_context.prev = 3;
|
|
715
|
+
_context.next = 4;
|
|
716
716
|
return options.getBinaryUrl();
|
|
717
|
-
case
|
|
717
|
+
case 4:
|
|
718
718
|
url = _context.sent;
|
|
719
|
-
_context.next =
|
|
719
|
+
_context.next = 6;
|
|
720
720
|
break;
|
|
721
|
-
case
|
|
722
|
-
_context.prev =
|
|
723
|
-
|
|
721
|
+
case 5:
|
|
722
|
+
_context.prev = 5;
|
|
723
|
+
_t = _context["catch"](3);
|
|
724
724
|
vectorsLoadStarted = false;
|
|
725
725
|
(0, _ufo.failExp)(_ufo.EXPERIENCE_NAME.LOAD_VECTORS, 'singleton', {
|
|
726
726
|
errorType: 'resolve_url'
|
|
727
727
|
});
|
|
728
728
|
// eslint-disable-next-line no-console
|
|
729
|
-
console.warn('[text-predictor] Failed to resolve vectors URL:',
|
|
729
|
+
console.warn('[text-predictor] Failed to resolve vectors URL:', _t);
|
|
730
730
|
return _context.abrupt("return");
|
|
731
|
-
case
|
|
732
|
-
_context.prev =
|
|
733
|
-
_context.next =
|
|
731
|
+
case 6:
|
|
732
|
+
_context.prev = 6;
|
|
733
|
+
_context.next = 7;
|
|
734
734
|
return fetch(url);
|
|
735
|
-
case
|
|
735
|
+
case 7:
|
|
736
736
|
res = _context.sent;
|
|
737
737
|
if (res.ok) {
|
|
738
|
-
_context.next =
|
|
738
|
+
_context.next = 8;
|
|
739
739
|
break;
|
|
740
740
|
}
|
|
741
741
|
vectorsLoadStarted = false;
|
|
@@ -746,10 +746,10 @@ var loadVectorsAsync = exports.loadVectorsAsync = /*#__PURE__*/function () {
|
|
|
746
746
|
// eslint-disable-next-line no-console
|
|
747
747
|
console.warn("[text-predictor] Failed to load vectors: ".concat(res.status));
|
|
748
748
|
return _context.abrupt("return");
|
|
749
|
-
case
|
|
750
|
-
_context.next =
|
|
749
|
+
case 8:
|
|
750
|
+
_context.next = 9;
|
|
751
751
|
return res.arrayBuffer();
|
|
752
|
-
case
|
|
752
|
+
case 9:
|
|
753
753
|
buffer = _context.sent;
|
|
754
754
|
float32 = new Float32Array(buffer);
|
|
755
755
|
wordIndex = _word_index_10k.default;
|
|
@@ -773,22 +773,22 @@ var loadVectorsAsync = exports.loadVectorsAsync = /*#__PURE__*/function () {
|
|
|
773
773
|
sizeBytes: float32.byteLength
|
|
774
774
|
});
|
|
775
775
|
}
|
|
776
|
-
_context.next =
|
|
776
|
+
_context.next = 11;
|
|
777
777
|
break;
|
|
778
|
-
case
|
|
779
|
-
_context.prev =
|
|
780
|
-
|
|
778
|
+
case 10:
|
|
779
|
+
_context.prev = 10;
|
|
780
|
+
_t2 = _context["catch"](6);
|
|
781
781
|
vectorsLoadStarted = false;
|
|
782
782
|
(0, _ufo.failExp)(_ufo.EXPERIENCE_NAME.LOAD_VECTORS, 'singleton', {
|
|
783
783
|
errorType: 'network'
|
|
784
784
|
});
|
|
785
785
|
// eslint-disable-next-line no-console
|
|
786
|
-
console.warn('[text-predictor] Failed to load vectors:',
|
|
787
|
-
case
|
|
786
|
+
console.warn('[text-predictor] Failed to load vectors:', _t2);
|
|
787
|
+
case 11:
|
|
788
788
|
case "end":
|
|
789
789
|
return _context.stop();
|
|
790
790
|
}
|
|
791
|
-
}, _callee, null, [[
|
|
791
|
+
}, _callee, null, [[3, 5], [6, 10]]);
|
|
792
792
|
}));
|
|
793
793
|
return function loadVectorsAsync(_x) {
|
|
794
794
|
return _ref6.apply(this, arguments);
|
|
@@ -28,10 +28,6 @@
|
|
|
28
28
|
|
|
29
29
|
import { isAutocompleteDebugEnabled } from './debug-mode';
|
|
30
30
|
import { isWordBoundary } from './slow-lane-client';
|
|
31
|
-
const startsWithAsciiLetter = value => {
|
|
32
|
-
const firstChar = value.charCodeAt(0);
|
|
33
|
-
return firstChar >= 65 && firstChar <= 90 || firstChar >= 97 && firstChar <= 122;
|
|
34
|
-
};
|
|
35
31
|
|
|
36
32
|
// ─── Types ───────────────────────────────────────────────────────────────────
|
|
37
33
|
|
|
@@ -122,8 +118,6 @@ export const createLocalSlowLaneClient = (config = {}) => {
|
|
|
122
118
|
if (!('gpu' in navigator)) {
|
|
123
119
|
throw new Error('WebGPU not supported');
|
|
124
120
|
}
|
|
125
|
-
|
|
126
|
-
// eslint-disable-next-line @repo/internal/import/no-unresolved, import/dynamic-import-chunkname -- runtime dependency declared in package.json and lazily loaded for webgpu support
|
|
127
121
|
const {
|
|
128
122
|
CreateMLCEngine,
|
|
129
123
|
prebuiltAppConfig
|
|
@@ -225,7 +219,8 @@ export const createLocalSlowLaneClient = (config = {}) => {
|
|
|
225
219
|
// Add the top token
|
|
226
220
|
if (tokenLogprobs.token) {
|
|
227
221
|
const token = tokenLogprobs.token.trim().toLowerCase();
|
|
228
|
-
|
|
222
|
+
// @ts-ignore TS1501: Unicode regex flag requires a newer TS target than the declaration build uses.
|
|
223
|
+
if (token.length > 0 && /^[a-z]/iu.test(token)) {
|
|
229
224
|
lmLogits[token] = Math.exp(tokenLogprobs.logprob);
|
|
230
225
|
}
|
|
231
226
|
}
|
|
@@ -234,7 +229,8 @@ export const createLocalSlowLaneClient = (config = {}) => {
|
|
|
234
229
|
if (tokenLogprobs.top_logprobs) {
|
|
235
230
|
for (const alt of tokenLogprobs.top_logprobs) {
|
|
236
231
|
const token = alt.token.trim().toLowerCase();
|
|
237
|
-
|
|
232
|
+
// @ts-ignore TS1501: Unicode regex flag requires a newer TS target than the declaration build uses.
|
|
233
|
+
if (token.length > 0 && /^[a-z]/iu.test(token)) {
|
|
238
234
|
lmLogits[token] = Math.exp(alt.logprob);
|
|
239
235
|
}
|
|
240
236
|
}
|
|
@@ -38,10 +38,6 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
38
38
|
|
|
39
39
|
import { isAutocompleteDebugEnabled } from './debug-mode';
|
|
40
40
|
import { isWordBoundary } from './slow-lane-client';
|
|
41
|
-
var startsWithAsciiLetter = function startsWithAsciiLetter(value) {
|
|
42
|
-
var firstChar = value.charCodeAt(0);
|
|
43
|
-
return firstChar >= 65 && firstChar <= 90 || firstChar >= 97 && firstChar <= 122;
|
|
44
|
-
};
|
|
45
41
|
|
|
46
42
|
// ─── Types ───────────────────────────────────────────────────────────────────
|
|
47
43
|
|
|
@@ -125,8 +121,8 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
|
|
|
125
121
|
};
|
|
126
122
|
var initEngine = /*#__PURE__*/function () {
|
|
127
123
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
128
|
-
var _yield$import, CreateMLCEngine, prebuiltAppConfig, customModelRecord, appConfig, errorMsg;
|
|
129
|
-
return _regeneratorRuntime.wrap(function
|
|
124
|
+
var _yield$import, CreateMLCEngine, prebuiltAppConfig, customModelRecord, appConfig, errorMsg, _t;
|
|
125
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
130
126
|
while (1) switch (_context.prev = _context.next) {
|
|
131
127
|
case 0:
|
|
132
128
|
_context.prev = 0;
|
|
@@ -136,14 +132,14 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
|
|
|
136
132
|
}
|
|
137
133
|
onStatus === null || onStatus === void 0 || onStatus("Initialising model: ".concat(modelId, "\u2026"));
|
|
138
134
|
if ('gpu' in navigator) {
|
|
139
|
-
_context.next =
|
|
135
|
+
_context.next = 1;
|
|
140
136
|
break;
|
|
141
137
|
}
|
|
142
138
|
throw new Error('WebGPU not supported');
|
|
143
|
-
case
|
|
144
|
-
_context.next =
|
|
139
|
+
case 1:
|
|
140
|
+
_context.next = 2;
|
|
145
141
|
return import( /* webpackChunkName: "@atlaskit-internal_editor-plugin-autocomplete-mlc-web-llm" */'@mlc-ai/web-llm');
|
|
146
|
-
case
|
|
142
|
+
case 2:
|
|
147
143
|
_yield$import = _context.sent;
|
|
148
144
|
CreateMLCEngine = _yield$import.CreateMLCEngine;
|
|
149
145
|
prebuiltAppConfig = _yield$import.prebuiltAppConfig;
|
|
@@ -163,34 +159,34 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
|
|
|
163
159
|
appConfig = {
|
|
164
160
|
model_list: [].concat(_toConsumableArray(prebuiltAppConfig.model_list), _toConsumableArray(customModelRecord ? [customModelRecord] : []))
|
|
165
161
|
};
|
|
166
|
-
_context.next =
|
|
162
|
+
_context.next = 3;
|
|
167
163
|
return CreateMLCEngine(modelId, {
|
|
168
164
|
appConfig: appConfig,
|
|
169
165
|
initProgressCallback: initProgressCallback
|
|
170
166
|
});
|
|
171
|
-
case
|
|
167
|
+
case 3:
|
|
172
168
|
engine = _context.sent;
|
|
173
169
|
if (!destroyed) {
|
|
174
|
-
_context.next =
|
|
170
|
+
_context.next = 4;
|
|
175
171
|
break;
|
|
176
172
|
}
|
|
177
173
|
// destroy() was called while we were loading — clean up
|
|
178
174
|
unloadEngine(engine);
|
|
179
175
|
engine = null;
|
|
180
176
|
return _context.abrupt("return");
|
|
181
|
-
case
|
|
177
|
+
case 4:
|
|
182
178
|
ready = true;
|
|
183
179
|
if (isAutocompleteDebugEnabled()) {
|
|
184
180
|
// eslint-disable-next-line no-console
|
|
185
181
|
console.log('%c[LocalSlowLane] %c✅ MLC engine loaded and ready', 'color: #9c27b0; font-weight: bold;', 'color: #4caf50;');
|
|
186
182
|
}
|
|
187
183
|
onStatus === null || onStatus === void 0 || onStatus('Model loaded and ready.');
|
|
188
|
-
_context.next =
|
|
184
|
+
_context.next = 6;
|
|
189
185
|
break;
|
|
190
|
-
case
|
|
191
|
-
_context.prev =
|
|
192
|
-
|
|
193
|
-
errorMsg =
|
|
186
|
+
case 5:
|
|
187
|
+
_context.prev = 5;
|
|
188
|
+
_t = _context["catch"](0);
|
|
189
|
+
errorMsg = _t instanceof Error ? _t.message : String(_t);
|
|
194
190
|
ready = false;
|
|
195
191
|
if (isAutocompleteDebugEnabled()) {
|
|
196
192
|
// eslint-disable-next-line no-console
|
|
@@ -199,11 +195,11 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
|
|
|
199
195
|
onStatus === null || onStatus === void 0 || onStatus("Engine initialisation failed: ".concat(errorMsg));
|
|
200
196
|
engineInitPromise = null;
|
|
201
197
|
initFailed = true;
|
|
202
|
-
case
|
|
198
|
+
case 6:
|
|
203
199
|
case "end":
|
|
204
200
|
return _context.stop();
|
|
205
201
|
}
|
|
206
|
-
}, _callee, null, [[0,
|
|
202
|
+
}, _callee, null, [[0, 5]]);
|
|
207
203
|
}));
|
|
208
204
|
return function initEngine() {
|
|
209
205
|
return _ref.apply(this, arguments);
|
|
@@ -230,18 +226,18 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
|
|
|
230
226
|
*/
|
|
231
227
|
var runInference = /*#__PURE__*/function () {
|
|
232
228
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(text, requestId) {
|
|
233
|
-
var _response$choices, response, lmLogits, logprobsContent, tokenLogprobs, token, _iterator, _step, alt, _token, logitValues, topTokens, errorMsg;
|
|
234
|
-
return _regeneratorRuntime.wrap(function
|
|
229
|
+
var _response$choices, response, lmLogits, logprobsContent, tokenLogprobs, token, _iterator, _step, alt, _token, logitValues, topTokens, errorMsg, _t2;
|
|
230
|
+
return _regeneratorRuntime.wrap(function (_context2) {
|
|
235
231
|
while (1) switch (_context2.prev = _context2.next) {
|
|
236
232
|
case 0:
|
|
237
233
|
if (!(!engine || destroyed)) {
|
|
238
|
-
_context2.next =
|
|
234
|
+
_context2.next = 1;
|
|
239
235
|
break;
|
|
240
236
|
}
|
|
241
237
|
return _context2.abrupt("return");
|
|
242
|
-
case
|
|
243
|
-
_context2.prev =
|
|
244
|
-
_context2.next =
|
|
238
|
+
case 1:
|
|
239
|
+
_context2.prev = 1;
|
|
240
|
+
_context2.next = 2;
|
|
245
241
|
return engine.chat.completions.create({
|
|
246
242
|
messages: [{
|
|
247
243
|
role: 'user',
|
|
@@ -252,22 +248,22 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
|
|
|
252
248
|
top_logprobs: 5,
|
|
253
249
|
temperature: 0
|
|
254
250
|
});
|
|
255
|
-
case
|
|
251
|
+
case 2:
|
|
256
252
|
response = _context2.sent;
|
|
257
253
|
if (!(requestId < latestRequestId || destroyed)) {
|
|
258
|
-
_context2.next =
|
|
254
|
+
_context2.next = 3;
|
|
259
255
|
break;
|
|
260
256
|
}
|
|
261
257
|
return _context2.abrupt("return");
|
|
262
|
-
case
|
|
258
|
+
case 3:
|
|
263
259
|
// ── Extract LM logits ───────────────────────────────────────
|
|
264
260
|
lmLogits = {};
|
|
265
261
|
logprobsContent = (_response$choices = response.choices) === null || _response$choices === void 0 || (_response$choices = _response$choices[0]) === null || _response$choices === void 0 || (_response$choices = _response$choices.logprobs) === null || _response$choices === void 0 ? void 0 : _response$choices.content;
|
|
266
262
|
if (logprobsContent && logprobsContent.length > 0) {
|
|
267
263
|
tokenLogprobs = logprobsContent[0]; // Add the top token
|
|
268
264
|
if (tokenLogprobs.token) {
|
|
269
|
-
token = tokenLogprobs.token.trim().toLowerCase();
|
|
270
|
-
if (token.length > 0 &&
|
|
265
|
+
token = tokenLogprobs.token.trim().toLowerCase(); // @ts-ignore TS1501: Unicode regex flag requires a newer TS target than the declaration build uses.
|
|
266
|
+
if (token.length > 0 && /^[a-z\u017F\u212A]/i.test(token)) {
|
|
271
267
|
lmLogits[token] = Math.exp(tokenLogprobs.logprob);
|
|
272
268
|
}
|
|
273
269
|
}
|
|
@@ -278,8 +274,8 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
|
|
|
278
274
|
try {
|
|
279
275
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
280
276
|
alt = _step.value;
|
|
281
|
-
_token = alt.token.trim().toLowerCase();
|
|
282
|
-
if (_token.length > 0 &&
|
|
277
|
+
_token = alt.token.trim().toLowerCase(); // @ts-ignore TS1501: Unicode regex flag requires a newer TS target than the declaration build uses.
|
|
278
|
+
if (_token.length > 0 && /^[a-z\u017F\u212A]/i.test(_token)) {
|
|
283
279
|
lmLogits[_token] = Math.exp(alt.logprob);
|
|
284
280
|
}
|
|
285
281
|
}
|
|
@@ -337,17 +333,17 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
|
|
|
337
333
|
hasVector: storedContextVector !== null,
|
|
338
334
|
hasLmLogits: storedLmLogits !== null
|
|
339
335
|
});
|
|
340
|
-
_context2.next =
|
|
336
|
+
_context2.next = 6;
|
|
341
337
|
break;
|
|
342
|
-
case
|
|
343
|
-
_context2.prev =
|
|
344
|
-
|
|
338
|
+
case 4:
|
|
339
|
+
_context2.prev = 4;
|
|
340
|
+
_t2 = _context2["catch"](1);
|
|
345
341
|
if (!(requestId < latestRequestId)) {
|
|
346
|
-
_context2.next =
|
|
342
|
+
_context2.next = 5;
|
|
347
343
|
break;
|
|
348
344
|
}
|
|
349
345
|
return _context2.abrupt("return");
|
|
350
|
-
case
|
|
346
|
+
case 5:
|
|
351
347
|
storedContextVector = null;
|
|
352
348
|
storedLmLogits = null;
|
|
353
349
|
onUpdate === null || onUpdate === void 0 || onUpdate({
|
|
@@ -355,16 +351,16 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
|
|
|
355
351
|
hasVector: false,
|
|
356
352
|
hasLmLogits: false
|
|
357
353
|
});
|
|
358
|
-
errorMsg =
|
|
354
|
+
errorMsg = _t2 instanceof Error ? _t2.message : String(_t2);
|
|
359
355
|
if (isAutocompleteDebugEnabled()) {
|
|
360
356
|
// eslint-disable-next-line no-console
|
|
361
357
|
console.log("%c[LocalSlowLane] %c\u274C Inference error (request #".concat(requestId, "): ").concat(errorMsg), 'color: #9c27b0; font-weight: bold;', 'color: #f44336;');
|
|
362
358
|
}
|
|
363
|
-
case
|
|
359
|
+
case 6:
|
|
364
360
|
case "end":
|
|
365
361
|
return _context2.stop();
|
|
366
362
|
}
|
|
367
|
-
}, _callee2, null, [[
|
|
363
|
+
}, _callee2, null, [[1, 4]]);
|
|
368
364
|
}));
|
|
369
365
|
return function runInference(_x, _x2) {
|
|
370
366
|
return _ref2.apply(this, arguments);
|
|
@@ -64,16 +64,16 @@ export var createSlowLaneClient = function createSlowLaneClient(config) {
|
|
|
64
64
|
var inflightRequestId = null;
|
|
65
65
|
var doUpdateContext = /*#__PURE__*/function () {
|
|
66
66
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(text, requestId) {
|
|
67
|
-
var url, payload, res, data;
|
|
68
|
-
return _regeneratorRuntime.wrap(function
|
|
67
|
+
var url, payload, res, data, _t;
|
|
68
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
69
69
|
while (1) switch (_context.prev = _context.next) {
|
|
70
70
|
case 0:
|
|
71
71
|
if (!(!text || text.trim().length === 0)) {
|
|
72
|
-
_context.next =
|
|
72
|
+
_context.next = 1;
|
|
73
73
|
break;
|
|
74
74
|
}
|
|
75
75
|
return _context.abrupt("return");
|
|
76
|
-
case
|
|
76
|
+
case 1:
|
|
77
77
|
// eslint-disable-next-line require-unicode-regexp
|
|
78
78
|
url = "".concat(baseUrl.replace(/\/$/, '')).concat(endpoint);
|
|
79
79
|
payload = {
|
|
@@ -93,17 +93,17 @@ export var createSlowLaneClient = function createSlowLaneClient(config) {
|
|
|
93
93
|
// eslint-disable-next-line no-console
|
|
94
94
|
console.groupEnd();
|
|
95
95
|
}
|
|
96
|
-
_context.prev =
|
|
97
|
-
_context.next =
|
|
96
|
+
_context.prev = 2;
|
|
97
|
+
_context.next = 3;
|
|
98
98
|
return fetchFn(url, {
|
|
99
99
|
method: 'POST',
|
|
100
100
|
headers: headers,
|
|
101
101
|
body: JSON.stringify(payload)
|
|
102
102
|
});
|
|
103
|
-
case
|
|
103
|
+
case 3:
|
|
104
104
|
res = _context.sent;
|
|
105
105
|
if (res.ok) {
|
|
106
|
-
_context.next =
|
|
106
|
+
_context.next = 4;
|
|
107
107
|
break;
|
|
108
108
|
}
|
|
109
109
|
storedContextVector = null;
|
|
@@ -117,10 +117,10 @@ export var createSlowLaneClient = function createSlowLaneClient(config) {
|
|
|
117
117
|
console.log("%c[SlowLane] %c\u274C Request failed (".concat(res.status, ")"), 'color: #9c27b0; font-weight: bold;', 'color: #f44336;');
|
|
118
118
|
}
|
|
119
119
|
return _context.abrupt("return");
|
|
120
|
-
case
|
|
121
|
-
_context.next =
|
|
120
|
+
case 4:
|
|
121
|
+
_context.next = 5;
|
|
122
122
|
return res.json();
|
|
123
|
-
case
|
|
123
|
+
case 5:
|
|
124
124
|
data = _context.sent;
|
|
125
125
|
if (data.semantic_vector && Array.isArray(data.semantic_vector)) {
|
|
126
126
|
storedContextVector = new Float32Array(data.semantic_vector);
|
|
@@ -153,11 +153,11 @@ export var createSlowLaneClient = function createSlowLaneClient(config) {
|
|
|
153
153
|
hasLmLogits: storedLmLogits !== null
|
|
154
154
|
});
|
|
155
155
|
// eslint-disable-next-line no-unused-vars
|
|
156
|
-
_context.next =
|
|
156
|
+
_context.next = 7;
|
|
157
157
|
break;
|
|
158
|
-
case
|
|
159
|
-
_context.prev =
|
|
160
|
-
|
|
158
|
+
case 6:
|
|
159
|
+
_context.prev = 6;
|
|
160
|
+
_t = _context["catch"](2);
|
|
161
161
|
storedContextVector = null;
|
|
162
162
|
storedLmLogits = null;
|
|
163
163
|
failExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, requestId, {
|
|
@@ -167,17 +167,17 @@ export var createSlowLaneClient = function createSlowLaneClient(config) {
|
|
|
167
167
|
// eslint-disable-next-line no-console
|
|
168
168
|
console.log('%c[SlowLane] %c❌ Network error — context cleared', 'color: #9c27b0; font-weight: bold;', 'color: #f44336;');
|
|
169
169
|
}
|
|
170
|
-
case
|
|
171
|
-
_context.prev =
|
|
170
|
+
case 7:
|
|
171
|
+
_context.prev = 7;
|
|
172
172
|
if (inflightRequestId === requestId) {
|
|
173
173
|
inflightRequestId = null;
|
|
174
174
|
}
|
|
175
|
-
return _context.finish(
|
|
176
|
-
case
|
|
175
|
+
return _context.finish(7);
|
|
176
|
+
case 8:
|
|
177
177
|
case "end":
|
|
178
178
|
return _context.stop();
|
|
179
179
|
}
|
|
180
|
-
}, _callee, null, [[
|
|
180
|
+
}, _callee, null, [[2, 6, 7, 8]]);
|
|
181
181
|
}));
|
|
182
182
|
return function doUpdateContext(_x, _x2) {
|
|
183
183
|
return _ref.apply(this, arguments);
|
|
@@ -689,51 +689,51 @@ export var predict = function predict(textBefore) {
|
|
|
689
689
|
|
|
690
690
|
export var loadVectorsAsync = /*#__PURE__*/function () {
|
|
691
691
|
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(options) {
|
|
692
|
-
var url, res, buffer, float32, wordIndex, nWords, dim;
|
|
693
|
-
return _regeneratorRuntime.wrap(function
|
|
692
|
+
var url, res, buffer, float32, wordIndex, nWords, dim, _t, _t2;
|
|
693
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
694
694
|
while (1) switch (_context.prev = _context.next) {
|
|
695
695
|
case 0:
|
|
696
696
|
if (!(vectorStore || vectorsLoadStarted)) {
|
|
697
|
-
_context.next =
|
|
697
|
+
_context.next = 1;
|
|
698
698
|
break;
|
|
699
699
|
}
|
|
700
700
|
return _context.abrupt("return");
|
|
701
|
-
case
|
|
701
|
+
case 1:
|
|
702
702
|
if (options !== null && options !== void 0 && options.getBinaryUrl) {
|
|
703
|
-
_context.next =
|
|
703
|
+
_context.next = 2;
|
|
704
704
|
break;
|
|
705
705
|
}
|
|
706
706
|
// eslint-disable-next-line no-console
|
|
707
707
|
console.warn('[text-predictor] loadVectorsAsync called without a getBinaryUrl — vectors will not load. Pass getVectorsBinaryUrl via plugin options.');
|
|
708
708
|
return _context.abrupt("return");
|
|
709
|
-
case
|
|
709
|
+
case 2:
|
|
710
710
|
vectorsLoadStarted = true;
|
|
711
711
|
startExp(EXPERIENCE_NAME.LOAD_VECTORS, 'singleton');
|
|
712
|
-
_context.prev =
|
|
713
|
-
_context.next =
|
|
712
|
+
_context.prev = 3;
|
|
713
|
+
_context.next = 4;
|
|
714
714
|
return options.getBinaryUrl();
|
|
715
|
-
case
|
|
715
|
+
case 4:
|
|
716
716
|
url = _context.sent;
|
|
717
|
-
_context.next =
|
|
717
|
+
_context.next = 6;
|
|
718
718
|
break;
|
|
719
|
-
case
|
|
720
|
-
_context.prev =
|
|
721
|
-
|
|
719
|
+
case 5:
|
|
720
|
+
_context.prev = 5;
|
|
721
|
+
_t = _context["catch"](3);
|
|
722
722
|
vectorsLoadStarted = false;
|
|
723
723
|
failExp(EXPERIENCE_NAME.LOAD_VECTORS, 'singleton', {
|
|
724
724
|
errorType: 'resolve_url'
|
|
725
725
|
});
|
|
726
726
|
// eslint-disable-next-line no-console
|
|
727
|
-
console.warn('[text-predictor] Failed to resolve vectors URL:',
|
|
727
|
+
console.warn('[text-predictor] Failed to resolve vectors URL:', _t);
|
|
728
728
|
return _context.abrupt("return");
|
|
729
|
-
case
|
|
730
|
-
_context.prev =
|
|
731
|
-
_context.next =
|
|
729
|
+
case 6:
|
|
730
|
+
_context.prev = 6;
|
|
731
|
+
_context.next = 7;
|
|
732
732
|
return fetch(url);
|
|
733
|
-
case
|
|
733
|
+
case 7:
|
|
734
734
|
res = _context.sent;
|
|
735
735
|
if (res.ok) {
|
|
736
|
-
_context.next =
|
|
736
|
+
_context.next = 8;
|
|
737
737
|
break;
|
|
738
738
|
}
|
|
739
739
|
vectorsLoadStarted = false;
|
|
@@ -744,10 +744,10 @@ export var loadVectorsAsync = /*#__PURE__*/function () {
|
|
|
744
744
|
// eslint-disable-next-line no-console
|
|
745
745
|
console.warn("[text-predictor] Failed to load vectors: ".concat(res.status));
|
|
746
746
|
return _context.abrupt("return");
|
|
747
|
-
case
|
|
748
|
-
_context.next =
|
|
747
|
+
case 8:
|
|
748
|
+
_context.next = 9;
|
|
749
749
|
return res.arrayBuffer();
|
|
750
|
-
case
|
|
750
|
+
case 9:
|
|
751
751
|
buffer = _context.sent;
|
|
752
752
|
float32 = new Float32Array(buffer);
|
|
753
753
|
wordIndex = wordIndexData;
|
|
@@ -771,22 +771,22 @@ export var loadVectorsAsync = /*#__PURE__*/function () {
|
|
|
771
771
|
sizeBytes: float32.byteLength
|
|
772
772
|
});
|
|
773
773
|
}
|
|
774
|
-
_context.next =
|
|
774
|
+
_context.next = 11;
|
|
775
775
|
break;
|
|
776
|
-
case
|
|
777
|
-
_context.prev =
|
|
778
|
-
|
|
776
|
+
case 10:
|
|
777
|
+
_context.prev = 10;
|
|
778
|
+
_t2 = _context["catch"](6);
|
|
779
779
|
vectorsLoadStarted = false;
|
|
780
780
|
failExp(EXPERIENCE_NAME.LOAD_VECTORS, 'singleton', {
|
|
781
781
|
errorType: 'network'
|
|
782
782
|
});
|
|
783
783
|
// eslint-disable-next-line no-console
|
|
784
|
-
console.warn('[text-predictor] Failed to load vectors:',
|
|
785
|
-
case
|
|
784
|
+
console.warn('[text-predictor] Failed to load vectors:', _t2);
|
|
785
|
+
case 11:
|
|
786
786
|
case "end":
|
|
787
787
|
return _context.stop();
|
|
788
788
|
}
|
|
789
|
-
}, _callee, null, [[
|
|
789
|
+
}, _callee, null, [[3, 5], [6, 10]]);
|
|
790
790
|
}));
|
|
791
791
|
return function loadVectorsAsync(_x) {
|
|
792
792
|
return _ref6.apply(this, arguments);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-autocomplete",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Client-side text autocomplete plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"wink-nlp": "^2.4.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@atlaskit/editor-common": "^
|
|
39
|
-
"@atlaskit/editor-plugin-analytics": "^
|
|
38
|
+
"@atlaskit/editor-common": "^115.0.0",
|
|
39
|
+
"@atlaskit/editor-plugin-analytics": "^11.0.0",
|
|
40
40
|
"react": "^18.2.0"
|
|
41
41
|
},
|
|
42
42
|
"techstack": {
|
|
@@ -33,12 +33,6 @@ import { isWordBoundary } from './slow-lane-client';
|
|
|
33
33
|
|
|
34
34
|
type WebLlmModelRecord = NonNullable<AppConfig['model_list']>[number];
|
|
35
35
|
|
|
36
|
-
const startsWithAsciiLetter = (value: string): boolean => {
|
|
37
|
-
const firstChar = value.charCodeAt(0);
|
|
38
|
-
|
|
39
|
-
return (firstChar >= 65 && firstChar <= 90) || (firstChar >= 97 && firstChar <= 122);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
36
|
// ─── Types ───────────────────────────────────────────────────────────────────
|
|
43
37
|
|
|
44
38
|
export interface LocalSlowLaneClientConfig {
|
|
@@ -195,7 +189,6 @@ export const createLocalSlowLaneClient = (
|
|
|
195
189
|
throw new Error('WebGPU not supported');
|
|
196
190
|
}
|
|
197
191
|
|
|
198
|
-
// eslint-disable-next-line @repo/internal/import/no-unresolved, import/dynamic-import-chunkname -- runtime dependency declared in package.json and lazily loaded for webgpu support
|
|
199
192
|
const { CreateMLCEngine, prebuiltAppConfig } = await import(
|
|
200
193
|
/* webpackChunkName: "@atlaskit-internal_editor-plugin-autocomplete-mlc-web-llm" */ '@mlc-ai/web-llm'
|
|
201
194
|
);
|
|
@@ -319,7 +312,8 @@ export const createLocalSlowLaneClient = (
|
|
|
319
312
|
// Add the top token
|
|
320
313
|
if (tokenLogprobs.token) {
|
|
321
314
|
const token = tokenLogprobs.token.trim().toLowerCase();
|
|
322
|
-
|
|
315
|
+
// @ts-ignore TS1501: Unicode regex flag requires a newer TS target than the declaration build uses.
|
|
316
|
+
if (token.length > 0 && /^[a-z]/iu.test(token)) {
|
|
323
317
|
lmLogits[token] = Math.exp(tokenLogprobs.logprob);
|
|
324
318
|
}
|
|
325
319
|
}
|
|
@@ -328,7 +322,8 @@ export const createLocalSlowLaneClient = (
|
|
|
328
322
|
if (tokenLogprobs.top_logprobs) {
|
|
329
323
|
for (const alt of tokenLogprobs.top_logprobs) {
|
|
330
324
|
const token = alt.token.trim().toLowerCase();
|
|
331
|
-
|
|
325
|
+
// @ts-ignore TS1501: Unicode regex flag requires a newer TS target than the declaration build uses.
|
|
326
|
+
if (token.length > 0 && /^[a-z]/iu.test(token)) {
|
|
332
327
|
lmLogits[token] = Math.exp(alt.logprob);
|
|
333
328
|
}
|
|
334
329
|
}
|