(
params: WorkspaceFileArgs,
context?: ServerToolContext
)
| 253 | export const workspaceFileServerTool: BaseServerTool<WorkspaceFileArgs, WorkspaceFileResult> = { |
| 254 | name: WorkspaceFile.id, |
| 255 | async execute( |
| 256 | params: WorkspaceFileArgs, |
| 257 | context?: ServerToolContext |
| 258 | ): Promise<WorkspaceFileResult> { |
| 259 | const withMessageId = (message: string) => |
| 260 | context?.messageId ? `${message} [messageId:${context.messageId}]` : message |
| 261 | |
| 262 | if (!context?.userId) { |
| 263 | logger.error('Unauthorized attempt to access workspace files') |
| 264 | throw new Error('Authentication required') |
| 265 | } |
| 266 | |
| 267 | const raw = params as Record<string, unknown> |
| 268 | const nested = raw.args as Record<string, unknown> | undefined |
| 269 | const normalized: WorkspaceFileArgs = |
| 270 | params.operation && params.target |
| 271 | ? params |
| 272 | : nested && typeof nested === 'object' |
| 273 | ? { |
| 274 | operation: (nested.operation ?? raw.operation) as WorkspaceFileOperation, |
| 275 | target: (nested.target ?? raw.target) as WorkspaceFileTarget | undefined, |
| 276 | title: (nested.title ?? raw.title) as string | undefined, |
| 277 | content: (nested.content ?? raw.content) as string | undefined, |
| 278 | contentType: (nested.contentType ?? raw.contentType) as string | undefined, |
| 279 | newName: (nested.newName ?? raw.newName) as string | undefined, |
| 280 | edit: (nested.edit ?? raw.edit) as WorkspaceFileEdit | undefined, |
| 281 | } |
| 282 | : params |
| 283 | const { operation } = normalized |
| 284 | const workspaceId = context.workspaceId |
| 285 | |
| 286 | const resolveExistingTarget = async ( |
| 287 | target: WorkspaceFileTarget | undefined, |
| 288 | operationName: string |
| 289 | ): Promise<{ fileRecord?: WorkspaceFileRecord; vfsPath?: string; error?: string }> => { |
| 290 | if (!target || (target.kind !== 'path' && target.kind !== 'file_id')) { |
| 291 | return { error: `${operationName} requires target.kind=path with target.path` } |
| 292 | } |
| 293 | let fileRecord: WorkspaceFileRecord | null = null |
| 294 | let vfsPath: string | undefined |
| 295 | if (target.kind === 'path') { |
| 296 | const alias = await resolveWorkflowAliasForWorkspace({ |
| 297 | workspaceId: workspaceId!, |
| 298 | path: target.path, |
| 299 | }) |
| 300 | if (!alias && isPlanAliasPath(target.path)) { |
| 301 | return { error: `Unsupported plan alias path or missing workflow: ${target.path}` } |
| 302 | } |
| 303 | if (alias) { |
| 304 | if (alias.kind === 'plans_dir') { |
| 305 | return { error: `Plan alias directory is not a file: ${target.path}` } |
| 306 | } |
| 307 | fileRecord = await resolveWorkspaceFileReference(workspaceId!, alias.backingPath) |
| 308 | if (!fileRecord && alias.kind === 'changelog') { |
| 309 | await ensureWorkflowAliasBacking({ |
| 310 | workspaceId: workspaceId!, |
| 311 | userId: context.userId, |
| 312 | workflowId: alias.workflowId, |
nothing calls this directly
no test coverage detected