mirror of
https://github.com/wu736139669/hapi.git
synced 2026-10-13 20:09:55 +00:00
31 lines
931 B
TypeScript
31 lines
931 B
TypeScript
import type { AttachmentMetadata } from '@/api/types'
|
|
|
|
/**
|
|
* Formats attachments for Claude by converting them to @path references.
|
|
* Claude understands the @path format for file references.
|
|
*/
|
|
export function formatAttachmentsForClaude(attachments: AttachmentMetadata[] | undefined): string {
|
|
if (!attachments || attachments.length === 0) {
|
|
return ''
|
|
}
|
|
return attachments.map(a => `@${a.path}`).join(' ')
|
|
}
|
|
|
|
/**
|
|
* Combines text and formatted attachments into a single prompt string.
|
|
* Attachments are formatted as @path references and prepended to the text.
|
|
*/
|
|
export function formatMessageWithAttachments(
|
|
text: string,
|
|
attachments: AttachmentMetadata[] | undefined
|
|
): string {
|
|
const attachmentText = formatAttachmentsForClaude(attachments)
|
|
if (!attachmentText) {
|
|
return text
|
|
}
|
|
if (!text) {
|
|
return attachmentText
|
|
}
|
|
return `${attachmentText}\n\n${text}`
|
|
}
|