mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 15:14:10 +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 * as path from 'path'
|
||||||
import { s3Service } from '@/services/s3/s3'
|
import { s3Service } from '@/services/s3/s3'
|
||||||
import { detectSupportedMimeType } from '@/utils/mime'
|
import { detectSupportedMimeType } from '@/utils/mime'
|
||||||
|
import { ulid } from 'ulid'
|
||||||
|
|
||||||
function getMimeType(filePath: string): string {
|
function getMimeType(filePath: string): string {
|
||||||
try {
|
try {
|
||||||
@@ -62,8 +63,9 @@ export function createCreateFileTool(userId: string): AgentTool<typeof createFil
|
|||||||
const fileSize = fs.statSync(absolutePath).size
|
const fileSize = fs.statSync(absolutePath).size
|
||||||
const mimeType = getMimeType(absolutePath)
|
const mimeType = getMimeType(absolutePath)
|
||||||
|
|
||||||
// Pre-upload the file to S3
|
// Generate compliant S3 key matching normal file upload format
|
||||||
const s3Key = await s3Service.uploadFile(absolutePath, mimeType)
|
const s3Key = `file/${ulid()}/raw`
|
||||||
|
await s3Service.uploadFileToKey(absolutePath, s3Key, mimeType)
|
||||||
|
|
||||||
const result = await executeAgentToolWorkflow({
|
const result = await executeAgentToolWorkflow({
|
||||||
toolName: 'create_file',
|
toolName: 'create_file',
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import * as fs from 'fs'
|
|||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import { s3Service } from '@/services/s3/s3'
|
import { s3Service } from '@/services/s3/s3'
|
||||||
import { detectSupportedMimeType } from '@/utils/mime'
|
import { detectSupportedMimeType } from '@/utils/mime'
|
||||||
|
import { ulid } from 'ulid'
|
||||||
|
|
||||||
function getMimeType(filePath: string): string {
|
function getMimeType(filePath: string): string {
|
||||||
try {
|
try {
|
||||||
@@ -63,8 +64,9 @@ export function createCreateVersionTool(userId: string): AgentTool<typeof create
|
|||||||
const fileSize = fs.statSync(absolutePath).size
|
const fileSize = fs.statSync(absolutePath).size
|
||||||
const mimeType = getMimeType(absolutePath)
|
const mimeType = getMimeType(absolutePath)
|
||||||
|
|
||||||
// Pre-upload the file to S3
|
// Generate compliant S3 key matching normal file upload format
|
||||||
const s3Key = await s3Service.uploadFile(absolutePath, mimeType)
|
const s3Key = `file/${ulid()}/raw`
|
||||||
|
await s3Service.uploadFileToKey(absolutePath, s3Key, mimeType)
|
||||||
|
|
||||||
const result = await executeAgentToolWorkflow({
|
const result = await executeAgentToolWorkflow({
|
||||||
toolName: 'create_version',
|
toolName: 'create_version',
|
||||||
|
|||||||
Reference in New Issue
Block a user