@atlaskit/editor-plugin-autocomplete 3.6.0 → 3.6.2

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.
Files changed (40) hide show
  1. package/CANONICAL_FIX__DO_NOT_USE_ME_A/package.json +1 -8
  2. package/CANONICAL_FIX__DO_NOT_USE_ME_B/package.json +1 -8
  3. package/CANONICAL_FIX__DO_NOT_USE_ME_C/package.json +1 -8
  4. package/CHANGELOG.md +21 -0
  5. package/autocompletePlugin/package.json +1 -8
  6. package/autocompletePluginType/package.json +1 -8
  7. package/dist/cjs/pm-plugins/autocomplete-plugin.js +20 -2
  8. package/dist/cjs/pm-plugins/local-slow-lane-client.js +3 -1
  9. package/dist/cjs/pm-plugins/text-predictor.js +18 -4
  10. package/dist/es2019/pm-plugins/autocomplete-plugin.js +20 -2
  11. package/dist/es2019/pm-plugins/local-slow-lane-client.js +3 -1
  12. package/dist/es2019/pm-plugins/text-predictor.js +17 -3
  13. package/dist/esm/pm-plugins/autocomplete-plugin.js +20 -2
  14. package/dist/esm/pm-plugins/local-slow-lane-client.js +3 -1
  15. package/dist/esm/pm-plugins/text-predictor.js +18 -4
  16. package/dist/types/pm-plugins/local-slow-lane-client.d.ts +2 -2
  17. package/dist/types/pm-plugins/text-predictor.d.ts +4 -1
  18. package/package.json +2 -2
  19. package/src/pm-plugins/autocomplete-plugin/package.json +1 -8
  20. package/src/pm-plugins/autocomplete-plugin.ts +18 -2
  21. package/src/pm-plugins/local-slow-lane-client.ts +10 -17
  22. package/src/pm-plugins/slow-lane-client/package.json +1 -8
  23. package/src/pm-plugins/text-predictor/package.json +1 -8
  24. package/src/pm-plugins/text-predictor.ts +15 -6
  25. package/dist/types-ts4.5/analytics/ufo.d.ts +0 -38
  26. package/dist/types-ts4.5/autocompletePlugin.d.ts +0 -2
  27. package/dist/types-ts4.5/autocompletePluginType.d.ts +0 -10
  28. package/dist/types-ts4.5/entry-points/autocompletePlugin.d.ts +0 -1
  29. package/dist/types-ts4.5/entry-points/autocompletePluginType.d.ts +0 -1
  30. package/dist/types-ts4.5/entry-points/src-pm-plugins-autocomplete-plugin.d.ts +0 -2
  31. package/dist/types-ts4.5/entry-points/src-pm-plugins-slow-lane-client.d.ts +0 -2
  32. package/dist/types-ts4.5/entry-points/src-pm-plugins-text-predictor.d.ts +0 -2
  33. package/dist/types-ts4.5/index.d.ts +0 -2
  34. package/dist/types-ts4.5/pm-plugins/autocomplete-plugin.d.ts +0 -49
  35. package/dist/types-ts4.5/pm-plugins/debug-mode.d.ts +0 -27
  36. package/dist/types-ts4.5/pm-plugins/ghost-text-decoration.d.ts +0 -7
  37. package/dist/types-ts4.5/pm-plugins/local-slow-lane-client.d.ts +0 -241
  38. package/dist/types-ts4.5/pm-plugins/scoring-pipeline.d.ts +0 -43
  39. package/dist/types-ts4.5/pm-plugins/slow-lane-client.d.ts +0 -46
  40. package/dist/types-ts4.5/pm-plugins/text-predictor.d.ts +0 -88
@@ -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
- /** GPU architecture reported by the adapter (e.g. "metal-3", "rdna2"). */
100
- architecture?: string;
101
- /** Whether `navigator.gpu.requestAdapter()` returned a usable adapter. */
102
- adapterAvailable?: boolean;
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,88 +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
- }) => Promise<void>;
86
- export declare const initVectors: (store: VectorStore) => void;
87
- export declare const loadDefaultVocabulary: () => Promise<void>;
88
- export {};