client.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. """
  2. This is the main file for the runtime client.
  3. It is responsible for executing actions received from OpenDevin backend and producing observations.
  4. NOTE: this will be executed inside the docker sandbox.
  5. """
  6. import argparse
  7. import asyncio
  8. import os
  9. import re
  10. import shutil
  11. import subprocess
  12. from contextlib import asynccontextmanager
  13. from pathlib import Path
  14. import pexpect
  15. from fastapi import FastAPI, HTTPException, Request, UploadFile
  16. from fastapi.responses import JSONResponse
  17. from pathspec import PathSpec
  18. from pathspec.patterns import GitWildMatchPattern
  19. from pydantic import BaseModel
  20. from uvicorn import run
  21. from opendevin.core.logger import opendevin_logger as logger
  22. from opendevin.events.action import (
  23. Action,
  24. BrowseInteractiveAction,
  25. BrowseURLAction,
  26. CmdRunAction,
  27. FileReadAction,
  28. FileWriteAction,
  29. IPythonRunCellAction,
  30. )
  31. from opendevin.events.observation import (
  32. CmdOutputObservation,
  33. ErrorObservation,
  34. FileReadObservation,
  35. FileWriteObservation,
  36. IPythonRunCellObservation,
  37. Observation,
  38. )
  39. from opendevin.events.serialization import event_from_dict, event_to_dict
  40. from opendevin.runtime.browser import browse
  41. from opendevin.runtime.browser.browser_env import BrowserEnv
  42. from opendevin.runtime.plugins import (
  43. ALL_PLUGINS,
  44. JupyterPlugin,
  45. Plugin,
  46. )
  47. from opendevin.runtime.utils import split_bash_commands
  48. from opendevin.runtime.utils.files import insert_lines, read_lines
  49. class ActionRequest(BaseModel):
  50. action: dict
  51. ROOT_GID = 0
  52. INIT_COMMANDS = [
  53. 'git config --global user.name "opendevin"',
  54. 'git config --global user.email "opendevin@all-hands.dev"',
  55. "alias git='git --no-pager'",
  56. ]
  57. class RuntimeClient:
  58. """RuntimeClient is running inside docker sandbox.
  59. It is responsible for executing actions received from OpenDevin backend and producing observations.
  60. """
  61. def __init__(
  62. self,
  63. plugins_to_load: list[Plugin],
  64. work_dir: str,
  65. username: str,
  66. user_id: int,
  67. browsergym_eval_env: str | None,
  68. ) -> None:
  69. self.plugins_to_load = plugins_to_load
  70. self.username = username
  71. self.user_id = user_id
  72. self.pwd = work_dir # current PWD
  73. self._initial_pwd = work_dir
  74. self._init_user(self.username, self.user_id)
  75. self._init_bash_shell(self.pwd, self.username)
  76. self.lock = asyncio.Lock()
  77. self.plugins: dict[str, Plugin] = {}
  78. self.browser = BrowserEnv(browsergym_eval_env)
  79. self._initial_pwd = work_dir
  80. @property
  81. def initial_pwd(self):
  82. return self._initial_pwd
  83. async def ainit(self):
  84. for plugin in self.plugins_to_load:
  85. await plugin.initialize(self.username)
  86. self.plugins[plugin.name] = plugin
  87. logger.info(f'Initializing plugin: {plugin.name}')
  88. if isinstance(plugin, JupyterPlugin):
  89. await self.run_ipython(
  90. IPythonRunCellAction(code=f'import os; os.chdir("{self.pwd}")')
  91. )
  92. # This is a temporary workaround
  93. # TODO: refactor AgentSkills to be part of JupyterPlugin
  94. # AFTER ServerRuntime is deprecated
  95. if 'agent_skills' in self.plugins and 'jupyter' in self.plugins:
  96. obs = await self.run_ipython(
  97. IPythonRunCellAction(code='from agentskills import *')
  98. )
  99. logger.info(f'AgentSkills initialized: {obs}')
  100. await self._init_bash_commands()
  101. def _init_user(self, username: str, user_id: int) -> None:
  102. """Create user if not exists."""
  103. # Skip root since it is already created
  104. if username == 'root':
  105. return
  106. # Add sudoer
  107. sudoer_line = r"echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers"
  108. output = subprocess.run(sudoer_line, shell=True, capture_output=True)
  109. if output.returncode != 0:
  110. raise RuntimeError(f'Failed to add sudoer: {output.stderr.decode()}')
  111. logger.debug(f'Added sudoer successfully. Output: [{output.stdout.decode()}]')
  112. # Add user and change ownership of the initial working directory if it doesn't exist
  113. command = (
  114. f'useradd -rm -d /home/{username} -s /bin/bash '
  115. f'-g root -G sudo -u {user_id} {username}'
  116. )
  117. if not os.path.exists(self.initial_pwd):
  118. command += f' && mkdir -p {self.initial_pwd}'
  119. command += f' && chown -R {username}:root {self.initial_pwd}'
  120. command += f' && chmod g+s {self.initial_pwd}'
  121. output = subprocess.run(
  122. command,
  123. shell=True,
  124. capture_output=True,
  125. )
  126. if output.returncode != 0:
  127. raise RuntimeError(
  128. f'Failed to create user {username}: {output.stderr.decode()}'
  129. )
  130. logger.debug(
  131. f'Added user {username} successfully. Output: [{output.stdout.decode()}]'
  132. )
  133. def _init_bash_shell(self, work_dir: str, username: str) -> None:
  134. self.shell = pexpect.spawn(
  135. f'su - {username}',
  136. encoding='utf-8',
  137. echo=False,
  138. )
  139. self.__bash_PS1 = r'[PEXPECT_BEGIN] \u@\h:\w [PEXPECT_END]'
  140. # This should NOT match "PS1=\u@\h:\w [PEXPECT]$" when `env` is executed
  141. self.__bash_expect_regex = (
  142. r'\[PEXPECT_BEGIN\] ([a-z0-9_-]*)@([a-zA-Z0-9.-]*):(.+) \[PEXPECT_END\]'
  143. )
  144. self.shell.sendline(f'export PS1="{self.__bash_PS1}"; export PS2=""')
  145. self.shell.expect(self.__bash_expect_regex)
  146. self.shell.sendline(f'cd {work_dir}')
  147. self.shell.expect(self.__bash_expect_regex)
  148. logger.debug(
  149. f'Bash initialized. Working directory: {work_dir}. Output: {self.shell.before}'
  150. )
  151. async def _init_bash_commands(self):
  152. logger.info(f'Initializing by running {len(INIT_COMMANDS)} bash commands...')
  153. for command in INIT_COMMANDS:
  154. action = CmdRunAction(command=command)
  155. action.timeout = 300
  156. logger.debug(f'Executing init command: {command}')
  157. obs: CmdOutputObservation = await self.run(action)
  158. logger.debug(
  159. f'Init command outputs (exit code: {obs.exit_code}): {obs.content}'
  160. )
  161. assert obs.exit_code == 0
  162. logger.info('Bash init commands completed')
  163. def _get_bash_prompt_and_update_pwd(self):
  164. ps1 = self.shell.after
  165. # begin at the last occurence of '[PEXPECT_BEGIN]'.
  166. # In multi-line bash commands, the prompt will be repeated
  167. # and the matched regex captures all of them
  168. # - we only want the last one (newest prompt)
  169. _begin_pos = ps1.rfind('[PEXPECT_BEGIN]')
  170. if _begin_pos != -1:
  171. ps1 = ps1[_begin_pos:]
  172. # parse the ps1 to get username, hostname, and working directory
  173. matched = re.match(self.__bash_expect_regex, ps1)
  174. assert (
  175. matched is not None
  176. ), f'Failed to parse bash prompt: {ps1}. This should not happen.'
  177. username, hostname, working_dir = matched.groups()
  178. self.pwd = os.path.expanduser(working_dir)
  179. # re-assemble the prompt
  180. prompt = f'{username}@{hostname}:{working_dir} '
  181. if username == 'root':
  182. prompt += '#'
  183. else:
  184. prompt += '$'
  185. return prompt + ' '
  186. def _execute_bash(
  187. self,
  188. command: str,
  189. timeout: int | None,
  190. keep_prompt: bool = True,
  191. ) -> tuple[str, int]:
  192. logger.debug(f'Executing command: {command}')
  193. try:
  194. self.shell.sendline(command)
  195. self.shell.expect(self.__bash_expect_regex, timeout=timeout)
  196. output = self.shell.before
  197. # Get exit code
  198. self.shell.sendline('echo $?')
  199. logger.debug(f'Executing command for exit code: {command}')
  200. self.shell.expect(self.__bash_expect_regex, timeout=timeout)
  201. _exit_code_output = self.shell.before
  202. logger.debug(f'Exit code Output: {_exit_code_output}')
  203. exit_code = int(_exit_code_output.strip().split()[0])
  204. except pexpect.TIMEOUT as e:
  205. self.shell.sendintr() # send SIGINT to the shell
  206. self.shell.expect(self.__bash_expect_regex, timeout=timeout)
  207. output = self.shell.before
  208. output += (
  209. '\r\n\r\n'
  210. + f'[Command timed out after {timeout} seconds. SIGINT was sent to interrupt it.]'
  211. )
  212. exit_code = 130 # SIGINT
  213. logger.error(f'Failed to execute command: {command}. Error: {e}')
  214. finally:
  215. bash_prompt = self._get_bash_prompt_and_update_pwd()
  216. if keep_prompt:
  217. output += '\r\n' + bash_prompt
  218. logger.debug(f'Command output: {output}')
  219. return output, exit_code
  220. async def run_action(self, action) -> Observation:
  221. action_type = action.action
  222. observation = await getattr(self, action_type)(action)
  223. return observation
  224. async def run(self, action: CmdRunAction) -> CmdOutputObservation:
  225. try:
  226. assert (
  227. action.timeout is not None
  228. ), f'Timeout argument is required for CmdRunAction: {action}'
  229. commands = split_bash_commands(action.command)
  230. all_output = ''
  231. for command in commands:
  232. output, exit_code = self._execute_bash(
  233. command,
  234. timeout=action.timeout,
  235. keep_prompt=action.keep_prompt,
  236. )
  237. if all_output:
  238. # previous output already exists with prompt "user@hostname:working_dir #""
  239. # we need to add the command to the previous output,
  240. # so model knows the following is the output of another action)
  241. all_output = all_output.rstrip() + ' ' + command + '\r\n'
  242. all_output += str(output) + '\r\n'
  243. if exit_code != 0:
  244. break
  245. return CmdOutputObservation(
  246. command_id=-1,
  247. content=all_output.rstrip('\r\n'),
  248. command=action.command,
  249. exit_code=exit_code,
  250. )
  251. except UnicodeDecodeError:
  252. raise RuntimeError('Command output could not be decoded as utf-8')
  253. async def run_ipython(self, action: IPythonRunCellAction) -> Observation:
  254. if 'jupyter' in self.plugins:
  255. _jupyter_plugin: JupyterPlugin = self.plugins['jupyter'] # type: ignore
  256. # This is used to make AgentSkills in Jupyter aware of the
  257. # current working directory in Bash
  258. if self.pwd != getattr(self, '_jupyter_pwd', None):
  259. logger.debug(
  260. f"{self.pwd} != {getattr(self, '_jupyter_pwd', None)} -> reset Jupyter PWD"
  261. )
  262. reset_jupyter_pwd_code = f'import os; os.chdir("{self.pwd}")'
  263. _aux_action = IPythonRunCellAction(code=reset_jupyter_pwd_code)
  264. _reset_obs = await _jupyter_plugin.run(_aux_action)
  265. logger.debug(
  266. f'Changed working directory in IPython to: {self.pwd}. Output: {_reset_obs}'
  267. )
  268. self._jupyter_pwd = self.pwd
  269. obs: IPythonRunCellObservation = await _jupyter_plugin.run(action)
  270. obs.content = obs.content.rstrip()
  271. obs.content += f'\n[Jupyter current working directory: {self.pwd}]'
  272. return obs
  273. else:
  274. raise RuntimeError(
  275. 'JupyterRequirement not found. Unable to run IPython action.'
  276. )
  277. def _get_working_directory(self):
  278. # NOTE: this is part of initialization, so we hard code the timeout
  279. result, exit_code = self._execute_bash('pwd', timeout=60, keep_prompt=False)
  280. if exit_code != 0:
  281. raise RuntimeError('Failed to get working directory')
  282. return result.strip()
  283. def _resolve_path(self, path: str, working_dir: str) -> str:
  284. filepath = Path(path)
  285. if not filepath.is_absolute():
  286. return str(Path(working_dir) / filepath)
  287. return str(filepath)
  288. async def read(self, action: FileReadAction) -> Observation:
  289. # NOTE: the client code is running inside the sandbox,
  290. # so there's no need to check permission
  291. working_dir = self._get_working_directory()
  292. filepath = self._resolve_path(action.path, working_dir)
  293. try:
  294. with open(filepath, 'r', encoding='utf-8') as file:
  295. lines = read_lines(file.readlines(), action.start, action.end)
  296. except FileNotFoundError:
  297. return ErrorObservation(
  298. f'File not found: {filepath}. Your current working directory is {working_dir}.'
  299. )
  300. except UnicodeDecodeError:
  301. return ErrorObservation(f'File could not be decoded as utf-8: {filepath}.')
  302. except IsADirectoryError:
  303. return ErrorObservation(
  304. f'Path is a directory: {filepath}. You can only read files'
  305. )
  306. code_view = ''.join(lines)
  307. return FileReadObservation(path=filepath, content=code_view)
  308. async def write(self, action: FileWriteAction) -> Observation:
  309. working_dir = self._get_working_directory()
  310. filepath = self._resolve_path(action.path, working_dir)
  311. insert = action.content.split('\n')
  312. try:
  313. if not os.path.exists(os.path.dirname(filepath)):
  314. os.makedirs(os.path.dirname(filepath))
  315. file_exists = os.path.exists(filepath)
  316. if file_exists:
  317. file_stat = os.stat(filepath)
  318. else:
  319. file_stat = None
  320. mode = 'w' if not file_exists else 'r+'
  321. try:
  322. with open(filepath, mode, encoding='utf-8') as file:
  323. if mode != 'w':
  324. all_lines = file.readlines()
  325. new_file = insert_lines(
  326. insert, all_lines, action.start, action.end
  327. )
  328. else:
  329. new_file = [i + '\n' for i in insert]
  330. file.seek(0)
  331. file.writelines(new_file)
  332. file.truncate()
  333. # Handle file permissions
  334. if file_exists:
  335. assert file_stat is not None
  336. # restore the original file permissions if the file already exists
  337. os.chmod(filepath, file_stat.st_mode)
  338. os.chown(filepath, file_stat.st_uid, file_stat.st_gid)
  339. else:
  340. # set the new file permissions if the file is new
  341. os.chmod(filepath, 0o644)
  342. os.chown(filepath, self.user_id, self.user_id)
  343. except FileNotFoundError:
  344. return ErrorObservation(f'File not found: {filepath}')
  345. except IsADirectoryError:
  346. return ErrorObservation(
  347. f'Path is a directory: {filepath}. You can only write to files'
  348. )
  349. except UnicodeDecodeError:
  350. return ErrorObservation(
  351. f'File could not be decoded as utf-8: {filepath}'
  352. )
  353. except PermissionError:
  354. return ErrorObservation(f'Malformed paths not permitted: {filepath}')
  355. return FileWriteObservation(content='', path=filepath)
  356. async def browse(self, action: BrowseURLAction) -> Observation:
  357. return await browse(action, self.browser)
  358. async def browse_interactive(self, action: BrowseInteractiveAction) -> Observation:
  359. return await browse(action, self.browser)
  360. def close(self):
  361. self.shell.close()
  362. self.browser.close()
  363. if __name__ == '__main__':
  364. parser = argparse.ArgumentParser()
  365. parser.add_argument('port', type=int, help='Port to listen on')
  366. parser.add_argument('--working-dir', type=str, help='Working directory')
  367. parser.add_argument('--plugins', type=str, help='Plugins to initialize', nargs='+')
  368. parser.add_argument(
  369. '--username', type=str, help='User to run as', default='opendevin'
  370. )
  371. parser.add_argument('--user-id', type=int, help='User ID to run as', default=1000)
  372. parser.add_argument(
  373. '--browsergym-eval-env',
  374. type=str,
  375. help='BrowserGym environment used for browser evaluation',
  376. default=None,
  377. )
  378. # example: python client.py 8000 --working-dir /workspace --plugins JupyterRequirement
  379. args = parser.parse_args()
  380. plugins_to_load: list[Plugin] = []
  381. if args.plugins:
  382. for plugin in args.plugins:
  383. if plugin not in ALL_PLUGINS:
  384. raise ValueError(f'Plugin {plugin} not found')
  385. plugins_to_load.append(ALL_PLUGINS[plugin]()) # type: ignore
  386. client: RuntimeClient | None = None
  387. @asynccontextmanager
  388. async def lifespan(app: FastAPI):
  389. global client
  390. client = RuntimeClient(
  391. plugins_to_load,
  392. work_dir=args.working_dir,
  393. username=args.username,
  394. user_id=args.user_id,
  395. browsergym_eval_env=args.browsergym_eval_env,
  396. )
  397. await client.ainit()
  398. yield
  399. # Clean up & release the resources
  400. client.close()
  401. app = FastAPI(lifespan=lifespan)
  402. @app.middleware('http')
  403. async def one_request_at_a_time(request: Request, call_next):
  404. assert client is not None
  405. async with client.lock:
  406. response = await call_next(request)
  407. return response
  408. @app.post('/execute_action')
  409. async def execute_action(action_request: ActionRequest):
  410. assert client is not None
  411. try:
  412. action = event_from_dict(action_request.action)
  413. if not isinstance(action, Action):
  414. raise HTTPException(status_code=400, detail='Invalid action type')
  415. observation = await client.run_action(action)
  416. return event_to_dict(observation)
  417. except Exception as e:
  418. logger.error(f'Error processing command: {str(e)}')
  419. raise HTTPException(status_code=500, detail=str(e))
  420. @app.post('/upload_file')
  421. async def upload_file(
  422. file: UploadFile, destination: str = '/', recursive: bool = False
  423. ):
  424. assert client is not None
  425. try:
  426. # Ensure the destination directory exists
  427. if not os.path.isabs(destination):
  428. raise HTTPException(
  429. status_code=400, detail='Destination must be an absolute path'
  430. )
  431. full_dest_path = destination
  432. if not os.path.exists(full_dest_path):
  433. os.makedirs(full_dest_path, exist_ok=True)
  434. if recursive:
  435. # For recursive uploads, we expect a zip file
  436. if not file.filename.endswith('.zip'):
  437. raise HTTPException(
  438. status_code=400, detail='Recursive uploads must be zip files'
  439. )
  440. zip_path = os.path.join(full_dest_path, file.filename)
  441. with open(zip_path, 'wb') as buffer:
  442. shutil.copyfileobj(file.file, buffer)
  443. # Extract the zip file
  444. shutil.unpack_archive(zip_path, full_dest_path)
  445. os.remove(zip_path) # Remove the zip file after extraction
  446. logger.info(
  447. f'Uploaded file {file.filename} and extracted to {destination}'
  448. )
  449. else:
  450. # For single file uploads
  451. file_path = os.path.join(full_dest_path, file.filename)
  452. with open(file_path, 'wb') as buffer:
  453. shutil.copyfileobj(file.file, buffer)
  454. logger.info(f'Uploaded file {file.filename} to {destination}')
  455. return JSONResponse(
  456. content={
  457. 'filename': file.filename,
  458. 'destination': destination,
  459. 'recursive': recursive,
  460. },
  461. status_code=200,
  462. )
  463. except Exception as e:
  464. raise HTTPException(status_code=500, detail=str(e))
  465. @app.get('/alive')
  466. async def alive():
  467. return {'status': 'ok'}
  468. # ================================
  469. # File-specific operations for UI
  470. # ================================
  471. @app.post('/list_files')
  472. async def list_files(request: Request):
  473. """List files in the specified path.
  474. This function retrieves a list of files from the agent's runtime file store,
  475. excluding certain system and hidden files/directories.
  476. To list files:
  477. ```sh
  478. curl http://localhost:3000/api/list-files
  479. ```
  480. Args:
  481. request (Request): The incoming request object.
  482. path (str, optional): The path to list files from. Defaults to '/'.
  483. Returns:
  484. list: A list of file names in the specified path.
  485. Raises:
  486. HTTPException: If there's an error listing the files.
  487. """
  488. assert client is not None
  489. # get request as dict
  490. request_dict = await request.json()
  491. path = request_dict.get('path', None)
  492. # Get the full path of the requested directory
  493. if path is None:
  494. full_path = client.initial_pwd
  495. elif os.path.isabs(path):
  496. full_path = path
  497. else:
  498. full_path = os.path.join(client.initial_pwd, path)
  499. if not os.path.exists(full_path):
  500. return JSONResponse(
  501. content={'error': f'Directory {full_path} does not exist'},
  502. status_code=400,
  503. )
  504. try:
  505. # Check if the directory exists
  506. if not os.path.exists(full_path) or not os.path.isdir(full_path):
  507. return []
  508. # Check if .gitignore exists
  509. gitignore_path = os.path.join(full_path, '.gitignore')
  510. if os.path.exists(gitignore_path):
  511. # Use PathSpec to parse .gitignore
  512. with open(gitignore_path, 'r') as f:
  513. spec = PathSpec.from_lines(GitWildMatchPattern, f.readlines())
  514. else:
  515. # Fallback to default exclude list if .gitignore doesn't exist
  516. default_exclude = [
  517. '.git',
  518. '.DS_Store',
  519. '.svn',
  520. '.hg',
  521. '.idea',
  522. '.vscode',
  523. '.settings',
  524. '.pytest_cache',
  525. '__pycache__',
  526. 'node_modules',
  527. 'vendor',
  528. 'build',
  529. 'dist',
  530. 'bin',
  531. 'logs',
  532. 'log',
  533. 'tmp',
  534. 'temp',
  535. 'coverage',
  536. 'venv',
  537. 'env',
  538. ]
  539. spec = PathSpec.from_lines(GitWildMatchPattern, default_exclude)
  540. entries = os.listdir(full_path)
  541. # Filter entries using PathSpec
  542. filtered_entries = [
  543. os.path.join(full_path, entry)
  544. for entry in entries
  545. if not spec.match_file(os.path.relpath(entry, str(full_path)))
  546. ]
  547. # Separate directories and files
  548. directories = []
  549. files = []
  550. for entry in filtered_entries:
  551. # Remove leading slash and any parent directory components
  552. entry_relative = entry.lstrip('/').split('/')[-1]
  553. # Construct the full path by joining the base path with the relative entry path
  554. full_entry_path = os.path.join(full_path, entry_relative)
  555. if os.path.exists(full_entry_path):
  556. is_dir = os.path.isdir(full_entry_path)
  557. if is_dir:
  558. # add trailing slash to directories
  559. # required by FE to differentiate directories and files
  560. entry = entry.rstrip('/') + '/'
  561. directories.append(entry)
  562. else:
  563. files.append(entry)
  564. # Sort directories and files separately
  565. directories.sort(key=lambda s: s.lower())
  566. files.sort(key=lambda s: s.lower())
  567. # Combine sorted directories and files
  568. sorted_entries = directories + files
  569. return sorted_entries
  570. except Exception as e:
  571. logger.error(f'Error listing files: {e}', exc_info=True)
  572. return []
  573. logger.info(f'Starting action execution API on port {args.port}')
  574. print(f'Starting action execution API on port {args.port}')
  575. run(app, host='0.0.0.0', port=args.port)