( app: FsRouteHost, ix: IInstantiationService, )
| 100 | const FS_TAIL_PREFIX = 'fs:'; |
| 101 | |
| 102 | export function registerFsRoutes( |
| 103 | app: FsRouteHost, |
| 104 | ix: IInstantiationService, |
| 105 | ): void { |
| 106 | |
| 107 | const fsActionRoute = defineRoute( |
| 108 | { |
| 109 | method: 'POST', |
| 110 | path: '/sessions/{session_id}/{tail}', |
| 111 | params: sessionIdAndTailParamSchema, |
| 112 | errors: { |
| 113 | [ErrorCode.VALIDATION_FAILED]: {}, |
| 114 | [ErrorCode.SESSION_NOT_FOUND]: {}, |
| 115 | [ErrorCode.FS_PATH_NOT_FOUND]: {}, |
| 116 | [ErrorCode.FS_IS_DIRECTORY]: {}, |
| 117 | [ErrorCode.FS_IS_BINARY]: {}, |
| 118 | [ErrorCode.FS_TOO_LARGE]: {}, |
| 119 | [ErrorCode.FS_TOO_MANY_RESULTS]: {}, |
| 120 | [ErrorCode.FS_PATH_ESCAPES_SESSION]: {}, |
| 121 | [ErrorCode.FS_GREP_TIMEOUT]: {}, |
| 122 | [ErrorCode.FS_GIT_UNAVAILABLE]: {}, |
| 123 | [ErrorCode.FS_ALREADY_EXISTS]: {}, |
| 124 | }, |
| 125 | description: |
| 126 | 'Filesystem action dispatcher. Supported actions: list, read, list_many, stat, stat_many, mkdir, search, grep, git_status, diff, open, reveal.', |
| 127 | tags: ['fs'], |
| 128 | operationId: 'fsAction', |
| 129 | }, |
| 130 | async (req, reply) => { |
| 131 | const { session_id, tail } = req.params; |
| 132 | |
| 133 | if (!tail.startsWith(FS_TAIL_PREFIX)) { |
| 134 | |
| 135 | reply.send( |
| 136 | errEnvelope( |
| 137 | ErrorCode.VALIDATION_FAILED, |
| 138 | `unsupported action: ${tail}`, |
| 139 | req.id, |
| 140 | ), |
| 141 | ); |
| 142 | return; |
| 143 | } |
| 144 | |
| 145 | const action = tail.slice(FS_TAIL_PREFIX.length); |
| 146 | if (!(FS_ACTIONS as readonly string[]).includes(action)) { |
| 147 | reply.send( |
| 148 | errEnvelope( |
| 149 | ErrorCode.VALIDATION_FAILED, |
| 150 | `unsupported action: ${tail}`, |
| 151 | req.id, |
| 152 | ), |
| 153 | ); |
| 154 | return; |
| 155 | } |
| 156 | const fsAction = action as FsAction; |
| 157 | |
| 158 | try { |
| 159 | switch (fsAction) { |
no test coverage detected