Files
opencode-manager/frontend/src/lib/sandboxResources.ts
T
Chris Scott 95a9f6e1ed feat(sandbox): add the session sandbox control to the desktop composer
The sandbox toggle and resources dialog were only reachable from the mobile composer menu. Add SessionSandboxMenu next to the permission toggle on desktop and share the sandbox menu items with the mobile menu.
2026-10-15 16:53:49 -04:00

24 lines
861 B
TypeScript

import type { SessionSandboxResources } from '@opencode-manager/shared/schemas'
import type { useSandboxToggle } from '@/hooks/useSandboxToggle'
export type SandboxToggleState = ReturnType<typeof useSandboxToggle>
export function shouldShowSandboxResources(sandbox: SandboxToggleState): boolean {
return (
sandbox.available &&
sandbox.isSandboxed &&
sandbox.lockedReason !== 'child' &&
sandbox.effectiveResources !== undefined
)
}
export function formatSandboxMemory(memoryMib: number): string {
const gib = memoryMib / 1024
return Number.isInteger(gib) ? String(gib) : String(Number(gib.toFixed(1)))
}
export function formatSandboxResources(resources: SessionSandboxResources): string {
const cpus = `${resources.cpus} CPU${resources.cpus === 1 ? '' : 's'}`
return `${cpus} · ${formatSandboxMemory(resources.memoryMib)} GiB`
}