fix(ralph-loop): use inherited fallback context and SDK TUI session selection
This commit is contained in:
parent
6ad615958f
commit
7bb427078a
@ -30,9 +30,9 @@ export async function injectContinuationPrompt(
|
||||
let agent: string | undefined
|
||||
let model: { providerID: string; modelID: string } | undefined
|
||||
let tools: Record<string, boolean | "allow" | "deny" | "ask"> | undefined
|
||||
const sourceSessionID = options.inheritFromSessionID ?? options.sessionID
|
||||
|
||||
try {
|
||||
const sourceSessionID = options.inheritFromSessionID ?? options.sessionID
|
||||
const messagesResp = await withTimeout(
|
||||
ctx.client.session.messages({
|
||||
path: { id: sourceSessionID },
|
||||
@ -54,7 +54,7 @@ export async function injectContinuationPrompt(
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
const messageDir = getMessageDir(options.sessionID)
|
||||
const messageDir = getMessageDir(sourceSessionID)
|
||||
const currentMessage = messageDir ? findNearestMessageWithFields(messageDir) : null
|
||||
agent = currentMessage?.agent
|
||||
model =
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import type { PluginInput } from "@opencode-ai/plugin"
|
||||
import { getServerBasicAuthHeader } from "../../shared/opencode-server-auth"
|
||||
import { getServerBaseUrl, log } from "../../shared"
|
||||
import { log } from "../../shared"
|
||||
|
||||
export async function createIterationSession(
|
||||
ctx: PluginInput,
|
||||
@ -30,36 +29,44 @@ export async function selectSessionInTui(
|
||||
client: PluginInput["client"],
|
||||
sessionID: string,
|
||||
): Promise<boolean> {
|
||||
const baseUrl = getServerBaseUrl(client)
|
||||
const authorization = getServerBasicAuthHeader()
|
||||
|
||||
if (!baseUrl || !authorization) {
|
||||
const selectSession = getSelectSessionApi(client)
|
||||
if (!selectSession) {
|
||||
return false
|
||||
}
|
||||
|
||||
const response = await fetch(`${baseUrl}/tui/select-session`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: authorization,
|
||||
},
|
||||
body: JSON.stringify({ sessionID }),
|
||||
signal: AbortSignal.timeout(5000),
|
||||
}).catch((error: unknown) => {
|
||||
try {
|
||||
await selectSession({ body: { sessionID } })
|
||||
return true
|
||||
} catch (error: unknown) {
|
||||
log("[ralph-loop] Failed to select session in TUI", {
|
||||
sessionID,
|
||||
error: String(error),
|
||||
})
|
||||
return null
|
||||
})
|
||||
|
||||
if (!response?.ok) {
|
||||
log("[ralph-loop] TUI session select request failed", {
|
||||
sessionID,
|
||||
status: response?.status,
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
type SelectSessionApi = (args: { body: { sessionID: string } }) => Promise<unknown>
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null
|
||||
}
|
||||
|
||||
function getSelectSessionApi(client: unknown): SelectSessionApi | null {
|
||||
if (!isRecord(client)) {
|
||||
return null
|
||||
}
|
||||
|
||||
const clientRecord = client
|
||||
const tuiValue = clientRecord.tui
|
||||
if (!isRecord(tuiValue)) {
|
||||
return null
|
||||
}
|
||||
|
||||
const selectSessionValue = tuiValue.selectSession
|
||||
if (typeof selectSessionValue !== "function") {
|
||||
return null
|
||||
}
|
||||
|
||||
return selectSessionValue as SelectSessionApi
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user