mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
Improve token streaming support with character-by-character matching
Co-Authored-By: Jack Hacksman <slack@hannis.io>
This commit is contained in:
parent
2f55580e67
commit
4c5e444bcb
1 changed files with 23 additions and 7 deletions
|
|
@ -396,14 +396,27 @@ class ThinkTagSurroundingsRemover extends SurroundingsRemover {
|
||||||
}
|
}
|
||||||
|
|
||||||
removeThinkTags() {
|
removeThinkTags() {
|
||||||
// Handle token streaming character by character
|
// Handle token streaming at a more granular level
|
||||||
const chars = ['<', 't', 'h', 'i', 'n', 'k', '>'];
|
let foundTag = false;
|
||||||
let foundTag = true;
|
|
||||||
|
|
||||||
for (const char of chars) {
|
// Try to remove opening tag, handling partial tokens
|
||||||
if (!this.removePrefix(char)) {
|
foundTag = this.removePrefix('<');
|
||||||
foundTag = false;
|
if (foundTag) {
|
||||||
break;
|
foundTag = this.removePrefix('t');
|
||||||
|
if (foundTag) {
|
||||||
|
foundTag = this.removePrefix('h');
|
||||||
|
if (foundTag) {
|
||||||
|
foundTag = this.removePrefix('i');
|
||||||
|
if (foundTag) {
|
||||||
|
foundTag = this.removePrefix('n');
|
||||||
|
if (foundTag) {
|
||||||
|
foundTag = this.removePrefix('k');
|
||||||
|
if (foundTag) {
|
||||||
|
foundTag = this.removePrefix('>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -411,7 +424,10 @@ class ThinkTagSurroundingsRemover extends SurroundingsRemover {
|
||||||
}
|
}
|
||||||
|
|
||||||
deltaInfo(recentlyAddedTextLen: number) {
|
deltaInfo(recentlyAddedTextLen: number) {
|
||||||
|
// Get the delta and suffix from parent class
|
||||||
const [delta, ignoredSuffix] = super.deltaInfo(recentlyAddedTextLen);
|
const [delta, ignoredSuffix] = super.deltaInfo(recentlyAddedTextLen);
|
||||||
|
|
||||||
|
// Strip any think tags from the delta before returning
|
||||||
return [stripThinkTags(delta), ignoredSuffix] as const;
|
return [stripThinkTags(delta), ignoredSuffix] as const;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue