@atlaskit/editor-plugin-autocomplete 4.1.0 → 4.1.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.
@@ -42,6 +42,7 @@ export const createSlowLaneClient = config => {
42
42
  baseUrl,
43
43
  sessionId: configSessionId,
44
44
  productKey = 'confluence',
45
+ surface,
45
46
  endpoint = '/gateway/api/v1/autocomplete/typeahead-encodings',
46
47
  debounceMs = DEFAULT_DEBOUNCE_MS,
47
48
  fetchFn = fetch,
@@ -70,7 +71,10 @@ export const createSlowLaneClient = config => {
70
71
  };
71
72
  startExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, requestId, {
72
73
  textLength: text.length,
73
- isLocalLLM: false
74
+ isLocalLLM: false,
75
+ ...(surface ? {
76
+ surface
77
+ } : {})
74
78
  });
75
79
  if (isAutocompleteDebugEnabled()) {
76
80
  // eslint-disable-next-line no-console
@@ -94,7 +98,10 @@ export const createSlowLaneClient = config => {
94
98
  failExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, requestId, {
95
99
  status: res.status,
96
100
  errorType: 'http_error',
97
- isLocalLLM: false
101
+ isLocalLLM: false,
102
+ ...(surface ? {
103
+ surface
104
+ } : {})
98
105
  });
99
106
  if (isAutocompleteDebugEnabled()) {
100
107
  // eslint-disable-next-line no-console
@@ -127,7 +134,10 @@ export const createSlowLaneClient = config => {
127
134
  textLength: text.length,
128
135
  hasVector: storedContextVector !== null,
129
136
  hasLmLogits: storedLmLogits !== null,
130
- isLocalLLM: false
137
+ isLocalLLM: false,
138
+ ...(surface ? {
139
+ surface
140
+ } : {})
131
141
  });
132
142
  onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate({
133
143
  textLength: text.length,
@@ -140,7 +150,10 @@ export const createSlowLaneClient = config => {
140
150
  storedLmLogits = null;
141
151
  failExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, requestId, {
142
152
  errorType: 'network',
143
- isLocalLLM: false
153
+ isLocalLLM: false,
154
+ ...(surface ? {
155
+ surface
156
+ } : {})
144
157
  });
145
158
  if (isAutocompleteDebugEnabled()) {
146
159
  // eslint-disable-next-line no-console
@@ -161,7 +174,10 @@ export const createSlowLaneClient = config => {
161
174
  debounceTimer = null;
162
175
  if (inflightRequestId !== null) {
163
176
  abortExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, inflightRequestId, 'superseded', {
164
- isLocalLLM: false
177
+ isLocalLLM: false,
178
+ ...(surface ? {
179
+ surface
180
+ } : {})
165
181
  });
166
182
  }
167
183
  const requestId = String(++requestSeq);
@@ -599,9 +599,13 @@ export const loadVectorsAsync = async options => {
599
599
  return;
600
600
  }
601
601
  const isLocalLLM = (_options$isLocalLLM = options === null || options === void 0 ? void 0 : options.isLocalLLM) !== null && _options$isLocalLLM !== void 0 ? _options$isLocalLLM : false;
602
+ const surface = options === null || options === void 0 ? void 0 : options.surface;
602
603
  vectorsLoadStarted = true;
603
604
  startExp(EXPERIENCE_NAME.LOAD_VECTORS, 'singleton', {
604
- isLocalLLM
605
+ isLocalLLM,
606
+ ...(surface ? {
607
+ surface
608
+ } : {})
605
609
  });
606
610
  let url;
607
611
  try {
@@ -610,7 +614,10 @@ export const loadVectorsAsync = async options => {
610
614
  vectorsLoadStarted = false;
611
615
  failExp(EXPERIENCE_NAME.LOAD_VECTORS, 'singleton', {
612
616
  isLocalLLM,
613
- errorType: 'resolve_url'
617
+ errorType: 'resolve_url',
618
+ ...(surface ? {
619
+ surface
620
+ } : {})
614
621
  });
615
622
  // eslint-disable-next-line no-console
616
623
  console.warn('[text-predictor] Failed to resolve vectors URL:', e);
@@ -624,7 +631,10 @@ export const loadVectorsAsync = async options => {
624
631
  failExp(EXPERIENCE_NAME.LOAD_VECTORS, 'singleton', {
625
632
  isLocalLLM,
626
633
  status: res.status,
627
- errorType: 'http_error'
634
+ errorType: 'http_error',
635
+ ...(surface ? {
636
+ surface
637
+ } : {})
628
638
  });
629
639
  // eslint-disable-next-line no-console
630
640
  console.warn(`[text-predictor] Failed to load vectors: ${res.status}`);
@@ -654,7 +664,10 @@ export const loadVectorsAsync = async options => {
654
664
  isLocalLLM,
655
665
  wordCount: nWords,
656
666
  dim,
657
- sizeBytes: float32.byteLength
667
+ sizeBytes: float32.byteLength,
668
+ ...(surface ? {
669
+ surface
670
+ } : {})
658
671
  });
659
672
  if (isAutocompleteDebugEnabled()) {
660
673
  // eslint-disable-next-line no-console
@@ -668,7 +681,10 @@ export const loadVectorsAsync = async options => {
668
681
  vectorsLoadStarted = false;
669
682
  failExp(EXPERIENCE_NAME.LOAD_VECTORS, 'singleton', {
670
683
  isLocalLLM,
671
- errorType: 'network'
684
+ errorType: 'network',
685
+ ...(surface ? {
686
+ surface
687
+ } : {})
672
688
  });
673
689
  // eslint-disable-next-line no-console
674
690
  console.warn('[text-predictor] Failed to load vectors:', e);
@@ -687,9 +703,13 @@ export const loadDefaultVocabulary = options => {
687
703
  return vocabularyLoadPromise;
688
704
  }
689
705
  const isLocalLLM = (_options$isLocalLLM2 = options === null || options === void 0 ? void 0 : options.isLocalLLM) !== null && _options$isLocalLLM2 !== void 0 ? _options$isLocalLLM2 : false;
706
+ const surface = options === null || options === void 0 ? void 0 : options.surface;
690
707
  vocabularyLoadPromise = (async () => {
691
708
  startExp(EXPERIENCE_NAME.LOAD_VOCABULARY, 'singleton', {
692
- isLocalLLM
709
+ isLocalLLM,
710
+ ...(surface ? {
711
+ surface
712
+ } : {})
693
713
  });
694
714
  try {
695
715
  // The L2 vocabulary and L3 word list are code-split into their own async
@@ -717,12 +737,18 @@ export const loadDefaultVocabulary = options => {
717
737
  succeedExp(EXPERIENCE_NAME.LOAD_VOCABULARY, 'singleton', {
718
738
  isLocalLLM,
719
739
  l2WordCount: terms.length,
720
- l3WordCount: l3VocabularyData.length
740
+ l3WordCount: l3VocabularyData.length,
741
+ ...(surface ? {
742
+ surface
743
+ } : {})
721
744
  });
722
745
  } catch (e) {
723
746
  failExp(EXPERIENCE_NAME.LOAD_VOCABULARY, 'singleton', {
724
747
  isLocalLLM,
725
- errorType: 'parse_error'
748
+ errorType: 'parse_error',
749
+ ...(surface ? {
750
+ surface
751
+ } : {})
726
752
  });
727
753
  // Allow a later call to retry the load rather than caching the failure.
728
754
  vocabularyLoadPromise = undefined;
@@ -235,7 +235,8 @@ var isEnglishLocale = function isEnglishLocale(locale) {
235
235
  return locale.toLowerCase().startsWith('en');
236
236
  };
237
237
  export var createAutocompletePlugin = function createAutocompletePlugin(options, api) {
238
- var _options$locale;
238
+ var _options$surface, _options$locale;
239
+ var surface = (_options$surface = options === null || options === void 0 ? void 0 : options.surface) !== null && _options$surface !== void 0 ? _options$surface : 'editor';
239
240
  var locale = (_options$locale = options === null || options === void 0 ? void 0 : options.locale) !== null && _options$locale !== void 0 ? _options$locale : typeof navigator !== 'undefined' ? navigator.language : undefined;
240
241
  var isAutocompleteEnabled = isEnglishLocale(locale);
241
242
  var debounceTimer = null;
@@ -283,7 +284,8 @@ export var createAutocompletePlugin = function createAutocompletePlugin(options,
283
284
  eventType: EVENT_TYPE.TRACK,
284
285
  attributes: {
285
286
  completionSource: getCompletionSource(),
286
- reason: reason
287
+ reason: reason,
288
+ surface: surface
287
289
  }
288
290
  });
289
291
  };
@@ -298,7 +300,8 @@ export var createAutocompletePlugin = function createAutocompletePlugin(options,
298
300
  embeddingModelId: info.embeddingModelId,
299
301
  loadDurationMs: info.loadDurationMs,
300
302
  gpuVendor: info.capabilities.vendor,
301
- gpuArchitecture: info.capabilities.architecture
303
+ gpuArchitecture: info.capabilities.architecture,
304
+ surface: surface
302
305
  }
303
306
  });
304
307
  };
@@ -320,7 +323,8 @@ export var createAutocompletePlugin = function createAutocompletePlugin(options,
320
323
  maxBufferSizeMB: capabilities.maxBufferSizeMB,
321
324
  maxStorageBufferBindingSizeMB: capabilities.maxStorageBufferBindingSizeMB,
322
325
  gpuVendor: capabilities.vendor,
323
- gpuArchitecture: capabilities.architecture
326
+ gpuArchitecture: capabilities.architecture,
327
+ surface: surface
324
328
  }
325
329
  });
326
330
  };
@@ -337,17 +341,20 @@ export var createAutocompletePlugin = function createAutocompletePlugin(options,
337
341
  completionSource: getCompletionSource(),
338
342
  suggestionLength: suggestionLength,
339
343
  typedLength: typedLength,
340
- kssDelta: kssDelta
344
+ kssDelta: kssDelta,
345
+ surface: surface
341
346
  }
342
347
  });
343
348
  };
344
349
  var slowLaneClient = options !== null && options !== void 0 && options.useLocalModel ? createLocalSlowLaneClient({
345
350
  debounceMs: LOCAL_SLOW_LANE_DEBOUNCE_MS,
346
351
  onLoadSuccess: fireLocalModelLoadedAnalytics,
347
- onLoadError: fireLocalModelLoadFailedAnalytics
352
+ onLoadError: fireLocalModelLoadFailedAnalytics,
353
+ surface: surface
348
354
  }) : createSlowLaneClient({
349
355
  baseUrl: '',
350
- debounceMs: NETWORK_SLOW_LANE_DEBOUNCE_MS
356
+ debounceMs: NETWORK_SLOW_LANE_DEBOUNCE_MS,
357
+ surface: surface
351
358
  });
352
359
  setDefaultSlowLaneClient(slowLaneClient);
353
360
  var contextRequestInFlight = false;
@@ -518,7 +525,8 @@ export var createAutocompletePlugin = function createAutocompletePlugin(options,
518
525
  actionSubject: ACTION_SUBJECT.CONTEXTUAL_TYPEAHEAD,
519
526
  eventType: EVENT_TYPE.TRACK,
520
527
  attributes: {
521
- completionSource: getCompletionSource()
528
+ completionSource: getCompletionSource(),
529
+ surface: surface
522
530
  }
523
531
  });
524
532
  }
@@ -642,7 +650,8 @@ export var createAutocompletePlugin = function createAutocompletePlugin(options,
642
650
  return false;
643
651
  }
644
652
  loadDefaultVocabulary({
645
- isLocalLLM: (_options$useLocalMode = options === null || options === void 0 ? void 0 : options.useLocalModel) !== null && _options$useLocalMode !== void 0 ? _options$useLocalMode : false
653
+ isLocalLLM: (_options$useLocalMode = options === null || options === void 0 ? void 0 : options.useLocalModel) !== null && _options$useLocalMode !== void 0 ? _options$useLocalMode : false,
654
+ surface: surface
646
655
  }).catch(function (error) {
647
656
  logException(error, {
648
657
  location: 'editor-plugin-autocomplete/loadDefaultVocabulary'
@@ -650,7 +659,8 @@ export var createAutocompletePlugin = function createAutocompletePlugin(options,
650
659
  });
651
660
  loadVectorsAsync({
652
661
  getBinaryUrl: options === null || options === void 0 ? void 0 : options.getVectorsBinaryUrl,
653
- isLocalLLM: (_options$useLocalMode2 = options === null || options === void 0 ? void 0 : options.useLocalModel) !== null && _options$useLocalMode2 !== void 0 ? _options$useLocalMode2 : false
662
+ isLocalLLM: (_options$useLocalMode2 = options === null || options === void 0 ? void 0 : options.useLocalModel) !== null && _options$useLocalMode2 !== void 0 ? _options$useLocalMode2 : false,
663
+ surface: surface
654
664
  }).catch(function (error) {
655
665
  logException(error, {
656
666
  location: 'editor-plugin-autocomplete/loadVectorsAsync'
@@ -621,7 +621,8 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
621
621
  onLoadSuccess = config.onLoadSuccess,
622
622
  _config$modelId = config.modelId,
623
623
  modelId = _config$modelId === void 0 ? LOCAL_MLC_CAUSAL_MODEL_ID : _config$modelId,
624
- customModelConfig = config.customModelConfig;
624
+ customModelConfig = config.customModelConfig,
625
+ surface = config.surface;
625
626
 
626
627
  // ── State ──────────────────────────────────────────────────────────────
627
628
  var storedContextVector = null;
@@ -990,10 +991,12 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
990
991
  // the try — post engine-init (parity with the network fetch, which
991
992
  // excludes the one-time model load) and so the catch below always
992
993
  // terminates the experience, even on a synchronous throw.
993
- startExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, experienceId, {
994
+ startExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, experienceId, _objectSpread({
994
995
  textLength: text.length,
995
996
  isLocalLLM: true
996
- });
997
+ }, surface ? {
998
+ surface: surface
999
+ } : {}));
997
1000
  tStart = performance.now();
998
1001
  tLmDone = 0;
999
1002
  tEmbDone = 0;
@@ -1026,9 +1029,11 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
1026
1029
  _context4.next = 4;
1027
1030
  break;
1028
1031
  }
1029
- abortExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, experienceId, destroyed ? 'destroyed' : 'superseded', {
1032
+ abortExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, experienceId, destroyed ? 'destroyed' : 'superseded', _objectSpread({
1030
1033
  isLocalLLM: true
1031
- });
1034
+ }, surface ? {
1035
+ surface: surface
1036
+ } : {}));
1032
1037
  return _context4.abrupt("return");
1033
1038
  case 4:
1034
1039
  // ── LM logits: whole-word BE-parity payload ──────────────────
@@ -1080,12 +1085,14 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
1080
1085
  // eslint-disable-next-line no-console
1081
1086
  console.groupEnd();
1082
1087
  }
1083
- succeedExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, experienceId, {
1088
+ succeedExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, experienceId, _objectSpread({
1084
1089
  textLength: text.length,
1085
1090
  hasVector: storedContextVector !== null,
1086
1091
  hasLmLogits: storedLmLogits !== null,
1087
1092
  isLocalLLM: true
1088
- });
1093
+ }, surface ? {
1094
+ surface: surface
1095
+ } : {}));
1089
1096
  onUpdate === null || onUpdate === void 0 || onUpdate({
1090
1097
  textLength: text.length,
1091
1098
  hasVector: storedContextVector !== null,
@@ -1100,17 +1107,21 @@ export var createLocalSlowLaneClient = function createLocalSlowLaneClient() {
1100
1107
  _context4.next = 6;
1101
1108
  break;
1102
1109
  }
1103
- abortExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, experienceId, destroyed ? 'destroyed' : 'superseded', {
1110
+ abortExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, experienceId, destroyed ? 'destroyed' : 'superseded', _objectSpread({
1104
1111
  isLocalLLM: true
1105
- });
1112
+ }, surface ? {
1113
+ surface: surface
1114
+ } : {}));
1106
1115
  return _context4.abrupt("return");
1107
1116
  case 6:
1108
1117
  storedContextVector = null;
1109
1118
  storedLmLogits = null;
1110
- failExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, experienceId, {
1119
+ failExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, experienceId, _objectSpread({
1111
1120
  errorType: 'inference',
1112
1121
  isLocalLLM: true
1113
- });
1122
+ }, surface ? {
1123
+ surface: surface
1124
+ } : {}));
1114
1125
  onUpdate === null || onUpdate === void 0 || onUpdate({
1115
1126
  textLength: text.length,
1116
1127
  hasVector: false,
@@ -1,6 +1,9 @@
1
1
  import _typeof from "@babel/runtime/helpers/typeof";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
3
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
4
  import _regeneratorRuntime from "@babel/runtime/regenerator";
5
+ 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; }
6
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
7
  /**
5
8
  * Slow Lane Client: Backend context encoding for autocomplete.
6
9
  *
@@ -45,6 +48,7 @@ export var createSlowLaneClient = function createSlowLaneClient(config) {
45
48
  configSessionId = config.sessionId,
46
49
  _config$productKey = config.productKey,
47
50
  productKey = _config$productKey === void 0 ? 'confluence' : _config$productKey,
51
+ surface = config.surface,
48
52
  _config$endpoint = config.endpoint,
49
53
  endpoint = _config$endpoint === void 0 ? '/gateway/api/v1/autocomplete/typeahead-encodings' : _config$endpoint,
50
54
  _config$debounceMs = config.debounceMs,
@@ -81,10 +85,12 @@ export var createSlowLaneClient = function createSlowLaneClient(config) {
81
85
  text: text,
82
86
  session_id: sessionId
83
87
  };
84
- startExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, requestId, {
88
+ startExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, requestId, _objectSpread({
85
89
  textLength: text.length,
86
90
  isLocalLLM: false
87
- });
91
+ }, surface ? {
92
+ surface: surface
93
+ } : {}));
88
94
  if (isAutocompleteDebugEnabled()) {
89
95
  // eslint-disable-next-line no-console
90
96
  console.groupCollapsed("%c[SlowLane] %c\uD83D\uDCE4 Sending context | ".concat(text.length, " chars"), 'color: #9c27b0; font-weight: bold;', 'color: inherit;');
@@ -110,11 +116,13 @@ export var createSlowLaneClient = function createSlowLaneClient(config) {
110
116
  }
111
117
  storedContextVector = null;
112
118
  storedLmLogits = null;
113
- failExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, requestId, {
119
+ failExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, requestId, _objectSpread({
114
120
  status: res.status,
115
121
  errorType: 'http_error',
116
122
  isLocalLLM: false
117
- });
123
+ }, surface ? {
124
+ surface: surface
125
+ } : {}));
118
126
  if (isAutocompleteDebugEnabled()) {
119
127
  // eslint-disable-next-line no-console
120
128
  console.log("%c[SlowLane] %c\u274C Request failed (".concat(res.status, ")"), 'color: #9c27b0; font-weight: bold;', 'color: #f44336;');
@@ -145,12 +153,14 @@ export var createSlowLaneClient = function createSlowLaneClient(config) {
145
153
  // eslint-disable-next-line no-console
146
154
  console.groupEnd();
147
155
  }
148
- succeedExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, requestId, {
156
+ succeedExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, requestId, _objectSpread({
149
157
  textLength: text.length,
150
158
  hasVector: storedContextVector !== null,
151
159
  hasLmLogits: storedLmLogits !== null,
152
160
  isLocalLLM: false
153
- });
161
+ }, surface ? {
162
+ surface: surface
163
+ } : {}));
154
164
  onUpdate === null || onUpdate === void 0 || onUpdate({
155
165
  textLength: text.length,
156
166
  hasVector: storedContextVector !== null,
@@ -164,10 +174,12 @@ export var createSlowLaneClient = function createSlowLaneClient(config) {
164
174
  _t = _context["catch"](2);
165
175
  storedContextVector = null;
166
176
  storedLmLogits = null;
167
- failExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, requestId, {
177
+ failExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, requestId, _objectSpread({
168
178
  errorType: 'network',
169
179
  isLocalLLM: false
170
- });
180
+ }, surface ? {
181
+ surface: surface
182
+ } : {}));
171
183
  if (isAutocompleteDebugEnabled()) {
172
184
  // eslint-disable-next-line no-console
173
185
  console.log('%c[SlowLane] %c❌ Network error — context cleared', 'color: #9c27b0; font-weight: bold;', 'color: #f44336;');
@@ -196,9 +208,11 @@ export var createSlowLaneClient = function createSlowLaneClient(config) {
196
208
  debounceTimer = setTimeout(function () {
197
209
  debounceTimer = null;
198
210
  if (inflightRequestId !== null) {
199
- abortExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, inflightRequestId, 'superseded', {
211
+ abortExp(EXPERIENCE_NAME.SLOW_LANE_FETCH, inflightRequestId, 'superseded', _objectSpread({
200
212
  isLocalLLM: false
201
- });
213
+ }, surface ? {
214
+ surface: surface
215
+ } : {}));
202
216
  }
203
217
  var requestId = String(++requestSeq);
204
218
  inflightRequestId = requestId;
@@ -5,6 +5,8 @@ import _createClass from "@babel/runtime/helpers/createClass";
5
5
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
6
6
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
7
7
  import _regeneratorRuntime from "@babel/runtime/regenerator";
8
+ 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; }
9
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8
10
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
9
11
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
10
12
  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; }
@@ -732,7 +734,7 @@ function unwrapJsonModule(mod, shape) {
732
734
  export var loadVectorsAsync = /*#__PURE__*/function () {
733
735
  var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(options) {
734
736
  var _options$isLocalLLM;
735
- var isLocalLLM, url, _wordIndexOuter$index, res, buffer, float32, wordIndexModule, wordIndexOuter, wordIndex, nWords, dim, _t, _t2;
737
+ var isLocalLLM, surface, url, _wordIndexOuter$index, res, buffer, float32, wordIndexModule, wordIndexOuter, wordIndex, nWords, dim, _t, _t2;
736
738
  return _regeneratorRuntime.wrap(function (_context) {
737
739
  while (1) switch (_context.prev = _context.next) {
738
740
  case 0:
@@ -751,10 +753,13 @@ export var loadVectorsAsync = /*#__PURE__*/function () {
751
753
  return _context.abrupt("return");
752
754
  case 2:
753
755
  isLocalLLM = (_options$isLocalLLM = options === null || options === void 0 ? void 0 : options.isLocalLLM) !== null && _options$isLocalLLM !== void 0 ? _options$isLocalLLM : false;
756
+ surface = options === null || options === void 0 ? void 0 : options.surface;
754
757
  vectorsLoadStarted = true;
755
- startExp(EXPERIENCE_NAME.LOAD_VECTORS, 'singleton', {
758
+ startExp(EXPERIENCE_NAME.LOAD_VECTORS, 'singleton', _objectSpread({
756
759
  isLocalLLM: isLocalLLM
757
- });
760
+ }, surface ? {
761
+ surface: surface
762
+ } : {}));
758
763
  _context.prev = 3;
759
764
  _context.next = 4;
760
765
  return options.getBinaryUrl();
@@ -766,10 +771,12 @@ export var loadVectorsAsync = /*#__PURE__*/function () {
766
771
  _context.prev = 5;
767
772
  _t = _context["catch"](3);
768
773
  vectorsLoadStarted = false;
769
- failExp(EXPERIENCE_NAME.LOAD_VECTORS, 'singleton', {
774
+ failExp(EXPERIENCE_NAME.LOAD_VECTORS, 'singleton', _objectSpread({
770
775
  isLocalLLM: isLocalLLM,
771
776
  errorType: 'resolve_url'
772
- });
777
+ }, surface ? {
778
+ surface: surface
779
+ } : {}));
773
780
  // eslint-disable-next-line no-console
774
781
  console.warn('[text-predictor] Failed to resolve vectors URL:', _t);
775
782
  return _context.abrupt("return");
@@ -784,11 +791,13 @@ export var loadVectorsAsync = /*#__PURE__*/function () {
784
791
  break;
785
792
  }
786
793
  vectorsLoadStarted = false;
787
- failExp(EXPERIENCE_NAME.LOAD_VECTORS, 'singleton', {
794
+ failExp(EXPERIENCE_NAME.LOAD_VECTORS, 'singleton', _objectSpread({
788
795
  isLocalLLM: isLocalLLM,
789
796
  status: res.status,
790
797
  errorType: 'http_error'
791
- });
798
+ }, surface ? {
799
+ surface: surface
800
+ } : {}));
792
801
  // eslint-disable-next-line no-console
793
802
  console.warn("[text-predictor] Failed to load vectors: ".concat(res.status));
794
803
  return _context.abrupt("return");
@@ -817,12 +826,14 @@ export var loadVectorsAsync = /*#__PURE__*/function () {
817
826
  wordIndex: wordIndex,
818
827
  dim: dim
819
828
  };
820
- succeedExp(EXPERIENCE_NAME.LOAD_VECTORS, 'singleton', {
829
+ succeedExp(EXPERIENCE_NAME.LOAD_VECTORS, 'singleton', _objectSpread({
821
830
  isLocalLLM: isLocalLLM,
822
831
  wordCount: nWords,
823
832
  dim: dim,
824
833
  sizeBytes: float32.byteLength
825
- });
834
+ }, surface ? {
835
+ surface: surface
836
+ } : {}));
826
837
  if (isAutocompleteDebugEnabled()) {
827
838
  // eslint-disable-next-line no-console
828
839
  console.log('[text-predictor] Vectors loaded:', {
@@ -837,10 +848,12 @@ export var loadVectorsAsync = /*#__PURE__*/function () {
837
848
  _context.prev = 11;
838
849
  _t2 = _context["catch"](6);
839
850
  vectorsLoadStarted = false;
840
- failExp(EXPERIENCE_NAME.LOAD_VECTORS, 'singleton', {
851
+ failExp(EXPERIENCE_NAME.LOAD_VECTORS, 'singleton', _objectSpread({
841
852
  isLocalLLM: isLocalLLM,
842
853
  errorType: 'network'
843
- });
854
+ }, surface ? {
855
+ surface: surface
856
+ } : {}));
844
857
  // eslint-disable-next-line no-console
845
858
  console.warn('[text-predictor] Failed to load vectors:', _t2);
846
859
  case 12:
@@ -866,14 +879,17 @@ export var loadDefaultVocabulary = function loadDefaultVocabulary(options) {
866
879
  return vocabularyLoadPromise;
867
880
  }
868
881
  var isLocalLLM = (_options$isLocalLLM2 = options === null || options === void 0 ? void 0 : options.isLocalLLM) !== null && _options$isLocalLLM2 !== void 0 ? _options$isLocalLLM2 : false;
882
+ var surface = options === null || options === void 0 ? void 0 : options.surface;
869
883
  vocabularyLoadPromise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
870
884
  var _yield$Promise$all, _yield$Promise$all2, vocabularyModule, l3VocabularyModule, vocabularyData, l3VocabularyData, terms, _t3;
871
885
  return _regeneratorRuntime.wrap(function (_context2) {
872
886
  while (1) switch (_context2.prev = _context2.next) {
873
887
  case 0:
874
- startExp(EXPERIENCE_NAME.LOAD_VOCABULARY, 'singleton', {
888
+ startExp(EXPERIENCE_NAME.LOAD_VOCABULARY, 'singleton', _objectSpread({
875
889
  isLocalLLM: isLocalLLM
876
- });
890
+ }, surface ? {
891
+ surface: surface
892
+ } : {}));
877
893
  _context2.prev = 1;
878
894
  _context2.next = 2;
879
895
  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')]);
@@ -907,20 +923,24 @@ export var loadDefaultVocabulary = function loadDefaultVocabulary(options) {
907
923
  initVocabulary({
908
924
  terms: terms
909
925
  });
910
- succeedExp(EXPERIENCE_NAME.LOAD_VOCABULARY, 'singleton', {
926
+ succeedExp(EXPERIENCE_NAME.LOAD_VOCABULARY, 'singleton', _objectSpread({
911
927
  isLocalLLM: isLocalLLM,
912
928
  l2WordCount: terms.length,
913
929
  l3WordCount: l3VocabularyData.length
914
- });
930
+ }, surface ? {
931
+ surface: surface
932
+ } : {}));
915
933
  _context2.next = 5;
916
934
  break;
917
935
  case 4:
918
936
  _context2.prev = 4;
919
937
  _t3 = _context2["catch"](1);
920
- failExp(EXPERIENCE_NAME.LOAD_VOCABULARY, 'singleton', {
938
+ failExp(EXPERIENCE_NAME.LOAD_VOCABULARY, 'singleton', _objectSpread({
921
939
  isLocalLLM: isLocalLLM,
922
940
  errorType: 'parse_error'
923
- });
941
+ }, surface ? {
942
+ surface: surface
943
+ } : {}));
924
944
  // Allow a later call to retry the load rather than caching the failure.
925
945
  vocabularyLoadPromise = undefined;
926
946
  throw _t3;
@@ -29,6 +29,11 @@ export interface AutocompleteContext {
29
29
  siblingCommentsContents?: string[];
30
30
  }
31
31
  export interface AutocompletePluginOptions {
32
+ /**
33
+ * Product/editor surface where autocomplete runs (e.g. "comment", "chat").
34
+ * Added to analytics and UFO metadata for cross-surface reporting.
35
+ */
36
+ surface?: string;
32
37
  /**
33
38
  * Async function called once on first editor focus to retrieve context for
34
39
  * word-frequency boosting. Called lazily so the preset can remain synchronous.
@@ -72,6 +72,8 @@ export interface LocalSlowLaneClientConfig {
72
72
  hasVector: boolean;
73
73
  textLength: number;
74
74
  }) => void;
75
+ /** Product/editor surface where autocomplete runs. */
76
+ surface?: string;
75
77
  }
76
78
  export interface LocalSlowLaneClient {
77
79
  /** Clean up resources. */
@@ -32,6 +32,7 @@ export interface SlowLaneClientConfig {
32
32
  }) => void;
33
33
  productKey?: string;
34
34
  sessionId?: string;
35
+ surface?: string;
35
36
  }
36
37
  export declare const createSlowLaneClient: (config: SlowLaneClientConfig) => {
37
38
  getContextVector: () => Float32Array | null;
@@ -83,9 +83,11 @@ export declare const predict: (textBefore: string) => string | null;
83
83
  export declare const loadVectorsAsync: (options?: {
84
84
  getBinaryUrl?: () => Promise<string>;
85
85
  isLocalLLM?: boolean;
86
+ surface?: string;
86
87
  }) => Promise<void>;
87
88
  export declare const initVectors: (store: VectorStore) => void;
88
89
  export declare const loadDefaultVocabulary: (options?: {
89
90
  isLocalLLM?: boolean;
91
+ surface?: string;
90
92
  }) => Promise<void>;
91
93
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-autocomplete",
3
- "version": "4.1.0",
3
+ "version": "4.1.1",
4
4
  "description": "Client-side text autocomplete plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -8,7 +8,7 @@
8
8
  "registry": "https://registry.npmjs.org/"
9
9
  },
10
10
  "scripts": {
11
- "ak-postbuild": "ls -d dist/* | grep -v dist/types | xargs -n 1 copyfiles -u 1 -V 'src/pm-plugins/data/*.json'"
11
+ "ak-postbuild": "ls -d dist/* | xargs -n 1 copyfiles -u 1 -V src/pm-plugins/data/*.json"
12
12
  },
13
13
  "atlassian": {
14
14
  "team": "Editor: AI",
@@ -36,9 +36,15 @@
36
36
  },
37
37
  "techstack": {
38
38
  "@atlassian/frontend": {
39
- "code-structure": ["editor-plugin"],
40
- "import-structure": ["atlassian-conventions"],
41
- "circular-dependencies": ["file-and-folder-level"]
39
+ "code-structure": [
40
+ "editor-plugin"
41
+ ],
42
+ "import-structure": [
43
+ "atlassian-conventions"
44
+ ],
45
+ "circular-dependencies": [
46
+ "file-and-folder-level"
47
+ ]
42
48
  }
43
49
  },
44
50
  "devDependencies": {