feat: file attachment input

This commit is contained in:
Acbox
2026-02-06 16:09:11 +08:00
parent 5a35ef34ac
commit fe71e7d36d
5 changed files with 28 additions and 8 deletions
+3 -2
View File
@@ -37,14 +37,15 @@ export const createAgent = ({
})
const generateUserPrompt = (input: AgentInput) => {
const images = input.attachments.filter(attachment => attachment.type === 'image')
const files = input.attachments.filter(attachment => attachment.type === 'file')
const text = user(input.query, {
contactId: identity.contactId,
contactName: identity.contactName,
platform: currentPlatform,
date: new Date(),
attachments: files,
})
const images = input.attachments.filter(attachment => attachment.type === 'image')
// const files = input.attachments.filter(attachment => attachment.type === 'file')
const userMessage: UserModelMessage = {
role: 'user',
content: [
+15 -1
View File
@@ -40,4 +40,18 @@ export const ScheduleModel = z.object({
pattern: z.string().min(1, 'Schedule pattern is required'),
maxCalls: z.number().nullable().optional(),
command: z.string().min(1, 'Schedule command is required'),
})
})
export const ImageAttachmentModel = z.object({
type: z.literal('image'),
base64: z.string().min(1, 'Image base64 is required'),
metadata: z.record(z.string(), z.any()).optional(),
})
export const FileAttachmentModel = z.object({
type: z.literal('file'),
path: z.string().min(1, 'File path is required'),
metadata: z.record(z.string(), z.any()).optional(),
})
export const AttachmentModel = z.union([ImageAttachmentModel, FileAttachmentModel])
+4 -3
View File
@@ -4,7 +4,7 @@ import { createAgent } from '../agent'
import { createAuthFetcher } from '../index'
import { ModelConfig } from '../types'
import { bearerMiddleware } from '../middlewares/bearer'
import { AllowedActionModel, IdentityContextModel, ModelConfigModel } from '../models'
import { AllowedActionModel, AttachmentModel, IdentityContextModel, ModelConfigModel } from '../models'
import { allActions } from '../types'
const AgentModel = z.object({
@@ -17,6 +17,7 @@ const AgentModel = z.object({
skills: z.array(z.string()),
query: z.string(),
identity: IdentityContextModel,
attachments: z.array(AttachmentModel),
})
export const chatModule = new Elysia({ prefix: '/chat' })
@@ -35,7 +36,7 @@ export const chatModule = new Elysia({ prefix: '/chat' })
query: body.query,
messages: body.messages,
skills: body.skills,
attachments: [],
attachments: body.attachments,
})
}, {
body: AgentModel,
@@ -54,7 +55,7 @@ export const chatModule = new Elysia({ prefix: '/chat' })
query: body.query,
messages: body.messages,
skills: body.skills,
attachments: [],
attachments: body.attachments,
})) {
yield sse(JSON.stringify(action))
}
+5 -1
View File
@@ -1,19 +1,23 @@
import { ContainerFileAttachment } from '../types'
export interface UserParams {
contactId: string
contactName: string
platform: string
date: Date
attachments: ContainerFileAttachment[]
}
export const user = (
query: string,
{ contactId, contactName, platform, date }: UserParams
{ contactId, contactName, platform, date, attachments }: UserParams
) => {
const headers = {
'contact-id': contactId,
'contact-name': contactName,
'platform': platform,
'time': date.toISOString(),
'attachments': attachments.map(attachment => attachment.path),
}
return `
---
+1 -1
View File
@@ -1,6 +1,6 @@
export interface BaseAgentAttachment {
type: string
metadata: Record<string, unknown>
metadata?: Record<string, unknown>
}
export interface ImageAttachment extends BaseAgentAttachment {