d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
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
93 lines
2.7 KiB
TypeScript
93 lines
2.7 KiB
TypeScript
import { createLogger } from '@sim/logger'
|
|
import { RenameFile } 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 { performRenameWorkspaceFile } from '@/lib/workspace-files/orchestration'
|
|
import { validateFlatWorkspaceFileName } from './workspace-file'
|
|
|
|
const logger = createLogger('RenameFileServerTool')
|
|
|
|
interface RenameFileArgs {
|
|
path?: string
|
|
fileId?: string
|
|
newName: string
|
|
args?: Record<string, unknown>
|
|
}
|
|
|
|
interface RenameFileResult {
|
|
success: boolean
|
|
message: string
|
|
data?: {
|
|
id: string
|
|
name: string
|
|
}
|
|
}
|
|
|
|
export const renameFileServerTool: BaseServerTool<RenameFileArgs, RenameFileResult> = {
|
|
name: RenameFile.id,
|
|
async execute(params: RenameFileArgs, context?: ServerToolContext): Promise<RenameFileResult> {
|
|
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 path = params.path || (nested?.path as string) || ''
|
|
const legacyFileId = params.fileId || (nested?.fileId as string) || ''
|
|
const newName = params.newName || (nested?.newName as string) || ''
|
|
|
|
const targetRef = path || legacyFileId
|
|
if (!targetRef) return { success: false, message: 'path is required' }
|
|
|
|
const nameError = validateFlatWorkspaceFileName(newName)
|
|
if (nameError) return { success: false, message: nameError }
|
|
|
|
const existingFile = path
|
|
? await resolveWorkspaceFileReference(workspaceId, path)
|
|
: await getWorkspaceFile(workspaceId, legacyFileId)
|
|
if (!existingFile) {
|
|
return { success: false, message: `File not found: ${targetRef}` }
|
|
}
|
|
const fileId = existingFile.id
|
|
|
|
assertServerToolNotAborted(context)
|
|
const result = await performRenameWorkspaceFile({
|
|
workspaceId,
|
|
fileId,
|
|
name: newName,
|
|
userId: context.userId,
|
|
})
|
|
if (!result.success) {
|
|
return { success: false, message: result.error || 'Failed to rename file' }
|
|
}
|
|
|
|
logger.info('File renamed via rename_file', {
|
|
fileId,
|
|
oldName: existingFile.name,
|
|
newName,
|
|
userId: context.userId,
|
|
})
|
|
|
|
return {
|
|
success: true,
|
|
message: `File renamed from "${existingFile.name}" to "${newName}"`,
|
|
data: {
|
|
id: fileId,
|
|
name: newName,
|
|
},
|
|
}
|
|
},
|
|
}
|