{"version":3,"file":"utils/workspace.mjs","sources":["webpack://@agent-tars/server/./src/utils/workspace.ts"],"sourcesContent":["/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { WorkspacePathManager } from './workspace-path';\n\n/**\n * Ensures a working directory exists and returns its path\n * @param namespace workspace namespace, used when you need to isolate the execution of tasks\n * @param workspacePath optional path to workspace directory (defaults to CWD/agent-tars-workspace)\n * @param isolateSessions whether to create isolated session directories (default: false)\n * @param isDebug whether to log debug information\n * @returns Path to the working directory\n */\nexport function ensureWorkingDirectory(\n  namespace: string,\n  workspacePath?: string,\n  isolateSessions = false,\n  isDebug = false,\n): string {\n  try {\n    // Resolve the workspace path using the workspace path manager\n    const baseDir = process.cwd();\n    const resolvedPath = WorkspacePathManager.resolveWorkspacePath(\n      baseDir,\n      workspacePath,\n      namespace,\n      isolateSessions,\n    );\n\n    // Ensure the directory exists\n    const workingDirectory = WorkspacePathManager.ensureWorkspaceDirectory(resolvedPath);\n\n    if (isDebug) {\n      console.log(`Created or verified working directory: ${workingDirectory}`);\n    }\n    return workingDirectory;\n  } catch (error) {\n    console.error(`Failed to create working directory:`, error);\n    throw new Error(\n      `Failed to initialize agent workspace: ${error instanceof Error ? error.message : String(error)}`,\n    );\n  }\n}\n"],"names":["ensureWorkingDirectory","namespace","workspacePath","isolateSessions","isDebug","baseDir","process","resolvedPath","WorkspacePathManager","workingDirectory","console","error","Error","String"],"mappings":";;;;;AAeO,SAASA,uBACdC,SAAiB,EACjBC,aAAsB,EACtBC,kBAAkB,KAAK,EACvBC,UAAU,KAAK;IAEf,IAAI;QAEF,MAAMC,UAAUC,QAAQ,GAAG;QAC3B,MAAMC,eAAeC,qBAAqB,oBAAoB,CAC5DH,SACAH,eACAD,WACAE;QAIF,MAAMM,mBAAmBD,qBAAqB,wBAAwB,CAACD;QAEvE,IAAIH,SACFM,QAAQ,GAAG,CAAC,CAAC,uCAAuC,EAAED,kBAAkB;QAE1E,OAAOA;IACT,EAAE,OAAOE,OAAO;QACdD,QAAQ,KAAK,CAAC,uCAAuCC;QACrD,MAAM,IAAIC,MACR,CAAC,sCAAsC,EAAED,iBAAiBC,QAAQD,MAAM,OAAO,GAAGE,OAAOF,QAAQ;IAErG;AACF"}