@atlaskit/editor-plugin-autocomplete 3.6.1 → 4.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 +1 -8
- package/CANONICAL_FIX__DO_NOT_USE_ME_B/package.json +1 -8
- package/CANONICAL_FIX__DO_NOT_USE_ME_C/package.json +1 -8
- package/CHANGELOG.md +39 -0
- package/autocompletePlugin/package.json +1 -8
- package/autocompletePluginType/package.json +1 -8
- package/package.json +5 -13
- package/src/pm-plugins/autocomplete-plugin/package.json +1 -8
- package/src/pm-plugins/autocomplete-plugin.ts +12 -12
- package/src/pm-plugins/local-slow-lane-client.ts +6 -14
- package/src/pm-plugins/slow-lane-client/package.json +1 -8
- package/src/pm-plugins/text-predictor/package.json +1 -8
- package/src/pm-plugins/text-predictor.ts +4 -1
- package/dist/types-ts4.5/analytics/ufo.d.ts +0 -38
- package/dist/types-ts4.5/autocompletePlugin.d.ts +0 -2
- package/dist/types-ts4.5/autocompletePluginType.d.ts +0 -10
- package/dist/types-ts4.5/entry-points/autocompletePlugin.d.ts +0 -1
- package/dist/types-ts4.5/entry-points/autocompletePluginType.d.ts +0 -1
- package/dist/types-ts4.5/entry-points/src-pm-plugins-autocomplete-plugin.d.ts +0 -2
- package/dist/types-ts4.5/entry-points/src-pm-plugins-slow-lane-client.d.ts +0 -2
- package/dist/types-ts4.5/entry-points/src-pm-plugins-text-predictor.d.ts +0 -2
- package/dist/types-ts4.5/index.d.ts +0 -2
- package/dist/types-ts4.5/pm-plugins/autocomplete-plugin.d.ts +0 -49
- package/dist/types-ts4.5/pm-plugins/debug-mode.d.ts +0 -27
- package/dist/types-ts4.5/pm-plugins/ghost-text-decoration.d.ts +0 -7
- package/dist/types-ts4.5/pm-plugins/local-slow-lane-client.d.ts +0 -241
- package/dist/types-ts4.5/pm-plugins/scoring-pipeline.d.ts +0 -43
- package/dist/types-ts4.5/pm-plugins/slow-lane-client.d.ts +0 -46
- package/dist/types-ts4.5/pm-plugins/text-predictor.d.ts +0 -91
|
@@ -4,12 +4,5 @@
|
|
|
4
4
|
"module": "../dist/esm/pm-plugins/autocomplete-plugin.js",
|
|
5
5
|
"module:es2019": "../dist/es2019/pm-plugins/autocomplete-plugin.js",
|
|
6
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
|
-
}
|
|
7
|
+
"types": "../dist/types/pm-plugins/autocomplete-plugin.d.ts"
|
|
15
8
|
}
|
|
@@ -4,12 +4,5 @@
|
|
|
4
4
|
"module": "../dist/esm/pm-plugins/slow-lane-client.js",
|
|
5
5
|
"module:es2019": "../dist/es2019/pm-plugins/slow-lane-client.js",
|
|
6
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
|
-
}
|
|
7
|
+
"types": "../dist/types/pm-plugins/slow-lane-client.d.ts"
|
|
15
8
|
}
|
|
@@ -4,12 +4,5 @@
|
|
|
4
4
|
"module": "../dist/esm/pm-plugins/text-predictor.js",
|
|
5
5
|
"module:es2019": "../dist/es2019/pm-plugins/text-predictor.js",
|
|
6
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
|
-
}
|
|
7
|
+
"types": "../dist/types/pm-plugins/text-predictor.d.ts"
|
|
15
8
|
}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-autocomplete
|
|
2
2
|
|
|
3
|
+
## 4.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [`f2dc9097319f0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f2dc9097319f0) - ###
|
|
8
|
+
Dropped support for _legacy_ Typescript 4 types. **Typescript 5 is now the new minimum**.
|
|
9
|
+
|
|
10
|
+
Removes the `typesVersions` property and `dist/types-ts4.5` directory from the dist.
|
|
11
|
+
|
|
12
|
+
Types are now exclusively via the `"types": "dist/types/index.d.ts"` property.
|
|
13
|
+
|
|
14
|
+
```diff
|
|
15
|
+
- "typesVersions": {
|
|
16
|
+
- ">=4.5 <4.9": {
|
|
17
|
+
- "*": [
|
|
18
|
+
- "dist/types-ts4.5/*",
|
|
19
|
+
- "dist/types-ts4.5/index.d.ts"
|
|
20
|
+
- ]
|
|
21
|
+
- }
|
|
22
|
+
- },
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- [`f92001e22291e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f92001e22291e) -
|
|
28
|
+
Reverts the mid-word cursor suppression for ghost-text suggestions. Autocomplete suggestions will
|
|
29
|
+
again appear regardless of cursor position within a word.
|
|
30
|
+
- Updated dependencies
|
|
31
|
+
|
|
32
|
+
## 3.6.2
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- [`8ed22a585196f`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/8ed22a585196f) -
|
|
37
|
+
[ux] Fixes a bug where autocomplete suggestions were shown when the cursor was positioned in the
|
|
38
|
+
middle of an existing word. Suggestions are now suppressed unless the cursor is at the trailing
|
|
39
|
+
edge of a token.
|
|
40
|
+
- Updated dependencies
|
|
41
|
+
|
|
3
42
|
## 3.6.1
|
|
4
43
|
|
|
5
44
|
### Patch Changes
|
|
@@ -4,12 +4,5 @@
|
|
|
4
4
|
"module": "../dist/esm/entry-points/autocompletePlugin.js",
|
|
5
5
|
"module:es2019": "../dist/es2019/entry-points/autocompletePlugin.js",
|
|
6
6
|
"sideEffects": false,
|
|
7
|
-
"types": "../dist/types/entry-points/autocompletePlugin.d.ts"
|
|
8
|
-
"typesVersions": {
|
|
9
|
-
">=4.5 <5.9": {
|
|
10
|
-
"*": [
|
|
11
|
-
"../dist/types-ts4.5/entry-points/autocompletePlugin.d.ts"
|
|
12
|
-
]
|
|
13
|
-
}
|
|
14
|
-
}
|
|
7
|
+
"types": "../dist/types/entry-points/autocompletePlugin.d.ts"
|
|
15
8
|
}
|
|
@@ -4,12 +4,5 @@
|
|
|
4
4
|
"module": "../dist/esm/entry-points/autocompletePluginType.js",
|
|
5
5
|
"module:es2019": "../dist/es2019/entry-points/autocompletePluginType.js",
|
|
6
6
|
"sideEffects": false,
|
|
7
|
-
"types": "../dist/types/entry-points/autocompletePluginType.d.ts"
|
|
8
|
-
"typesVersions": {
|
|
9
|
-
">=4.5 <5.9": {
|
|
10
|
-
"*": [
|
|
11
|
-
"../dist/types-ts4.5/entry-points/autocompletePluginType.d.ts"
|
|
12
|
-
]
|
|
13
|
-
}
|
|
14
|
-
}
|
|
7
|
+
"types": "../dist/types/entry-points/autocompletePluginType.d.ts"
|
|
15
8
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-autocomplete",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.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",
|
|
@@ -16,27 +16,19 @@
|
|
|
16
16
|
"module": "dist/esm/index.js",
|
|
17
17
|
"module:es2019": "dist/es2019/index.js",
|
|
18
18
|
"types": "dist/types/index.d.ts",
|
|
19
|
-
"typesVersions": {
|
|
20
|
-
">=4.5 <4.9": {
|
|
21
|
-
"*": [
|
|
22
|
-
"dist/types-ts4.5/*",
|
|
23
|
-
"dist/types-ts4.5/index.d.ts"
|
|
24
|
-
]
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
19
|
"sideEffects": false,
|
|
28
20
|
"atlaskit:src": "src/index.ts",
|
|
29
21
|
"dependencies": {
|
|
30
|
-
"@atlaskit/editor-prosemirror": "^
|
|
31
|
-
"@atlaskit/ufo": "^0.
|
|
22
|
+
"@atlaskit/editor-prosemirror": "^8.0.0",
|
|
23
|
+
"@atlaskit/ufo": "^1.0.0",
|
|
32
24
|
"@babel/runtime": "^7.0.0",
|
|
33
25
|
"@mlc-ai/web-llm": "^0.2.78",
|
|
34
26
|
"compromise": "^14.15.0",
|
|
35
27
|
"wink-nlp": "^2.4.0"
|
|
36
28
|
},
|
|
37
29
|
"peerDependencies": {
|
|
38
|
-
"@atlaskit/editor-common": "^
|
|
39
|
-
"@atlaskit/editor-plugin-analytics": "^
|
|
30
|
+
"@atlaskit/editor-common": "^116.0.0",
|
|
31
|
+
"@atlaskit/editor-plugin-analytics": "^12.0.0",
|
|
40
32
|
"react": "^18.2.0"
|
|
41
33
|
},
|
|
42
34
|
"techstack": {
|
|
@@ -4,12 +4,5 @@
|
|
|
4
4
|
"module": "../../../dist/esm/entry-points/src-pm-plugins-autocomplete-plugin.js",
|
|
5
5
|
"module:es2019": "../../../dist/es2019/entry-points/src-pm-plugins-autocomplete-plugin.js",
|
|
6
6
|
"sideEffects": false,
|
|
7
|
-
"types": "../../../dist/types/entry-points/src-pm-plugins-autocomplete-plugin.d.ts"
|
|
8
|
-
"typesVersions": {
|
|
9
|
-
">=4.5 <5.9": {
|
|
10
|
-
"*": [
|
|
11
|
-
"../../../dist/types-ts4.5/entry-points/src-pm-plugins-autocomplete-plugin.d.ts"
|
|
12
|
-
]
|
|
13
|
-
}
|
|
14
|
-
}
|
|
7
|
+
"types": "../../../dist/types/entry-points/src-pm-plugins-autocomplete-plugin.d.ts"
|
|
15
8
|
}
|
|
@@ -680,20 +680,20 @@ export const createAutocompletePlugin = (
|
|
|
680
680
|
}
|
|
681
681
|
return false;
|
|
682
682
|
},
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
683
|
+
focus: () => {
|
|
684
|
+
loadDefaultVocabulary({ isLocalLLM: options?.useLocalModel ?? false }).catch((error) => {
|
|
685
|
+
logException(error as Error, {
|
|
686
|
+
location: 'editor-plugin-autocomplete/loadDefaultVocabulary',
|
|
687
|
+
});
|
|
687
688
|
});
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
689
|
+
loadVectorsAsync({
|
|
690
|
+
getBinaryUrl: options?.getVectorsBinaryUrl,
|
|
691
|
+
isLocalLLM: options?.useLocalModel ?? false,
|
|
692
|
+
}).catch((error) => {
|
|
693
|
+
logException(error as Error, {
|
|
694
|
+
location: 'editor-plugin-autocomplete/loadVectorsAsync',
|
|
695
|
+
});
|
|
695
696
|
});
|
|
696
|
-
});
|
|
697
697
|
if (!hasIngestedPage) {
|
|
698
698
|
hasIngestedPage = true;
|
|
699
699
|
refreshContext({
|
|
@@ -367,16 +367,14 @@ let bePayloadDataPromise: Promise<void> | undefined;
|
|
|
367
367
|
* :param shape: `'object'` if the source JSON is `{...}`, `'array'` if `[...]`.
|
|
368
368
|
* :returns: The parsed JSON value, or `null` if neither interop mode applies.
|
|
369
369
|
*/
|
|
370
|
-
const unwrapJsonModule = <T
|
|
370
|
+
const unwrapJsonModule = <T>(mod: unknown, shape: 'object' | 'array'): T | null => {
|
|
371
371
|
if (mod == null || typeof mod !== 'object') {
|
|
372
372
|
return null;
|
|
373
373
|
}
|
|
374
374
|
const namespace = mod as Record<string, unknown> & { default?: unknown };
|
|
375
375
|
|
|
376
376
|
// Compute the named-export own-keys (strip synthetic markers).
|
|
377
|
-
const ownKeys = Object.keys(namespace).filter(
|
|
378
|
-
(k) => k !== 'default' && k !== '__esModule',
|
|
379
|
-
);
|
|
377
|
+
const ownKeys = Object.keys(namespace).filter((k) => k !== 'default' && k !== '__esModule');
|
|
380
378
|
|
|
381
379
|
// PREFER named exports when present — they always reflect the JSON's real
|
|
382
380
|
// top-level keys / indices, regardless of what `default` happens to be.
|
|
@@ -456,10 +454,7 @@ const loadBePayloadData = (): Promise<void> => {
|
|
|
456
454
|
}
|
|
457
455
|
|
|
458
456
|
firstTokenToWords = new Map(
|
|
459
|
-
Object.entries(firstTokenToWordsData).map(([tokenId, words]) => [
|
|
460
|
-
Number(tokenId),
|
|
461
|
-
words,
|
|
462
|
-
]),
|
|
457
|
+
Object.entries(firstTokenToWordsData).map(([tokenId, words]) => [Number(tokenId), words]),
|
|
463
458
|
);
|
|
464
459
|
l2Words = new Set(Object.keys(vocabularyData.words));
|
|
465
460
|
prefixMapTokenIds = Array.from(firstTokenToWords.keys());
|
|
@@ -519,7 +514,6 @@ export const computeBePayload = (
|
|
|
519
514
|
*/
|
|
520
515
|
validTokenIds: number[] = prefixMapTokenIds,
|
|
521
516
|
): Record<string, number> => {
|
|
522
|
-
|
|
523
517
|
// 1. Numerically-stable masked softmax over validTokenIds only.
|
|
524
518
|
let maxLogit = -Infinity;
|
|
525
519
|
for (const id of validTokenIds) {
|
|
@@ -1006,7 +1000,7 @@ export const createLocalSlowLaneClient = (
|
|
|
1006
1000
|
const lmText = truncateToLastNWords(text, BE_PARITY.MAX_CONTEXT_TOKENS);
|
|
1007
1001
|
const semanticText = truncateToLastNWords(text, BE_PARITY.MAX_CONTEXT_WORDS);
|
|
1008
1002
|
const arcticInput = wrapForArctic(semanticText);
|
|
1009
|
-
const captureCompletionTime = <T
|
|
1003
|
+
const captureCompletionTime = <T>(
|
|
1010
1004
|
promise: Promise<T>,
|
|
1011
1005
|
onResolved: (resolvedAt: number) => void,
|
|
1012
1006
|
): Promise<T> =>
|
|
@@ -1043,8 +1037,7 @@ export const createLocalSlowLaneClient = (
|
|
|
1043
1037
|
max_tokens: 1,
|
|
1044
1038
|
temperature: 0,
|
|
1045
1039
|
logprobs: false,
|
|
1046
|
-
})
|
|
1047
|
-
,
|
|
1040
|
+
}),
|
|
1048
1041
|
(resolvedAt) => {
|
|
1049
1042
|
tLmDone = resolvedAt;
|
|
1050
1043
|
},
|
|
@@ -1053,8 +1046,7 @@ export const createLocalSlowLaneClient = (
|
|
|
1053
1046
|
engine.embeddings.create({
|
|
1054
1047
|
model: LOCAL_MLC_EMBEDDING_MODEL_ID,
|
|
1055
1048
|
input: arcticInput,
|
|
1056
|
-
})
|
|
1057
|
-
,
|
|
1049
|
+
}),
|
|
1058
1050
|
(resolvedAt) => {
|
|
1059
1051
|
tEmbDone = resolvedAt;
|
|
1060
1052
|
},
|
|
@@ -4,12 +4,5 @@
|
|
|
4
4
|
"module": "../../../dist/esm/entry-points/src-pm-plugins-slow-lane-client.js",
|
|
5
5
|
"module:es2019": "../../../dist/es2019/entry-points/src-pm-plugins-slow-lane-client.js",
|
|
6
6
|
"sideEffects": false,
|
|
7
|
-
"types": "../../../dist/types/entry-points/src-pm-plugins-slow-lane-client.d.ts"
|
|
8
|
-
"typesVersions": {
|
|
9
|
-
">=4.5 <5.9": {
|
|
10
|
-
"*": [
|
|
11
|
-
"../../../dist/types-ts4.5/entry-points/src-pm-plugins-slow-lane-client.d.ts"
|
|
12
|
-
]
|
|
13
|
-
}
|
|
14
|
-
}
|
|
7
|
+
"types": "../../../dist/types/entry-points/src-pm-plugins-slow-lane-client.d.ts"
|
|
15
8
|
}
|
|
@@ -4,12 +4,5 @@
|
|
|
4
4
|
"module": "../../../dist/esm/entry-points/src-pm-plugins-text-predictor.js",
|
|
5
5
|
"module:es2019": "../../../dist/es2019/entry-points/src-pm-plugins-text-predictor.js",
|
|
6
6
|
"sideEffects": false,
|
|
7
|
-
"types": "../../../dist/types/entry-points/src-pm-plugins-text-predictor.d.ts"
|
|
8
|
-
"typesVersions": {
|
|
9
|
-
">=4.5 <5.9": {
|
|
10
|
-
"*": [
|
|
11
|
-
"../../../dist/types-ts4.5/entry-points/src-pm-plugins-text-predictor.d.ts"
|
|
12
|
-
]
|
|
13
|
-
}
|
|
14
|
-
}
|
|
7
|
+
"types": "../../../dist/types/entry-points/src-pm-plugins-text-predictor.d.ts"
|
|
15
8
|
}
|
|
@@ -889,7 +889,10 @@ export const loadDefaultVocabulary = (options?: { isLocalLLM?: boolean }): Promi
|
|
|
889
889
|
l3WordCount: l3VocabularyData.length,
|
|
890
890
|
});
|
|
891
891
|
} catch (e) {
|
|
892
|
-
failExp(EXPERIENCE_NAME.LOAD_VOCABULARY, 'singleton', {
|
|
892
|
+
failExp(EXPERIENCE_NAME.LOAD_VOCABULARY, 'singleton', {
|
|
893
|
+
isLocalLLM,
|
|
894
|
+
errorType: 'parse_error',
|
|
895
|
+
});
|
|
893
896
|
// Allow a later call to retry the load rather than caching the failure.
|
|
894
897
|
vocabularyLoadPromise = undefined;
|
|
895
898
|
throw e;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* UFO experience tracking helpers for `@atlaskit/editor-plugin-autocomplete`.
|
|
3
|
-
*
|
|
4
|
-
* Pattern follows `packages/linking-platform/smart-card/src/state/analytics/ufoExperiences.ts`
|
|
5
|
-
* (ConcurrentExperience keyed per request/instance) plus a try/catch safety wrap
|
|
6
|
-
* inspired by `packages/editor/collab-provider/src/analytics/ufo.ts` so a UFO
|
|
7
|
-
* runtime error can never break the autocomplete feature.
|
|
8
|
-
*
|
|
9
|
-
* Experience names must be registered in DataPortal's `task` attribute before
|
|
10
|
-
* they can power FE Reliability SLOs:
|
|
11
|
-
* https://hello.atlassian.net/wiki/spaces/AA6/pages/3961393753
|
|
12
|
-
*/
|
|
13
|
-
import { type CustomData } from '@atlaskit/ufo';
|
|
14
|
-
/**
|
|
15
|
-
* Experience name strings are surfaced downstream by the UFO pipeline as
|
|
16
|
-
* `platform.fe.<type>.<platform.component>.<name>` (e.g.
|
|
17
|
-
* `platform.fe.operation.editor-plugin-autocomplete.slow-lane-fetch`), so
|
|
18
|
-
* names here should be short, dot-free, and must not repeat the component
|
|
19
|
-
* name. This matches the convention used by `@atlaskit/emoji`'s
|
|
20
|
-
* `ufoExperiences` map (e.g. `'emoji-rendered'`).
|
|
21
|
-
*/
|
|
22
|
-
/**
|
|
23
|
-
* Only experiences with meaningful async work and a real success/failure
|
|
24
|
-
* outcome belong on UFO (which measures latency and success rate for FE
|
|
25
|
-
* Reliability SLOs). Per-keystroke suggestion lifecycle counters (viewed /
|
|
26
|
-
* inserted / dismissed) are tracked via analytics-next instead — they would
|
|
27
|
-
* otherwise emit zero-duration events on every word boundary.
|
|
28
|
-
*/
|
|
29
|
-
export declare const EXPERIENCE_NAME: {
|
|
30
|
-
readonly SLOW_LANE_FETCH: "slow-lane-fetch";
|
|
31
|
-
readonly LOAD_VOCABULARY: "load-vocabulary";
|
|
32
|
-
readonly LOAD_VECTORS: "load-vectors";
|
|
33
|
-
};
|
|
34
|
-
export type AutocompleteExperienceName = (typeof EXPERIENCE_NAME)[keyof typeof EXPERIENCE_NAME];
|
|
35
|
-
export declare const startExp: (name: AutocompleteExperienceName, id: string, metadata?: CustomData) => void;
|
|
36
|
-
export declare const succeedExp: (name: AutocompleteExperienceName, id: string, metadata?: CustomData) => void;
|
|
37
|
-
export declare const failExp: (name: AutocompleteExperienceName, id: string, metadata?: CustomData) => void;
|
|
38
|
-
export declare const abortExp: (name: AutocompleteExperienceName, id: string, reason?: string) => void;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
|
-
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
3
|
-
import type { AutocompletePluginOptions, AutocompletePluginState } from './pm-plugins/autocomplete-plugin';
|
|
4
|
-
export type AutocompletePlugin = NextEditorPlugin<'autocomplete', {
|
|
5
|
-
pluginConfiguration?: AutocompletePluginOptions | undefined;
|
|
6
|
-
sharedState: AutocompletePluginState | undefined;
|
|
7
|
-
dependencies: [
|
|
8
|
-
OptionalPlugin<AnalyticsPlugin>
|
|
9
|
-
];
|
|
10
|
-
}>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { autocompletePlugin } from '../autocompletePlugin';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type { AutocompletePlugin } from '../autocompletePluginType';
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export { createSlowLaneClient, getStoredContextVector, getStoredLmLogits, isWordBoundary, setDefaultSlowLaneClient, } from '../pm-plugins/slow-lane-client';
|
|
2
|
-
export type { SlowLaneClientConfig, TypeaheadEncodingsRequest, TypeaheadEncodingsResponse, } from '../pm-plugins/slow-lane-client';
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export { getLastPredictionDebug, getPredictorStatus, incrementSessionFreq, ingestDocumentPage, initL3Vocabulary, initVectors, initVocabulary, loadDefaultVocabulary, loadVectorsAsync, predict, } from '../pm-plugins/text-predictor';
|
|
2
|
-
export type { TenantVocabulary, WeightedTerm } from '../pm-plugins/text-predictor';
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
-
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
-
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
-
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
5
|
-
import type { AutocompletePlugin } from '../autocompletePluginType';
|
|
6
|
-
export declare const autocompletePluginKey: PluginKey;
|
|
7
|
-
export interface AutocompletePluginState {
|
|
8
|
-
/** The decoration set containing the ghost text widget */
|
|
9
|
-
decorationSet: DecorationSet;
|
|
10
|
-
/** The document position where the ghost text should appear */
|
|
11
|
-
ghostPosition: number;
|
|
12
|
-
/** The predicted ghost text to display */
|
|
13
|
-
ghostText: string;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Context provided to the autocomplete plugin on first editor focus.
|
|
17
|
-
* Text fields are selectively ingested to boost word-frequency scoring for
|
|
18
|
-
* predictions, giving words already present in the document/thread an L1
|
|
19
|
-
* priority boost.
|
|
20
|
-
*/
|
|
21
|
-
export interface AutocompleteContext {
|
|
22
|
-
/** Full page content as a string (e.g. markdown). */
|
|
23
|
-
fullPageContent?: string;
|
|
24
|
-
/** The currently selected text on the page, if any. */
|
|
25
|
-
pageSelectionContent?: string;
|
|
26
|
-
/** Content of the parent comment when the editor is in reply or edit mode. */
|
|
27
|
-
parentCommentContent?: string;
|
|
28
|
-
/** Contents of sibling comments when the editor is in reply or edit mode. */
|
|
29
|
-
siblingCommentsContents?: string[];
|
|
30
|
-
}
|
|
31
|
-
export interface AutocompletePluginOptions {
|
|
32
|
-
/**
|
|
33
|
-
* Async function called once on first editor focus to retrieve context for
|
|
34
|
-
* word-frequency boosting. Called lazily so the preset can remain synchronous.
|
|
35
|
-
*/
|
|
36
|
-
getContext?: () => Promise<AutocompleteContext | undefined>;
|
|
37
|
-
/**
|
|
38
|
-
* Async function that resolves to a URL for the word vectors binary file.
|
|
39
|
-
* When provided, this takes precedence over the bundled asset URL.
|
|
40
|
-
* Use this to serve vectors from a CDN or media service in production.
|
|
41
|
-
*/
|
|
42
|
-
getVectorsBinaryUrl?: () => Promise<string>;
|
|
43
|
-
/**
|
|
44
|
-
* When true, uses on-device inference via WebGPU (MLC WebLLM) instead of
|
|
45
|
-
* the network-based slow-lane backend. Defaults to false (network client).
|
|
46
|
-
*/
|
|
47
|
-
useLocalModel?: boolean;
|
|
48
|
-
}
|
|
49
|
-
export declare const createAutocompletePlugin: (options?: AutocompletePluginOptions, api?: ExtractInjectionAPI<AutocompletePlugin>) => SafePlugin<AutocompletePluginState>;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Contextual Typeahead Completions (CTC) debug logging utility.
|
|
3
|
-
*
|
|
4
|
-
* Logs are silent by default. Enable in any environment (dev, staging, prod):
|
|
5
|
-
*
|
|
6
|
-
* // Live, for the current session (no reload required):
|
|
7
|
-
* __atlCtcDebug__.enable()
|
|
8
|
-
*
|
|
9
|
-
* // To disable:
|
|
10
|
-
* __atlCtcDebug__.disable()
|
|
11
|
-
*
|
|
12
|
-
* // From initial page load (survives reload) — append to the URL:
|
|
13
|
-
* ?atlCtcDebug=1
|
|
14
|
-
*
|
|
15
|
-
* Storage-free by design: avoids browser-storage consent controls (BSC), which can
|
|
16
|
-
* block uncategorized localStorage/sessionStorage/cookie writes in some products.
|
|
17
|
-
*/
|
|
18
|
-
declare global {
|
|
19
|
-
interface Window {
|
|
20
|
-
__atlCtcDebug__?: {
|
|
21
|
-
enable: () => void;
|
|
22
|
-
disable: () => void;
|
|
23
|
-
isEnabled: () => boolean;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
export declare const isAutocompleteDebugEnabled: () => boolean;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
-
/**
|
|
4
|
-
* Creates a DecorationSet containing a ghost text widget at the given position.
|
|
5
|
-
* The ghost text is rendered as a styled <span> that appears after the cursor.
|
|
6
|
-
*/
|
|
7
|
-
export declare const createGhostTextDecorationSet: (state: EditorState, position: number, text: string) => DecorationSet;
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Local Slow Lane Client: On-device inference via @mlc-ai/web-llm.
|
|
3
|
-
*
|
|
4
|
-
* Drop-in replacement for the network-based slow-lane-client. Instead of calling
|
|
5
|
-
* a backend API, this client runs two models in the browser via WebGPU, in a
|
|
6
|
-
* single MLCEngine, to reproduce the BE encoder's outputs on-device:
|
|
7
|
-
*
|
|
8
|
-
* - Causal LM (SmolLM2-135M-Instruct): one decode step per word boundary. A
|
|
9
|
-
* registered LogitProcessor captures the raw next-token logits, which
|
|
10
|
-
* `computeBePayload` turns into a whole-word `lm_logits` payload — a faithful
|
|
11
|
-
* port of the BE `CausalLMEncoder._get_top_k_probs` (masked softmax over the
|
|
12
|
-
* vocab's first-tokens, prefix expansion, L2 reservation, log-space pooling).
|
|
13
|
-
* - Semantic embedder (Snowflake Arctic Embed S): produces the real 384-d
|
|
14
|
-
* `semantic_vector`. Inputs are wrapped as passages (see `wrapForArctic`) so
|
|
15
|
-
* the runtime vector lands in the same space as the precomputed word bin.
|
|
16
|
-
*
|
|
17
|
-
* ── Why main thread (no Web Worker)? ─────────────────────────────────────
|
|
18
|
-
* The models are small enough (~640 MB combined VRAM) that WebGPU inference on
|
|
19
|
-
* the main thread is viable:
|
|
20
|
-
*
|
|
21
|
-
* - WebGPU GPU compute is inherently async (doesn't block the main thread)
|
|
22
|
-
* - CPU overhead (BE-parity post-processing) is a few ms
|
|
23
|
-
* - Per-inference latency is well within autocomplete expectations
|
|
24
|
-
* (~250 ms between word boundaries)
|
|
25
|
-
*
|
|
26
|
-
* This avoids all the complexity of Web Workers:
|
|
27
|
-
* - No CSP workarounds (blob URLs, inline scripts)
|
|
28
|
-
* - No bundler configuration (worker-plugin, import.meta.url)
|
|
29
|
-
* - No message passing protocol
|
|
30
|
-
* - Standard npm import — just works
|
|
31
|
-
*
|
|
32
|
-
* ── Interface ────────────────────────────────────────────────────────────
|
|
33
|
-
* Same shape as createSlowLaneClient so text-predictor.ts needs zero changes.
|
|
34
|
-
* The client exposes getContextVector() and getLmLogits() which are populated
|
|
35
|
-
* asynchronously after each updateContext() call.
|
|
36
|
-
*/
|
|
37
|
-
export interface LocalSlowLaneClientConfig {
|
|
38
|
-
/**
|
|
39
|
-
* Optional custom model registration for models not in web-llm's
|
|
40
|
-
* built-in list. When provided, the model is appended to the app
|
|
41
|
-
* config before engine creation.
|
|
42
|
-
*/
|
|
43
|
-
customModelConfig?: {
|
|
44
|
-
/** Context window size override (optional) */
|
|
45
|
-
contextWindowSize?: number;
|
|
46
|
-
/** HuggingFace URL to the model weights (e.g. "https://huggingface.co/HuggingFaceTB/smollm-135M-instruct-add-basics-q0f16-MLC") */
|
|
47
|
-
model: string;
|
|
48
|
-
/** URL to the compiled WASM library for this model architecture */
|
|
49
|
-
modelLib: string;
|
|
50
|
-
/** VRAM required in MB (optional, for resource planning) */
|
|
51
|
-
vramRequiredMB?: number;
|
|
52
|
-
};
|
|
53
|
-
/** Debounce interval in ms before sending context for inference. */
|
|
54
|
-
debounceMs?: number;
|
|
55
|
-
/**
|
|
56
|
-
* MLC model identifier.
|
|
57
|
-
* Defaults to the built-in SmolLM2-135M-Instruct-q0f16-MLC.
|
|
58
|
-
*
|
|
59
|
-
* To use a custom HuggingFace model, provide both `modelId` and
|
|
60
|
-
* `customModelConfig` with the model URL and WASM library URL.
|
|
61
|
-
*/
|
|
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;
|
|
67
|
-
/** Callback fired with status messages (model loading progress, etc.). */
|
|
68
|
-
onStatus?: (message: string) => void;
|
|
69
|
-
/** Callback fired when inference returns new results. */
|
|
70
|
-
onUpdate?: (opts: {
|
|
71
|
-
hasLmLogits: boolean;
|
|
72
|
-
hasVector: boolean;
|
|
73
|
-
textLength: number;
|
|
74
|
-
}) => void;
|
|
75
|
-
}
|
|
76
|
-
export interface LocalSlowLaneClient {
|
|
77
|
-
/** Clean up resources. */
|
|
78
|
-
destroy: () => void;
|
|
79
|
-
getContextVector: () => Float32Array | null;
|
|
80
|
-
getLmLogits: () => Record<string, number> | null;
|
|
81
|
-
/** Whether the model is loaded and ready for inference. */
|
|
82
|
-
isReady: () => boolean;
|
|
83
|
-
isWordBoundary: (text: string) => boolean;
|
|
84
|
-
setContextVector: (vector: Float32Array | null) => void;
|
|
85
|
-
setLmLogits: (logits: Record<string, number> | null) => void;
|
|
86
|
-
updateContext: (text: string) => void;
|
|
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
|
-
}
|
|
136
|
-
export declare const LOCAL_MLC_CAUSAL_MODEL_ID = "SmolLM2-135M-Instruct-q0f16-MLC";
|
|
137
|
-
/**
|
|
138
|
-
* MLC ID for the semantic embedder (Snowflake Arctic Embed S, batch=4 variant).
|
|
139
|
-
*
|
|
140
|
-
* The `-b4` suffix selects the prebuilt variant compiled for a max batch size of
|
|
141
|
-
* 4 (≈239 MB VRAM) rather than `-b32` (≈1023 MB VRAM). Autocomplete embeds one
|
|
142
|
-
* context at a time, so `-b4` is the right fit. This model IS in
|
|
143
|
-
* `prebuiltAppConfig.model_list` of web-llm 0.2.82 — no `customModelConfig` needed.
|
|
144
|
-
*/
|
|
145
|
-
export declare const LOCAL_MLC_EMBEDDING_MODEL_ID = "snowflake-arctic-embed-s-q0f32-MLC-b4";
|
|
146
|
-
/**
|
|
147
|
-
* Wrap raw context text with BERT special tokens before embedding.
|
|
148
|
-
*
|
|
149
|
-
* web-llm's `EmbeddingPipeline` does NOT auto-prepend `[CLS]` / append `[SEP]`
|
|
150
|
-
* (the official MLC embeddings example wraps manually). The Python
|
|
151
|
-
* `sentence_transformers` side that generated the word-vector bin adds these
|
|
152
|
-
* inside `model.encode()`, so we must mirror it here for the runtime context
|
|
153
|
-
* vector to land in the same region of Arctic's embedding space as the bin.
|
|
154
|
-
*
|
|
155
|
-
* No query prefix is applied: the semantic step is sentence-to-sentence (`s2s`)
|
|
156
|
-
* similarity ("which words are conceptually similar to this context?"), not
|
|
157
|
-
* sentence-to-passage (`s2p`) retrieval. Arctic's query prefix would misframe
|
|
158
|
-
* the relationship. Encode both sides as passages. See implementation.md §4.3.
|
|
159
|
-
*/
|
|
160
|
-
export declare const wrapForArctic: (text: string) => string;
|
|
161
|
-
/**
|
|
162
|
-
* BE-parity constants — must match `CausalLMEncoder` defaults in the Python
|
|
163
|
-
* sidecar (`cc-smarts/python-sidecar/src/causal_lm_encoder.py`) and
|
|
164
|
-
* `SlowLaneEngine` (`typeahead_context_encoding.py`) so local payloads behave
|
|
165
|
-
* identically to the server-client setup.
|
|
166
|
-
*/
|
|
167
|
-
export declare const BE_PARITY: {
|
|
168
|
-
/** Final payload size cap (BE: `top_k_words`). */
|
|
169
|
-
readonly TOP_K_WORDS: 2000;
|
|
170
|
-
/** L2 (domain) words admitted unconditionally before pooling (BE: `reserved_l2_slots`). */
|
|
171
|
-
readonly RESERVED_L2_SLOTS: 500;
|
|
172
|
-
/** Log-space additive bias favouring L2 over L3 in the pool (BE: `l2_bias`). */
|
|
173
|
-
readonly L2_BIAS: 1;
|
|
174
|
-
/** Drop words below this probability from the final payload (BE: `> 0.00001`). */
|
|
175
|
-
readonly MIN_PROB: 0.00001;
|
|
176
|
-
/**
|
|
177
|
-
* Word-level approximation of the BE causal LM token limit.
|
|
178
|
-
*
|
|
179
|
-
* BE: `CausalLMEncoder.max_context_tokens = 100` (BPE tokens, left-truncated).
|
|
180
|
-
* FE: no tokenizer available, so we approximate with word count. English text
|
|
181
|
-
* averages ~1.3–1.5 BPE tokens/word, meaning 100 words ≈ 130–150 tokens.
|
|
182
|
-
* Using 100 words keeps the approximation simple and errs on the side of
|
|
183
|
-
* sending slightly more context than the BE sees — acceptable for a PoC.
|
|
184
|
-
*/
|
|
185
|
-
readonly MAX_CONTEXT_TOKENS: 100;
|
|
186
|
-
/**
|
|
187
|
-
* Word-level rolling window for the semantic embedder.
|
|
188
|
-
*
|
|
189
|
-
* BE: `SlowLaneEngine.max_context_words = 100` (applied in
|
|
190
|
-
* `typeahead_context_encoding.py` before calling `SemanticEncoder.encode`).
|
|
191
|
-
* Truncated identically here so the runtime Arctic vector lands in the same
|
|
192
|
-
* region of the embedding space as the precomputed word-vector bin.
|
|
193
|
-
*/
|
|
194
|
-
readonly MAX_CONTEXT_WORDS: 100;
|
|
195
|
-
};
|
|
196
|
-
/**
|
|
197
|
-
* Convert a raw next-token logit vector into a whole-word probability payload,
|
|
198
|
-
* faithfully porting the BE `CausalLMEncoder._get_top_k_probs`
|
|
199
|
-
* (`cc-smarts/python-sidecar/src/causal_lm_encoder.py`).
|
|
200
|
-
*
|
|
201
|
-
* Steps: (1) numerically-stable masked softmax over only the token ids present
|
|
202
|
-
* in the prefix-expansion map; (2) spread each token's probability to every
|
|
203
|
-
* whole word sharing that first token, taking the max; (3) reserve the top L2
|
|
204
|
-
* words unconditionally; (4) rank the remainder in a log-space pool with an
|
|
205
|
-
* additive L2 bias; (5) emit raw probabilities for the survivors, lowercased
|
|
206
|
-
* and trimmed at `MIN_PROB`.
|
|
207
|
-
*
|
|
208
|
-
* :params:
|
|
209
|
-
* rawLogits: Full-vocabulary logits from the LM's single decode step
|
|
210
|
-
* prefixMap: Map of first-token id to the words starting with that token
|
|
211
|
-
* domainWords: Set of L2 (domain) words, for tier-aware ranking
|
|
212
|
-
* :returns:
|
|
213
|
-
* A record of lowercase word to probability — the BE `lm_logits` payload
|
|
214
|
-
*/
|
|
215
|
-
export declare const computeBePayload: (rawLogits: Float32Array, prefixMap: Map<number, string[]>, domainWords: Set<string>,
|
|
216
|
-
/**
|
|
217
|
-
* Pre-derived token-ID array for the softmax mask. Defaults to the
|
|
218
|
-
* module-level `prefixMapTokenIds` (zero allocation in production). Pass
|
|
219
|
-
* `Array.from(prefixMap.keys())` in tests that supply a custom prefixMap so
|
|
220
|
-
* the softmax mask stays consistent with the iteration in Step 2.
|
|
221
|
-
*/
|
|
222
|
-
validTokenIds?: number[]) => Record<string, number>;
|
|
223
|
-
/**
|
|
224
|
-
* Create a local slow-lane client powered by MLC WebLLM.
|
|
225
|
-
*
|
|
226
|
-
* The engine is initialised lazily — model weights are downloaded (and cached
|
|
227
|
-
* in IndexedDB) on first use. Subsequent page loads skip the download.
|
|
228
|
-
*
|
|
229
|
-
* Usage:
|
|
230
|
-
* ```ts
|
|
231
|
-
* const client = createLocalSlowLaneClient({ debounceMs: 300 });
|
|
232
|
-
* // On word boundaries:
|
|
233
|
-
* client.updateContext(docText);
|
|
234
|
-
* // In scoring pipeline:
|
|
235
|
-
* const vec = client.getContextVector();
|
|
236
|
-
* const logits = client.getLmLogits();
|
|
237
|
-
* // On plugin teardown:
|
|
238
|
-
* client.destroy();
|
|
239
|
-
* ```
|
|
240
|
-
*/
|
|
241
|
-
export declare const createLocalSlowLaneClient: (config?: LocalSlowLaneClientConfig) => LocalSlowLaneClient;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Scoring Pipeline: Stage 1 (Semantic + Frequency), Grammar Filter, Stage 2 (LM Re-ranking).
|
|
3
|
-
*
|
|
4
|
-
* Operates synchronously on pre-loaded data. Each stage gracefully degrades
|
|
5
|
-
* when its required data isn't available (cold → warm → full warm).
|
|
6
|
-
*/
|
|
7
|
-
export interface ScoringCandidate {
|
|
8
|
-
authorFreq: number;
|
|
9
|
-
docFreq: number;
|
|
10
|
-
sessionFreq: number;
|
|
11
|
-
tenantFreq: number;
|
|
12
|
-
word: string;
|
|
13
|
-
}
|
|
14
|
-
export interface ScoredCandidate {
|
|
15
|
-
finalScore: number;
|
|
16
|
-
freqScore: number;
|
|
17
|
-
lmScore: number;
|
|
18
|
-
semanticScore: number;
|
|
19
|
-
word: string;
|
|
20
|
-
}
|
|
21
|
-
/** Metadata returned by the grammar filter for debug logging in the caller. */
|
|
22
|
-
export interface GrammarFilterMeta {
|
|
23
|
-
after: number;
|
|
24
|
-
before: number;
|
|
25
|
-
dropped: string[];
|
|
26
|
-
prevTags: string[];
|
|
27
|
-
prevWord: string;
|
|
28
|
-
}
|
|
29
|
-
export declare const STAGE1_WEIGHT = 0.35;
|
|
30
|
-
export declare const STAGE2_WEIGHT = 0.65;
|
|
31
|
-
export declare const MIN_STAGE1_SCORE = 0.35;
|
|
32
|
-
export interface PipelineDebug {
|
|
33
|
-
final: number;
|
|
34
|
-
grammarRejected: string[];
|
|
35
|
-
initial: number;
|
|
36
|
-
stage1Rejected: string[];
|
|
37
|
-
}
|
|
38
|
-
export interface RankCandidatesResult {
|
|
39
|
-
candidates: ScoredCandidate[];
|
|
40
|
-
grammarMeta: GrammarFilterMeta | null;
|
|
41
|
-
pipelineDebug: PipelineDebug;
|
|
42
|
-
}
|
|
43
|
-
export declare function rankCandidates(candidates: ScoringCandidate[], contextVector: Float32Array | null, getWordVector: (word: string) => Float32Array | null, lmLogits: Record<string, number> | null, maxTenantFreq: number, previousWord: string): RankCandidatesResult;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Slow Lane Client: Backend context encoding for autocomplete.
|
|
3
|
-
*
|
|
4
|
-
* Fires a BE request on word boundaries to encode document context.
|
|
5
|
-
* Expects the typeahead-encodings API format:
|
|
6
|
-
* Request: { text, session_id }
|
|
7
|
-
* Response: { semantic_vector: number[], lm_logits: Record<string, number> }
|
|
8
|
-
*/
|
|
9
|
-
/** Request payload for typeahead-encodings endpoint. */
|
|
10
|
-
export interface TypeaheadEncodingsRequest {
|
|
11
|
-
session_id: string;
|
|
12
|
-
text: string;
|
|
13
|
-
}
|
|
14
|
-
/** Response from typeahead-encodings endpoint. */
|
|
15
|
-
export interface TypeaheadEncodingsResponse {
|
|
16
|
-
lm_logits: Record<string, number>;
|
|
17
|
-
semantic_vector: number[];
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Check if text ends with a word boundary character (space or punctuation).
|
|
21
|
-
*/
|
|
22
|
-
export declare const isWordBoundary: (text: string) => boolean;
|
|
23
|
-
export interface SlowLaneClientConfig {
|
|
24
|
-
baseUrl: string;
|
|
25
|
-
debounceMs?: number;
|
|
26
|
-
endpoint?: string;
|
|
27
|
-
fetchFn?: typeof fetch;
|
|
28
|
-
onUpdate?: (opts: {
|
|
29
|
-
hasLmLogits: boolean;
|
|
30
|
-
hasVector: boolean;
|
|
31
|
-
textLength: number;
|
|
32
|
-
}) => void;
|
|
33
|
-
productKey?: string;
|
|
34
|
-
sessionId?: string;
|
|
35
|
-
}
|
|
36
|
-
export declare const createSlowLaneClient: (config: SlowLaneClientConfig) => {
|
|
37
|
-
getContextVector: () => Float32Array | null;
|
|
38
|
-
getLmLogits: () => Record<string, number> | null;
|
|
39
|
-
isWordBoundary: (text: string) => boolean;
|
|
40
|
-
setContextVector: (vector: Float32Array | null) => void;
|
|
41
|
-
setLmLogits: (logits: Record<string, number> | null) => void;
|
|
42
|
-
updateContext: (text: string) => void;
|
|
43
|
-
};
|
|
44
|
-
export declare const setDefaultSlowLaneClient: (client: ReturnType<typeof createSlowLaneClient> | null) => void;
|
|
45
|
-
export declare const getStoredContextVector: () => Float32Array | null;
|
|
46
|
-
export declare const getStoredLmLogits: () => Record<string, number> | null;
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fast Lane Predictor: Local autocomplete using weighted trie + frequency + semantic scoring.
|
|
3
|
-
*
|
|
4
|
-
* Two prediction modes:
|
|
5
|
-
* 1. Word boundary → bigram-based next-word suggestion (grammar-filtered)
|
|
6
|
-
* 2. Mid-word (≥3 chars) → trie prefix search → scoring pipeline → top result
|
|
7
|
-
*
|
|
8
|
-
* Scoring is delegated to scoring-pipeline.ts which handles:
|
|
9
|
-
* Stage 1 (semantic + frequency), grammar filter, Stage 2 (optional LM re-ranking).
|
|
10
|
-
*
|
|
11
|
-
* Context vector: average of word vectors from text before cursor (last N words).
|
|
12
|
-
* Falls back to cold mode (freq-only) when vectors not yet loaded.
|
|
13
|
-
*
|
|
14
|
-
* Session personalization (L1): words the user types are incrementally boosted
|
|
15
|
-
* via incrementSessionFreq(), called on word boundaries from the plugin.
|
|
16
|
-
*/
|
|
17
|
-
export interface WeightedTerm {
|
|
18
|
-
authorFreq: number;
|
|
19
|
-
docFreq: number;
|
|
20
|
-
freq: number;
|
|
21
|
-
word: string;
|
|
22
|
-
}
|
|
23
|
-
export interface TenantVocabulary {
|
|
24
|
-
terms: WeightedTerm[];
|
|
25
|
-
}
|
|
26
|
-
interface VectorStore {
|
|
27
|
-
dim: number;
|
|
28
|
-
float32: Float32Array;
|
|
29
|
-
wordIndex: Record<string, number>;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Loads the General English vocabulary.
|
|
33
|
-
* expects a simple array of strings: ["about", "above", "actually", ...]
|
|
34
|
-
*/
|
|
35
|
-
export declare const initL3Vocabulary: (l3Words: string[]) => void;
|
|
36
|
-
/**
|
|
37
|
-
* Get predictor status for debugging.
|
|
38
|
-
* vectorsLoaded: true when semantic scoring is active
|
|
39
|
-
* wordCount: number of words in vector store (0 if not loaded)
|
|
40
|
-
*/
|
|
41
|
-
export declare const getPredictorStatus: () => {
|
|
42
|
-
isInitialized: boolean;
|
|
43
|
-
vectorsLoaded: boolean;
|
|
44
|
-
vectorsLoadStarted: boolean;
|
|
45
|
-
wordCount: number;
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Get details of the last prediction (for debugging).
|
|
49
|
-
* Returns null if no prediction has run yet or debug was off.
|
|
50
|
-
*/
|
|
51
|
-
export declare const getLastPredictionDebug: () => {
|
|
52
|
-
contextWords: string[];
|
|
53
|
-
currentWord: string;
|
|
54
|
-
mode: "cold" | "warm";
|
|
55
|
-
suggestion: string | null;
|
|
56
|
-
textBefore: string;
|
|
57
|
-
topCandidates: Array<{
|
|
58
|
-
finalScore: number;
|
|
59
|
-
freqScore: number;
|
|
60
|
-
lmScore: number;
|
|
61
|
-
semanticScore: number;
|
|
62
|
-
word: string;
|
|
63
|
-
}>;
|
|
64
|
-
} | null;
|
|
65
|
-
export declare const initVocabulary: (vocabulary: TenantVocabulary) => void;
|
|
66
|
-
/**
|
|
67
|
-
* Increment L1 session frequency for a single word.
|
|
68
|
-
* Called from the plugin on word boundaries for efficient incremental boosting.
|
|
69
|
-
*/
|
|
70
|
-
export declare const incrementSessionFreq: (word: string) => void;
|
|
71
|
-
/**
|
|
72
|
-
* Prime session frequencies from a document page string.
|
|
73
|
-
*
|
|
74
|
-
* Iterates through every token in `pageContent` and increments its session
|
|
75
|
-
* frequency so that words already present on the page receive an L1 boost
|
|
76
|
-
* before the user starts typing.
|
|
77
|
-
*
|
|
78
|
-
* Pass `undefined` (or omit the argument) to skip priming — useful when the
|
|
79
|
-
* calling context does not yet have a page value available.
|
|
80
|
-
*/
|
|
81
|
-
export declare const ingestDocumentPage: (pageContent: string | undefined) => void;
|
|
82
|
-
export declare const predict: (textBefore: string) => string | null;
|
|
83
|
-
export declare const loadVectorsAsync: (options?: {
|
|
84
|
-
getBinaryUrl?: () => Promise<string>;
|
|
85
|
-
isLocalLLM?: boolean;
|
|
86
|
-
}) => Promise<void>;
|
|
87
|
-
export declare const initVectors: (store: VectorStore) => void;
|
|
88
|
-
export declare const loadDefaultVocabulary: (options?: {
|
|
89
|
-
isLocalLLM?: boolean;
|
|
90
|
-
}) => Promise<void>;
|
|
91
|
-
export {};
|