vercel / ai

Build AI-powered applications with React, Svelte, Vue, and Solid
https://sdk.vercel.ai/docs
Other
9.91k stars 1.47k forks source link

Extend Attachment Type to support custom attributes #3148

Closed aneequrrehman closed 1 month ago

aneequrrehman commented 1 month ago

Feature Description

Related to Generic Messages #1180.

Currently, Attachments are not easily extensible. For instance, images may require additional fields such as height and width, or attachments may need a file_pointer depending upon the storage mechanism. And so at the moment, it requires custom projections and types to tackle this.

Additional context

While I understand that handling storage details is not the responsibility of the AI SDK itself, introducing such a field as Record<string, unknown> or some similar mechanism to allow the Attachment type extension would simplify integration for consumers.

aneequrrehman commented 1 month ago

I noticed that FilePart and ImagePart are already interfaces, and even if you extend those, the conversational APIs seem to work.

Example:

declare module 'ai' {
  interface ImagePart {
    filePointer: string
    width: number
    height: number
}