continue-custom/core/autocomplete/charStream.ts
Nate Sesti 34b40f4f53
Dev (#1627)
* docs: add docs and schema for "OS" provider (#1536)

* ignore .env

* ✨ use and cache imports for autocomplete (#1456)

* ✨ use and cache imports for autocomplete

* fix tsc

* add voyage rerank-1

* import Handlebars

* feat: open pane on install (#1564)

* feat: open pane on activation

* comment out testing code

* chore: add telemetry for pageviews (#1576)

* feat: update onboarding w/ embeddings model (#1570)

* chore(gui): remove unused pages

* feat: add embeddings step

* feat: update styles

* feat: copy button updates

* fix: correct pull command for embed model

* fix: remove commented code

* fix: remove commented code

* feat: simplify copy btn props

* chore: rename onboarding selection event

* feat: add provider config

* fix: undo msg name

* remove dead code

* fix: invalid mode check

* fix: remove testing logic

* fix: fullscreen gui retains context when hidden, fixed fullscreen focusing (#1582)

* small UI tweaks

* media query

* feat: add best experience onboarding

* small fixes

* feat: add free trial card to onboarding (#1600)

* feat: add free trial card to onboarding

* add import

* chore: add telemetry for full screen toggle (#1618)

* rerank-lite-1

* remove doccs

* basic tests for VS Code extension

* improved testing of VS Code extension

* manually implement stop tokens for hf inference api

* chore: onboarding metrics (#1626)

* fix: pageview tracking

* feat: add onboarding telemetry

* create single `onboardingStatus` type

* improved var naming

* remove console logs

* fix windows performance issue

* rename vscodeExtension.ts

* migration of onboarding variables

---------

Co-authored-by: Patrick Erichsen <patrick.a.erichsen@gmail.com>
Co-authored-by: Jonah Wagner <jonahwagner231@gmail.com>
2024-07-01 21:34:06 -07:00

82 lines
1.8 KiB
TypeScript

export async function* onlyWhitespaceAfterEndOfLine(
stream: AsyncGenerator<string>,
endOfLine: string[],
fullStop: () => void,
): AsyncGenerator<string> {
let pending = "";
for await (let chunk of stream) {
chunk = pending + chunk;
pending = "";
for (let i = 0; i < chunk.length - 1; i++) {
if (
endOfLine.includes(chunk[i]) &&
chunk[i + 1].trim() === chunk[i + 1]
) {
yield chunk.slice(0, i + 1);
fullStop();
return;
}
}
if (endOfLine.includes(chunk[chunk.length - 1])) {
pending = chunk[chunk.length - 1];
yield chunk.slice(0, chunk.length - 1);
} else {
yield chunk;
}
}
yield pending;
}
export async function* noFirstCharNewline(stream: AsyncGenerator<string>) {
let first = true;
for await (const char of stream) {
if (first) {
first = false;
if (char.startsWith("\n") || char.startsWith("\r")) {
return;
}
}
yield char;
}
}
export async function* stopAtStopTokens(
stream: AsyncGenerator<string>,
stopTokens: string[],
): AsyncGenerator<string> {
if (stopTokens.length === 0) {
for await (const char of stream) {
yield char;
}
return;
}
const maxStopTokenLength = Math.max(
...stopTokens.map((token) => token.length),
);
let buffer = "";
for await (const chunk of stream) {
buffer += chunk;
while (buffer.length >= maxStopTokenLength) {
let found = false;
for (const stopToken of stopTokens) {
if (buffer.startsWith(stopToken)) {
found = true;
return;
}
}
if (!found) {
yield buffer[0];
buffer = buffer.slice(1);
}
}
}
// Yield any remaining characters in the buffer
for (const char of buffer) {
yield char;
}
}