mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 07:29:07 +00:00
fix(agent): upload files and versions using compliant S3 keys
This commit is contained in:
@@ -5,6 +5,7 @@ import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import { s3Service } from '@/services/s3/s3'
|
||||
import { detectSupportedMimeType } from '@/utils/mime'
|
||||
import { ulid } from 'ulid'
|
||||
|
||||
function getMimeType(filePath: string): string {
|
||||
try {
|
||||
@@ -62,8 +63,9 @@ export function createCreateFileTool(userId: string): AgentTool<typeof createFil
|
||||
const fileSize = fs.statSync(absolutePath).size
|
||||
const mimeType = getMimeType(absolutePath)
|
||||
|
||||
// Pre-upload the file to S3
|
||||
const s3Key = await s3Service.uploadFile(absolutePath, mimeType)
|
||||
// Generate compliant S3 key matching normal file upload format
|
||||
const s3Key = `file/${ulid()}/raw`
|
||||
await s3Service.uploadFileToKey(absolutePath, s3Key, mimeType)
|
||||
|
||||
const result = await executeAgentToolWorkflow({
|
||||
toolName: 'create_file',
|
||||
|
||||
@@ -5,6 +5,7 @@ import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import { s3Service } from '@/services/s3/s3'
|
||||
import { detectSupportedMimeType } from '@/utils/mime'
|
||||
import { ulid } from 'ulid'
|
||||
|
||||
function getMimeType(filePath: string): string {
|
||||
try {
|
||||
@@ -63,8 +64,9 @@ export function createCreateVersionTool(userId: string): AgentTool<typeof create
|
||||
const fileSize = fs.statSync(absolutePath).size
|
||||
const mimeType = getMimeType(absolutePath)
|
||||
|
||||
// Pre-upload the file to S3
|
||||
const s3Key = await s3Service.uploadFile(absolutePath, mimeType)
|
||||
// Generate compliant S3 key matching normal file upload format
|
||||
const s3Key = `file/${ulid()}/raw`
|
||||
await s3Service.uploadFileToKey(absolutePath, s3Key, mimeType)
|
||||
|
||||
const result = await executeAgentToolWorkflow({
|
||||
toolName: 'create_version',
|
||||
|
||||
Reference in New Issue
Block a user