804895b24a
- Gate session-recovery writes: injectTextPart, prependThinkingPart, replaceEmptyTextParts, stripThinkingParts - Gate context-window-recovery writes: truncateToolResult - Add isSqliteBackend() checks with log warnings - Create beta-degraded-features.md documentation
37 lines
938 B
TypeScript
37 lines
938 B
TypeScript
import { existsSync, mkdirSync, writeFileSync } from "node:fs"
|
|
import { join } from "node:path"
|
|
import { PART_STORAGE } from "../constants"
|
|
import type { StoredTextPart } from "../types"
|
|
import { generatePartId } from "./part-id"
|
|
import { log, isSqliteBackend } from "../../../shared"
|
|
|
|
export function injectTextPart(sessionID: string, messageID: string, text: string): boolean {
|
|
if (isSqliteBackend()) {
|
|
log("[session-recovery] Disabled on SQLite backend: injectTextPart")
|
|
return false
|
|
}
|
|
|
|
const partDir = join(PART_STORAGE, messageID)
|
|
|
|
if (!existsSync(partDir)) {
|
|
mkdirSync(partDir, { recursive: true })
|
|
}
|
|
|
|
const partId = generatePartId()
|
|
const part: StoredTextPart = {
|
|
id: partId,
|
|
sessionID,
|
|
messageID,
|
|
type: "text",
|
|
text,
|
|
synthetic: true,
|
|
}
|
|
|
|
try {
|
|
writeFileSync(join(partDir, `${partId}.json`), JSON.stringify(part, null, 2))
|
|
return true
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|