chore: import upstream snapshot with attribution
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
import { createLogger } from '@sim/logger'
|
||||
import { DeleteFile } from '@/lib/copilot/generated/tool-catalog-v1'
|
||||
import { ensureWorkspaceAccess } from '@/lib/copilot/tools/handlers/access'
|
||||
import {
|
||||
assertServerToolNotAborted,
|
||||
type BaseServerTool,
|
||||
type ServerToolContext,
|
||||
} from '@/lib/copilot/tools/server/base-tool'
|
||||
import {
|
||||
getWorkspaceFile,
|
||||
resolveWorkspaceFileReference,
|
||||
} from '@/lib/uploads/contexts/workspace/workspace-file-manager'
|
||||
import { performDeleteWorkspaceFileItems } from '@/lib/workspace-files/orchestration'
|
||||
|
||||
const logger = createLogger('DeleteFileServerTool')
|
||||
|
||||
interface DeleteFileArgs {
|
||||
paths?: string[]
|
||||
path?: string
|
||||
fileIds?: string[]
|
||||
fileId?: string
|
||||
args?: Record<string, unknown>
|
||||
}
|
||||
|
||||
interface DeleteFileResult {
|
||||
success: boolean
|
||||
message: string
|
||||
}
|
||||
|
||||
export const deleteFileServerTool: BaseServerTool<DeleteFileArgs, DeleteFileResult> = {
|
||||
name: DeleteFile.id,
|
||||
async execute(params: DeleteFileArgs, context?: ServerToolContext): Promise<DeleteFileResult> {
|
||||
if (!context?.userId) {
|
||||
throw new Error('Authentication required')
|
||||
}
|
||||
const workspaceId = context.workspaceId
|
||||
if (!workspaceId) {
|
||||
return { success: false, message: 'Workspace ID is required' }
|
||||
}
|
||||
await ensureWorkspaceAccess(workspaceId, context.userId, 'write')
|
||||
|
||||
const nested = params.args
|
||||
const paths: string[] =
|
||||
params.paths ??
|
||||
(nested?.paths as string[] | undefined) ??
|
||||
[params.path || (nested?.path as string) || ''].filter(Boolean)
|
||||
const legacyFileIds: string[] =
|
||||
params.fileIds ??
|
||||
(nested?.fileIds as string[] | undefined) ??
|
||||
[params.fileId || (nested?.fileId as string) || ''].filter(Boolean)
|
||||
|
||||
if (paths.length === 0 && legacyFileIds.length === 0) {
|
||||
return { success: false, message: 'paths is required' }
|
||||
}
|
||||
|
||||
const deletable: { id: string; name: string }[] = []
|
||||
const failed: string[] = []
|
||||
|
||||
for (const path of paths) {
|
||||
const existingFile = await resolveWorkspaceFileReference(workspaceId, path)
|
||||
if (!existingFile) {
|
||||
failed.push(path)
|
||||
continue
|
||||
}
|
||||
deletable.push({ id: existingFile.id, name: existingFile.name })
|
||||
}
|
||||
|
||||
for (const fileId of legacyFileIds) {
|
||||
const existingFile = await getWorkspaceFile(workspaceId, fileId)
|
||||
if (!existingFile) {
|
||||
failed.push(fileId)
|
||||
continue
|
||||
}
|
||||
deletable.push({ id: fileId, name: existingFile.name })
|
||||
}
|
||||
|
||||
if (deletable.length > 0) {
|
||||
assertServerToolNotAborted(context)
|
||||
const result = await performDeleteWorkspaceFileItems({
|
||||
workspaceId,
|
||||
userId: context.userId,
|
||||
fileIds: deletable.map((file) => file.id),
|
||||
})
|
||||
if (!result.success) {
|
||||
return { success: false, message: result.error || 'Failed to delete files' }
|
||||
}
|
||||
}
|
||||
|
||||
for (const file of deletable) {
|
||||
logger.info('File deleted via delete_file', {
|
||||
fileId: file.id,
|
||||
name: file.name,
|
||||
userId: context.userId,
|
||||
})
|
||||
}
|
||||
|
||||
const parts: string[] = []
|
||||
if (deletable.length > 0)
|
||||
parts.push(`Deleted: ${deletable.map((file) => file.name).join(', ')}`)
|
||||
if (failed.length > 0) parts.push(`Not found: ${failed.join(', ')}`)
|
||||
|
||||
return {
|
||||
success: deletable.length > 0,
|
||||
message: parts.join('. '),
|
||||
}
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user