diff --git a/packages/tools/src/vercel/util.ts b/packages/tools/src/vercel/util.ts index 6fc8df03..49ab30c5 100644 --- a/packages/tools/src/vercel/util.ts +++ b/packages/tools/src/vercel/util.ts @@ -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 }> - dynamic?: Array<{ memory: string; metadata?: Record }> - } - searchResults: { - results: Array<{ memory: string; metadata?: Record }> - } -} - -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(" ") }