fix(runtime-fallback): normalize retry part message extraction
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -1,22 +1,9 @@
|
|||||||
type MessageItem = {
|
import { extractSessionMessages } from "./session-messages"
|
||||||
info?: Record<string, unknown>
|
|
||||||
parts?: Array<{ type?: string; text?: string }>
|
|
||||||
}
|
|
||||||
|
|
||||||
function extractMessages(messagesResponse: unknown): MessageItem[] | undefined {
|
|
||||||
if (messagesResponse == null) return undefined
|
|
||||||
if (Array.isArray(messagesResponse)) return messagesResponse as MessageItem[]
|
|
||||||
if (typeof messagesResponse === "object") {
|
|
||||||
const data = (messagesResponse as Record<string, unknown>).data
|
|
||||||
if (Array.isArray(data)) return data as MessageItem[]
|
|
||||||
}
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getLastUserRetryParts(
|
export function getLastUserRetryParts(
|
||||||
messagesResponse: unknown,
|
messagesResponse: unknown,
|
||||||
): Array<{ type: "text"; text: string }> {
|
): Array<{ type: "text"; text: string }> {
|
||||||
const messages = extractMessages(messagesResponse)
|
const messages = extractSessionMessages(messagesResponse)
|
||||||
const lastUserMessage = messages?.filter((message) => message.info?.role === "user").pop()
|
const lastUserMessage = messages?.filter((message) => message.info?.role === "user").pop()
|
||||||
const lastUserParts =
|
const lastUserParts =
|
||||||
lastUserMessage?.parts
|
lastUserMessage?.parts
|
||||||
|
|||||||
Reference in New Issue
Block a user