mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 11:17:40 +00:00
refactor(sandbox): dedupe session resolution
This commit is contained in:
@@ -64,11 +64,7 @@ async function ensureSandboxWorkspaceLayout(params: {
|
|||||||
return { agentWorkspaceDir, scopeKey, sandboxWorkspaceDir, workspaceDir };
|
return { agentWorkspaceDir, scopeKey, sandboxWorkspaceDir, workspaceDir };
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function resolveSandboxContext(params: {
|
function resolveSandboxSession(params: { config?: OpenClawConfig; sessionKey?: string }) {
|
||||||
config?: OpenClawConfig;
|
|
||||||
sessionKey?: string;
|
|
||||||
workspaceDir?: string;
|
|
||||||
}): Promise<SandboxContext | null> {
|
|
||||||
const rawSessionKey = params.sessionKey?.trim();
|
const rawSessionKey = params.sessionKey?.trim();
|
||||||
if (!rawSessionKey) {
|
if (!rawSessionKey) {
|
||||||
return null;
|
return null;
|
||||||
@@ -83,6 +79,19 @@ export async function resolveSandboxContext(params: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const cfg = resolveSandboxConfigForAgent(params.config, runtime.agentId);
|
const cfg = resolveSandboxConfigForAgent(params.config, runtime.agentId);
|
||||||
|
return { rawSessionKey, runtime, cfg };
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function resolveSandboxContext(params: {
|
||||||
|
config?: OpenClawConfig;
|
||||||
|
sessionKey?: string;
|
||||||
|
workspaceDir?: string;
|
||||||
|
}): Promise<SandboxContext | null> {
|
||||||
|
const resolved = resolveSandboxSession(params);
|
||||||
|
if (!resolved) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const { rawSessionKey, cfg } = resolved;
|
||||||
|
|
||||||
await maybePruneSandboxes(cfg);
|
await maybePruneSandboxes(cfg);
|
||||||
|
|
||||||
@@ -152,20 +161,11 @@ export async function ensureSandboxWorkspaceForSession(params: {
|
|||||||
sessionKey?: string;
|
sessionKey?: string;
|
||||||
workspaceDir?: string;
|
workspaceDir?: string;
|
||||||
}): Promise<SandboxWorkspaceInfo | null> {
|
}): Promise<SandboxWorkspaceInfo | null> {
|
||||||
const rawSessionKey = params.sessionKey?.trim();
|
const resolved = resolveSandboxSession(params);
|
||||||
if (!rawSessionKey) {
|
if (!resolved) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
const { rawSessionKey, cfg } = resolved;
|
||||||
const runtime = resolveSandboxRuntimeStatus({
|
|
||||||
cfg: params.config,
|
|
||||||
sessionKey: rawSessionKey,
|
|
||||||
});
|
|
||||||
if (!runtime.sandboxed) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const cfg = resolveSandboxConfigForAgent(params.config, runtime.agentId);
|
|
||||||
|
|
||||||
const { workspaceDir } = await ensureSandboxWorkspaceLayout({
|
const { workspaceDir } = await ensureSandboxWorkspaceLayout({
|
||||||
cfg,
|
cfg,
|
||||||
|
|||||||
Reference in New Issue
Block a user