mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 10:58:10 +00:00
* refactor: use concrete browser and input owners * refactor: bind remote runtime callers to concrete transport owners * Use checked subscription mock argument types * Type browser lease mock with its subscription contract * refactor: bind sleeping VM status probe test to socket owner
33 lines
980 B
TypeScript
33 lines
980 B
TypeScript
import { getUtf8ChunkEndIndex, measureUtf8ByteLength } from './utf8-byte-limits'
|
|
|
|
export const BROWSER_TEXT_INSERT_CHUNK_BYTES = 64 * 1024
|
|
|
|
export function splitBrowserTextInsertionChunks(
|
|
text: string,
|
|
maxChunkBytes = BROWSER_TEXT_INSERT_CHUNK_BYTES
|
|
): string[] {
|
|
return [...iterateBrowserTextInsertionChunks(text, maxChunkBytes)]
|
|
}
|
|
|
|
export function* iterateBrowserTextInsertionChunks(
|
|
text: string,
|
|
maxChunkBytes = BROWSER_TEXT_INSERT_CHUNK_BYTES
|
|
): Generator<string> {
|
|
if (text.length === 0) {
|
|
return
|
|
}
|
|
const normalizedMax = Number.isFinite(maxChunkBytes) && maxChunkBytes > 0 ? maxChunkBytes : 1
|
|
const measurement = measureUtf8ByteLength(text, { stopAfterBytes: normalizedMax })
|
|
if (!measurement.exceededLimit) {
|
|
yield text
|
|
return
|
|
}
|
|
|
|
let startIndex = 0
|
|
while (startIndex < text.length) {
|
|
const endIndex = getUtf8ChunkEndIndex(text, startIndex, normalizedMax)
|
|
yield text.slice(startIndex, endIndex)
|
|
startIndex = endIndex
|
|
}
|
|
}
|