2026-07-20 10:22:36 +08:00
export function getSimpleMediaType ( proxyType? : string | null ) : 'image' | 'video' | 'pdf' | 'other' {
if ( proxyType === 'image' ) return 'image'
if ( proxyType === 'video' ) return 'video'
if ( proxyType === 'pdf' ) return 'pdf'
2026-06-05 21:25:08 +08:00
return 'other'
}
2026-06-03 16:02:06 +08:00
export class AgentChatPromptBuilder {
private assetId : string
2026-06-05 21:25:08 +08:00
private assetName? : string
private mediaType? : string
2026-07-20 10:22:36 +08:00
private proxyType? : string
2026-06-05 21:25:08 +08:00
private videoDuration? : number
2026-07-19 09:45:14 +08:00
private totalPages? : number
2026-06-05 21:25:08 +08:00
private commentTimestamp? : number
2026-06-03 16:02:06 +08:00
private pathContext? : string
private explicitMention = false
2026-07-07 11:42:40 +08:00
private attachedFiles : string [] = []
private referencedAssets : string [] = []
2026-06-03 16:02:06 +08:00
2026-07-07 21:51:10 +08:00
private isContinuation = false
2026-07-21 10:01:22 +08:00
private hasAssetChanged = false
2026-07-07 21:51:10 +08:00
2026-06-03 16:02:06 +08:00
constructor ( assetId : string ) {
this . assetId = assetId
}
2026-07-07 21:51:10 +08:00
withContinuation ( isContinuation : boolean ) : this {
this . isContinuation = isContinuation
return this
}
2026-07-21 10:01:22 +08:00
withAssetChanged ( hasAssetChanged? : boolean ) : this {
this . hasAssetChanged = !! hasAssetChanged
return this
}
2026-07-07 11:42:40 +08:00
withAttachedFiles ( files? : string []) : this {
if ( files ) {
this . attachedFiles = files
}
return this
}
withReferencedAssets ( assets? : string []) : this {
if ( assets ) {
this . referencedAssets = assets
}
return this
}
2026-06-03 16:02:06 +08:00
withPathContext ( pathContext? : string ) : this {
this . pathContext = pathContext
return this
}
2026-07-19 09:45:14 +08:00
withAssetDetails (
name : string ,
mediaType : string | null ,
duration? : number ,
totalPages? : number ,
2026-07-20 10:22:36 +08:00
proxyType? : string | null ,
2026-07-19 09:45:14 +08:00
) : this {
2026-06-05 21:25:08 +08:00
this . assetName = name
this . mediaType = mediaType || undefined
2026-07-20 10:22:36 +08:00
this . proxyType = proxyType || undefined
2026-06-05 21:25:08 +08:00
this . videoDuration = duration
2026-07-19 09:45:14 +08:00
this . totalPages = totalPages
2026-06-05 21:25:08 +08:00
return this
}
withCommentTimestamp ( second? : number | null ) : this {
if ( second !== undefined && second !== null ) {
this . commentTimestamp = second
}
2026-06-03 16:02:06 +08:00
return this
}
withExplicitMention ( explicitMention? : boolean ) : this {
this . explicitMention = !! explicitMention
return this
}
build () : string {
2026-07-20 11:01:22 +08:00
const effectiveType = this . proxyType
2026-07-20 10:22:36 +08:00
2026-07-07 21:51:10 +08:00
if ( this . isContinuation ) {
let instruction = ''
2026-07-21 10:01:22 +08:00
if ( this . hasAssetChanged ) {
instruction += `[Context: User Navigated to a New Location] \ nNew Location Asset ID: ${ this . assetId } `
if ( this . assetName ) {
instruction += ` \ nFile Name: ${ this . assetName } `
}
if ( effectiveType ) {
const type = getSimpleMediaType ( effectiveType )
instruction += ` \ nFile Type: ${ type } `
if ( type === 'video' && this . videoDuration !== undefined ) {
instruction += ` \ nVideo Length: ${ this . videoDuration . toFixed ( 2 ) } seconds`
} else if ( type === 'pdf' && this . totalPages !== undefined ) {
instruction += ` \ nTotal Pages: ${ this . totalPages } `
}
}
if ( this . pathContext ) {
instruction += ` \ n \ nAsset Path Context: \ n ${ this . pathContext } `
}
}
2026-07-07 21:51:10 +08:00
if ( this . commentTimestamp !== undefined ) {
2026-07-20 10:22:36 +08:00
const type = getSimpleMediaType ( effectiveType )
2026-07-21 10:01:22 +08:00
if ( instruction ) instruction += '\n\n'
2026-07-19 09:45:14 +08:00
if ( type === 'pdf' ) {
instruction += `Comment Page: ${ Math . round ( this . commentTimestamp ) } `
} else {
instruction += `Comment Timestamp: ${ this . commentTimestamp . toFixed ( 2 ) } seconds`
}
2026-07-07 21:51:10 +08:00
}
if ( this . attachedFiles . length > 0 || this . referencedAssets . length > 0 ) {
2026-07-21 10:01:22 +08:00
if ( instruction ) instruction += '\n\n'
instruction += `[Context: New Attached Files & Referenced Assets]`
2026-07-07 21:51:10 +08:00
if ( this . attachedFiles . length > 0 ) {
instruction += ` \ nAttached Files: \ n ${ this . attachedFiles . join ( '\n' ) } `
}
if ( this . referencedAssets . length > 0 ) {
instruction += ` \ nReferenced Workspace Assets: \ n ${ this . referencedAssets . join ( '\n' ) } `
}
}
return instruction . trim ()
}
2026-06-05 21:25:08 +08:00
let instruction = `The user is discussing an asset with ID: ${ this . assetId } .`
if ( this . assetName ) {
instruction += ` \ nFile Name: ${ this . assetName } `
}
2026-07-20 10:22:36 +08:00
if ( effectiveType ) {
const type = getSimpleMediaType ( effectiveType )
2026-06-05 21:25:08 +08:00
instruction += ` \ nFile Type: ${ type } `
if ( type === 'video' && this . videoDuration !== undefined ) {
instruction += ` \ nVideo Length: ${ this . videoDuration . toFixed ( 2 ) } seconds`
2026-07-19 09:45:14 +08:00
} else if ( type === 'pdf' && this . totalPages !== undefined ) {
instruction += ` \ nTotal Pages: ${ this . totalPages } `
2026-06-05 21:25:08 +08:00
}
}
if ( this . commentTimestamp !== undefined ) {
2026-07-20 10:22:36 +08:00
const type = getSimpleMediaType ( effectiveType )
2026-07-19 09:45:14 +08:00
if ( type === 'pdf' ) {
instruction += ` \ nComment Page: ${ Math . round ( this . commentTimestamp ) } `
} else {
instruction += ` \ nComment Timestamp: ${ this . commentTimestamp . toFixed ( 2 ) } seconds`
}
2026-06-05 21:25:08 +08:00
}
2026-06-03 16:02:06 +08:00
if ( this . pathContext ) {
2026-06-05 21:25:08 +08:00
instruction += ` \ n \ nAsset Path Context: \ n ${ this . pathContext } `
2026-06-03 16:02:06 +08:00
}
2026-06-05 21:25:08 +08:00
2026-07-07 11:42:40 +08:00
if ( this . attachedFiles . length > 0 || this . referencedAssets . length > 0 ) {
instruction += ` \ n \ n[Context: Attached Files & Referenced Assets]`
if ( this . attachedFiles . length > 0 ) {
instruction += ` \ nAttached Files: \ n ${ this . attachedFiles . join ( '\n' ) } `
}
if ( this . referencedAssets . length > 0 ) {
instruction += ` \ nReferenced Workspace Assets: \ n ${ this . referencedAssets . join ( '\n' ) } `
}
}
2026-07-20 10:22:36 +08:00
if ( effectiveType ) {
const type = getSimpleMediaType ( effectiveType )
2026-06-05 21:25:08 +08:00
if ( type === 'image' ) {
instruction += ` \ n \ nIf you need to view the image data, call the 'analyze_image' tool. It does not require any parameters.`
} else if ( type === 'video' ) {
instruction += ` \ n \ nIf you need to view visual frames or take screenshots of the video, call the 'screenshot' tool. You must specify the 'start' (seconds), 'end' (seconds), and 'count' (number of screenshots) parameters.`
2026-07-19 09:45:14 +08:00
} else if ( type === 'pdf' ) {
2026-07-19 10:17:21 +08:00
instruction += ` \ n \ nIf you need to view pages of the PDF document, call the 'read_pdf_pages' tool. You must specify the 'start' (page number) and 'end' (page number) parameters. Maximum 20 pages allowed per call.`
2026-06-05 21:25:08 +08:00
}
2026-06-03 16:02:06 +08:00
}
2026-06-05 21:25:08 +08:00
2026-06-03 16:02:06 +08:00
if ( this . explicitMention ) {
2026-06-05 21:25:08 +08:00
instruction += ` \ n \ nThe user explicitly mentioned you in their message. You MUST reply to this message.`
2026-06-03 16:02:06 +08:00
} else {
2026-06-05 21:25:08 +08:00
instruction += ` \ n \ nThe user did not explicitly mention you, but is replying in a thread where you are the participant. Let's decide if you should reply or not. If the user is not directly addressing you or doesn't need a response from you, you may choose to not reply. To choose not to reply, respond with exactly and only the text: __NO_REPLY__.`
2026-06-03 16:02:06 +08:00
}
2026-06-05 21:25:08 +08:00
2026-06-03 16:02:06 +08:00
return instruction
}
}