feat: implement SQLite backend for injectTextPart via HTTP PATCH
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
import { existsSync, mkdirSync, writeFileSync } from "node:fs"
|
||||
import { join } from "node:path"
|
||||
import type { PluginInput } from "@opencode-ai/plugin"
|
||||
import { PART_STORAGE } from "../constants"
|
||||
import type { StoredTextPart } from "../types"
|
||||
import { generatePartId } from "./part-id"
|
||||
import { log, isSqliteBackend } from "../../../shared"
|
||||
import { log, isSqliteBackend, patchPart } from "../../../shared"
|
||||
|
||||
type OpencodeClient = PluginInput["client"]
|
||||
|
||||
export function injectTextPart(sessionID: string, messageID: string, text: string): boolean {
|
||||
if (isSqliteBackend()) {
|
||||
log("[session-recovery] Disabled on SQLite backend: injectTextPart")
|
||||
log("[session-recovery] Disabled on SQLite backend: injectTextPart (use async variant)")
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -34,3 +37,27 @@ export function injectTextPart(sessionID: string, messageID: string, text: strin
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export async function injectTextPartAsync(
|
||||
client: OpencodeClient,
|
||||
sessionID: string,
|
||||
messageID: string,
|
||||
text: string
|
||||
): Promise<boolean> {
|
||||
const partId = generatePartId()
|
||||
const part: Record<string, unknown> = {
|
||||
id: partId,
|
||||
sessionID,
|
||||
messageID,
|
||||
type: "text",
|
||||
text,
|
||||
synthetic: true,
|
||||
}
|
||||
|
||||
try {
|
||||
return await patchPart(client, sessionID, messageID, partId, part)
|
||||
} catch (error) {
|
||||
log("[session-recovery] injectTextPartAsync failed", { error: String(error) })
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user