GHHG10's picture
download
raw
1.37 kB
import { displaySlice } from "./display"
export function stripPromptPartIDs<Part extends { id: string; messageID: string; sessionID: string }>(part: Part) {
const { id: _id, messageID: _messageID, sessionID: _sessionID, ...rest } = part
return rest
}
export function expandPastedTextPlaceholders(text: string, parts: readonly unknown[]) {
return parts.reduce<string>((result, part) => {
if (!isPastedTextPart(part)) return result
return result.replace(part.source.text.value, part.text)
}, text)
}
function isPastedTextPart(part: unknown): part is { type: "text"; text: string; source: { text: { value: string } } } {
if (!part || typeof part !== "object" || !("type" in part) || part.type !== "text") return false
if (!("text" in part) || typeof part.text !== "string" || !("source" in part)) return false
const source = part.source
if (!source || typeof source !== "object" || !("text" in source)) return false
const text = source.text
return Boolean(text && typeof text === "object" && "value" in text && typeof text.value === "string")
}
export function expandTrackedPastedText(text: string, ranges: { start: number; end: number; text: string }[]) {
return ranges
.slice()
.sort((a, b) => b.start - a.start)
.reduce((result, part) => displaySlice(result, 0, part.start) + part.text + displaySlice(result, part.end), text)
}

Xet Storage Details

Size:
1.37 kB
·
Xet hash:
d3ef976a5bb0b0ae9dec0acd7c7449471c73af8d7a49f89f564f2aab3fb3344f

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.