revert utils

This commit is contained in:
Sreeram Sreedhar 2026-04-22 16:24:35 -07:00
parent bb950d4087
commit b13dce0df7

View file

@ -9,6 +9,12 @@ import type {
LanguageModelV3StreamPart,
} from "@ai-sdk/provider"
// Re-export shared types for backward compatibility
export type {
ProfileStructure,
ProfileMarkdownData,
} from "../shared"
// Union types for dual SDK version support (V2 = SDK 5, V3 = SDK 6)
export type LanguageModel = LanguageModelV2 | LanguageModelV3
export type LanguageModelCallOptions =
@ -21,26 +27,6 @@ export type LanguageModelStreamPart =
| LanguageModelV2StreamPart
| LanguageModelV3StreamPart
export interface ProfileStructure {
profile: {
static?: Array<{ memory: string; metadata?: Record<string, unknown> }>
dynamic?: Array<{ memory: string; metadata?: Record<string, unknown> }>
}
searchResults: {
results: Array<{ memory: string; metadata?: Record<string, unknown> }>
}
}
export interface ProfileMarkdownData {
profile: {
static?: string[]
dynamic?: string[]
}
searchResults: {
results: Array<{ memory: string }>
}
}
export type OutputContentItem =
| { type: "text"; text: string }
| { type: "reasoning"; text: string }
@ -58,46 +44,32 @@ export type OutputContentItem =
title: string
}
/**
* Convert profile data to markdown format
* @param data Profile data with string arrays for static and dynamic memories
* @returns Markdown string with profile sections
*/
export function convertProfileToMarkdown(data: ProfileMarkdownData): string {
const sections: string[] = []
// Re-export convertProfileToMarkdown from shared for backward compatibility
export { convertProfileToMarkdown } from "../shared"
if (data.profile.static && data.profile.static.length > 0) {
sections.push("## Static Profile")
sections.push(data.profile.static.map((item) => `- ${item}`).join("\n"))
}
if (data.profile.dynamic && data.profile.dynamic.length > 0) {
sections.push("## Dynamic Profile")
sections.push(data.profile.dynamic.map((item) => `- ${item}`).join("\n"))
}
return sections.join("\n\n")
}
export const getLastUserMessage = (params: LanguageModelCallOptions) => {
export const getLastUserMessage = (
params: LanguageModelCallOptions,
): string | undefined => {
const lastUserMessage = params.prompt
.slice()
.reverse()
.find((prompt: LanguageModelMessage) => prompt.role === "user")
const content = lastUserMessage?.content
if (!content) return undefined
if (!lastUserMessage) {
return undefined
}
// Handle string content (allowed by Vercel AI SDK)
const content = lastUserMessage.content
// Handle string content directly
if (typeof content === "string") {
return content
}
// Handle array content
// biome-ignore lint/suspicious/noExplicitAny: Union type compatibility between V2 and V3
return (content as any[])
// Handle array content - extract text parts
return content
.filter((part) => part.type === "text")
.map((part) => part.text || "")
.map((part) => (part as { type: "text"; text: string }).text)
.join(" ")
}