feat: implement SQLite backend for injectTextPart via HTTP PATCH
This commit is contained in:
parent
049a259332
commit
c771eb5acd
@ -1,13 +1,16 @@
|
|||||||
import { existsSync, mkdirSync, writeFileSync } from "node:fs"
|
import { existsSync, mkdirSync, writeFileSync } from "node:fs"
|
||||||
import { join } from "node:path"
|
import { join } from "node:path"
|
||||||
|
import type { PluginInput } from "@opencode-ai/plugin"
|
||||||
import { PART_STORAGE } from "../constants"
|
import { PART_STORAGE } from "../constants"
|
||||||
import type { StoredTextPart } from "../types"
|
import type { StoredTextPart } from "../types"
|
||||||
import { generatePartId } from "./part-id"
|
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 {
|
export function injectTextPart(sessionID: string, messageID: string, text: string): boolean {
|
||||||
if (isSqliteBackend()) {
|
if (isSqliteBackend()) {
|
||||||
log("[session-recovery] Disabled on SQLite backend: injectTextPart")
|
log("[session-recovery] Disabled on SQLite backend: injectTextPart (use async variant)")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,3 +37,27 @@ export function injectTextPart(sessionID: string, messageID: string, text: strin
|
|||||||
return false
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user