fix(session-recovery): fallback when stored unavailable-tool parts are absent
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -13,6 +13,10 @@ mock.module("./storage", () => ({
|
|||||||
readParts: () => storedParts,
|
readParts: () => storedParts,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
mock.module("./storage/parts-reader", () => ({
|
||||||
|
readParts: () => storedParts,
|
||||||
|
}))
|
||||||
|
|
||||||
const { recoverUnavailableTool } = await import("./recover-unavailable-tool")
|
const { recoverUnavailableTool } = await import("./recover-unavailable-tool")
|
||||||
|
|
||||||
const failedAssistantMsg: MessageData = {
|
const failedAssistantMsg: MessageData = {
|
||||||
@@ -82,7 +86,10 @@ describe("recoverUnavailableTool", () => {
|
|||||||
tool: "bash",
|
tool: "bash",
|
||||||
state: { input: {} },
|
state: { input: {} },
|
||||||
}]
|
}]
|
||||||
const { client, promptAsync } = createMockClient()
|
const { client, promptAsync } = createMockClient([{
|
||||||
|
info: { id: "msg_failed", role: "assistant" },
|
||||||
|
parts: [{ type: "tool", id: "prt_stored_valid_call", callID: "toolu_recovered", name: "bash", input: {} }],
|
||||||
|
}])
|
||||||
|
|
||||||
//#when
|
//#when
|
||||||
const result = await recoverUnavailableTool(client, "ses_2", failedAssistantMsg)
|
const result = await recoverUnavailableTool(client, "ses_2", failedAssistantMsg)
|
||||||
|
|||||||
@@ -83,11 +83,13 @@ export async function recoverUnavailableTool(
|
|||||||
parts = await readPartsFromSDKFallback(client, sessionID, failedAssistantMsg.info.id)
|
parts = await readPartsFromSDKFallback(client, sessionID, failedAssistantMsg.info.id)
|
||||||
} else {
|
} else {
|
||||||
const storedParts = readParts(failedAssistantMsg.info.id)
|
const storedParts = readParts(failedAssistantMsg.info.id)
|
||||||
parts = storedParts.map((part) => ({
|
parts = storedParts.length > 0
|
||||||
type: part.type === "tool" ? "tool_use" : part.type,
|
? storedParts.map((part) => ({
|
||||||
id: "callID" in part ? (part as { callID?: string }).callID : part.id,
|
type: part.type === "tool" ? "tool_use" : part.type,
|
||||||
name: "tool" in part && typeof part.tool === "string" ? part.tool : undefined,
|
id: "callID" in part ? (part as { callID?: string }).callID : part.id,
|
||||||
}))
|
name: "tool" in part && typeof part.tool === "string" ? part.tool : undefined,
|
||||||
|
}))
|
||||||
|
: await readPartsFromSDKFallback(client, sessionID, failedAssistantMsg.info.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user