fix: address Cubic findings for runtime fallback child sessions
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,14 +1,22 @@
|
||||
type SessionMessagesResponse = {
|
||||
data?: Array<{
|
||||
info?: Record<string, unknown>
|
||||
parts?: Array<{ type?: string; text?: string }>
|
||||
}>
|
||||
type MessageItem = {
|
||||
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(
|
||||
messagesResponse: unknown,
|
||||
): Array<{ type: "text"; text: string }> {
|
||||
const messages = (messagesResponse as SessionMessagesResponse).data
|
||||
const messages = extractMessages(messagesResponse)
|
||||
const lastUserMessage = messages?.filter((message) => message.info?.role === "user").pop()
|
||||
const lastUserParts =
|
||||
lastUserMessage?.parts
|
||||
|
||||
Reference in New Issue
Block a user