mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-29 12:24:39 +00:00
fix(agent): resolve S3 MIME type detection and prompt parameter in image analysis
This commit is contained in:
@@ -351,49 +351,49 @@ describe('ChatService', () => {
|
||||
},
|
||||
})
|
||||
|
||||
// 2. Manually insert a test entry representing a custom context message
|
||||
await prisma.agentSessionEntry.create({
|
||||
// 2. Manually insert a test entry representing a custom context message
|
||||
await prisma.agentSessionEntry.create({
|
||||
data: {
|
||||
id: 'test-entry-2-context',
|
||||
sessionId,
|
||||
type: 'custom_message',
|
||||
parentId: 'test-entry-1-user',
|
||||
data: {
|
||||
id: 'test-entry-2-context',
|
||||
sessionId,
|
||||
type: 'custom_message',
|
||||
parentId: 'test-entry-1-user',
|
||||
data: {
|
||||
customType: 'context',
|
||||
content: 'some context',
|
||||
display: 'chat',
|
||||
} as PrismaJson.PiSessionEntryData,
|
||||
},
|
||||
})
|
||||
customType: 'context',
|
||||
content: 'some context',
|
||||
display: 'chat',
|
||||
} as PrismaJson.PiSessionEntryData,
|
||||
},
|
||||
})
|
||||
|
||||
// 3. Manually insert a test entry representing a custom thinking level change
|
||||
await prisma.agentSessionEntry.create({
|
||||
// 3. Manually insert a test entry representing a custom thinking level change
|
||||
await prisma.agentSessionEntry.create({
|
||||
data: {
|
||||
id: 'test-entry-3-thinking',
|
||||
sessionId,
|
||||
type: 'thinking_level_change',
|
||||
parentId: 'test-entry-2-context',
|
||||
data: {
|
||||
id: 'test-entry-3-thinking',
|
||||
sessionId,
|
||||
type: 'thinking_level_change',
|
||||
parentId: 'test-entry-2-context',
|
||||
data: {
|
||||
thinkingLevel: 'deep',
|
||||
} as PrismaJson.PiSessionEntryData,
|
||||
},
|
||||
})
|
||||
thinkingLevel: 'deep',
|
||||
} as PrismaJson.PiSessionEntryData,
|
||||
},
|
||||
})
|
||||
|
||||
// 4. Manually insert a test entry representing custom context_display_info entry
|
||||
await prisma.agentSessionEntry.create({
|
||||
// 4. Manually insert a test entry representing custom context_display_info entry
|
||||
await prisma.agentSessionEntry.create({
|
||||
data: {
|
||||
id: 'test-entry-4-display',
|
||||
sessionId,
|
||||
type: 'custom',
|
||||
parentId: 'test-entry-3-thinking',
|
||||
data: {
|
||||
id: 'test-entry-4-display',
|
||||
sessionId,
|
||||
type: 'custom',
|
||||
parentId: 'test-entry-3-thinking',
|
||||
customType: 'context_display_info',
|
||||
data: {
|
||||
customType: 'context_display_info',
|
||||
data: {
|
||||
assets: [{ id: 'a1', name: 'File A', type: 'file' }],
|
||||
},
|
||||
} as PrismaJson.PiSessionEntryData,
|
||||
},
|
||||
})
|
||||
assets: [{ id: 'a1', name: 'File A', type: 'file' }],
|
||||
},
|
||||
} as PrismaJson.PiSessionEntryData,
|
||||
},
|
||||
})
|
||||
|
||||
await prisma.agentSession.update({
|
||||
where: { id: sessionId },
|
||||
|
||||
@@ -5,6 +5,7 @@ import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import { ulid } from 'ulid'
|
||||
import { LruTtlCache } from '../cache/lru-ttl-cache'
|
||||
import { detectSupportedMimeType } from '../utils/mime'
|
||||
|
||||
export function signLocalUrl(bucket: string, key: string): string {
|
||||
const secret = process.env.BETTER_AUTH_SECRET || 'shumai-local-storage-secret'
|
||||
@@ -99,9 +100,22 @@ export class S3StorageService implements S3Service {
|
||||
async getObject(bucket: string, key: string): Promise<S3Object> {
|
||||
const file = this.client.file(key, { bucket })
|
||||
const arrayBuffer = await file.arrayBuffer()
|
||||
const buffer = Buffer.from(arrayBuffer)
|
||||
let contentType = file.type
|
||||
if (!contentType || contentType === 'application/octet-stream') {
|
||||
const detected = detectSupportedMimeType(buffer)
|
||||
if (detected) {
|
||||
contentType = detected
|
||||
} else {
|
||||
const fileType = Bun.file(key).type
|
||||
if (fileType && fileType !== 'application/octet-stream') {
|
||||
contentType = fileType
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
buffer: Buffer.from(arrayBuffer),
|
||||
contentType: file.type || 'application/octet-stream',
|
||||
buffer,
|
||||
contentType: contentType || 'application/octet-stream',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user