Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Improve services filtering
Tomas Valenta007c5e4e699b
diff --git a/apps/docs/src/app/cli/commands/page.mdx b/apps/docs/src/app/cli/commands/page.mdxindex 495886c50..f9b09b2fe 100644--- a/apps/docs/src/app/cli/commands/page.mdx+++ b/apps/docs/src/app/cli/commands/page.mdx@@ -284,8 +284,8 @@ You can use `e2b sandbox list` to get a list of running sandboxes and their IDs</Option><Option name="services" type="--services">Specify services for printing logs — allowed values are `process`, `filesystem`, `terminal`, `network`.- You can specify multiple services by separating them with a space.+ You can specify multiple services by separating them with a comma.- Default value is `process, filesystem`.+ Default value is `process,filesystem`.</Option></Options>diff --git a/packages/cli/src/commands/sandbox/logs.ts b/packages/cli/src/commands/sandbox/logs.tsindex 9e17548f4..1d2989cc3 100644--- a/packages/cli/src/commands/sandbox/logs.ts+++ b/packages/cli/src/commands/sandbox/logs.ts@@ -3,13 +3,13 @@ import * as e2b from 'e2b'import * as util from 'util'import * as chalk from 'chalk'-import { ensureAPIKey } from 'src/api'+import { client, ensureAPIKey } from 'src/api'import { asBold, asTimestamp, withUnderline } from 'src/utils/format'import { listSandboxes } from './list'import { wait } from 'src/utils/wait'const getSandboxLogs = e2b.withAPIKey(- e2b.api.path('/sandboxes/{sandboxID}/logs').method('get').create(),+ client.api.path('/sandboxes/{sandboxID}/logs').method('get').create(),)const maxRuntime = 24 * 60 * 60 * 1000 // 24 hours in milliseconds@@ -109,13 +109,25 @@ export const logsCommand = new commander.Command('logs').option('-l, --level <level>', `filter logs by level (${formatEnum(LogLevel)}). The logs with the higher levels will be also shown.`, LogLevel.INFO).option('-f, --follow', 'keep streaming logs until the sandbox is closed').option('--format <format>', `specify format for printing logs (${formatEnum(LogFormat)})`, LogFormat.PRETTY)- .option('--s <services...>, --service <services...>', `filter logs by service (${formatEnum(LogService)})`, [LogService.PROCESS, LogService.FILESYSTEM])+ .option('-s, --services [services]', `filter logs by service. The available services are ${formatEnum(LogService)}. Specify multiple services by separating them with a comma.`, (value) => {+ const services = value.split(',').map(s => s.trim()) as LogService[]+ // Check if all services are valid+ services.forEach(s => {+ if (!Object.values(LogService).includes(s)) {+ console.error(`Invalid service used as argument: "${s}"\nValid services are ${formatEnum(LogService)}`)+ process.exit(1)+ }+ })++ return services+ }, [LogService.PROCESS, LogService.FILESYSTEM]).action(async (sandboxID: string, opts?: {level: string,follow: boolean,format: LogFormat,- services: LogService[],+ services: LogService[] | boolean,}) => {+ console.log(opts?.services)try {const level = opts?.level.toUpperCase() as LogLevel | undefinedif (level && !Object.values(LogLevel).includes(level)) {@@ -206,14 +218,14 @@ export const logsCommand = new commander.Command('logs')}})-function printLog(timestamp: string, line: string, allowedLevel: LogLevel | undefined, format: LogFormat | undefined, allowedLoggers: LogService[]) {+function printLog(timestamp: string, line: string, allowedLevel: LogLevel | undefined, format: LogFormat | undefined, allowedLoggers?: LogService[] | boolean) {const log = JSON.parse(line)let level = log['level'].toUpperCase()log.logger = cleanLogger(log.logger)// Check if the current logger startsWith any of the allowed loggers. If there are no specified loggers, print logs from all services.- if (!allowedLoggers.some(allowedLogger => log.logger.startsWith(allowedLogger)) && allowedLoggers.length > 0) {+ if (allowedLoggers !== true && Array.isArray(allowedLoggers) && !allowedLoggers.some(allowedLogger => log.logger.startsWith(allowedLogger))) {return}