mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-27 19:34:38 +00:00
feat(agent): add agent avatar selection and S3 uploading
This commit is contained in:
@@ -190,6 +190,45 @@ describe('AgentService', () => {
|
||||
expect(reUpdated.skills?.length).toBe(1)
|
||||
})
|
||||
|
||||
test('Create Agent with presigned URL extracts S3 key', async () => {
|
||||
const db = prisma
|
||||
const svc = new AgentService()
|
||||
const { team, provider, model } = await setupTestData(db)
|
||||
|
||||
const avatarPresigned = 'https://shumai.s3.amazonaws.com/files/01JK23456789ABCDEF01234567?AWSAccessKeyId=foo'
|
||||
const agent = await svc.createAgent({
|
||||
teamId: team.id,
|
||||
name: 'Agent with URL',
|
||||
type: 'chat',
|
||||
enabled: true,
|
||||
avatar: avatarPresigned,
|
||||
providerId: provider.id,
|
||||
modelId: model.id,
|
||||
})
|
||||
|
||||
expect(agent?.id).toBeDefined()
|
||||
expect(agent?.user.image).toBe('files/01JK23456789ABCDEF01234567')
|
||||
})
|
||||
|
||||
test('Update Agent with presigned URL extracts S3 key', async () => {
|
||||
const db = prisma
|
||||
const svc = new AgentService()
|
||||
const { agent } = await setupTestData(db)
|
||||
|
||||
const avatarPresigned = 'https://shumai.s3.amazonaws.com/files/01JK23456789ABCDEF01234567?AWSAccessKeyId=foo'
|
||||
const updated = await svc.updateAgent({
|
||||
agentId: agent.id,
|
||||
name: 'Updated with URL',
|
||||
type: 'chat',
|
||||
enabled: true,
|
||||
avatar: avatarPresigned,
|
||||
providerId: agent.providerId!,
|
||||
modelId: agent.modelId!,
|
||||
})
|
||||
|
||||
expect(updated.user.image).toBe('files/01JK23456789ABCDEF01234567')
|
||||
})
|
||||
|
||||
test('Delete Agent', async () => {
|
||||
const db = prisma
|
||||
const svc = new AgentService()
|
||||
|
||||
@@ -11,6 +11,12 @@ import AdmZip from 'adm-zip'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
|
||||
function extractS3Key(urlOrKey?: string | null): string | null | undefined {
|
||||
if (!urlOrKey) return urlOrKey
|
||||
const match = urlOrKey.match(/files\/[A-Z0-9]{26}/)
|
||||
return match ? match[0] : urlOrKey
|
||||
}
|
||||
|
||||
export class AgentService {
|
||||
constructor(private readonly prismaClient: typeof prisma = prisma) {}
|
||||
|
||||
@@ -153,7 +159,7 @@ export class AgentService {
|
||||
name,
|
||||
email: `agent-${Date.now()}-${Math.random().toString(36).substring(7)}@shumai.ai`,
|
||||
type: 'agent',
|
||||
image: avatar,
|
||||
image: extractS3Key(avatar),
|
||||
},
|
||||
})
|
||||
|
||||
@@ -252,7 +258,7 @@ export class AgentService {
|
||||
where: { id: agentId },
|
||||
data: {
|
||||
name,
|
||||
image: avatar,
|
||||
image: extractS3Key(avatar),
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user