mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 21:04:23 +01:00
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { useSessionSandbox, useSetSessionSandbox } from '@/hooks/useSessionSandbox'
|
|
|
|
export function useSandboxToggle(sessionID: string, options: { enabled?: boolean } = {}) {
|
|
const { data, isError } = useSessionSandbox(sessionID, options)
|
|
const setSandbox = useSetSessionSandbox(sessionID)
|
|
|
|
const loaded = data !== undefined
|
|
const isSandboxed = data?.sandboxed ?? false
|
|
const available = data?.available ?? true
|
|
const lockedReason = data?.lockedReason ?? null
|
|
const resources = data?.resources ?? null
|
|
const effectiveResources = data?.effectiveResources
|
|
const disabled = !loaded || lockedReason !== null || setSandbox.isPending
|
|
|
|
const label = !loaded
|
|
? isError
|
|
? 'Sandbox: unavailable'
|
|
: 'Sandbox: loading'
|
|
: lockedReason === 'child'
|
|
? 'Inherited from parent session'
|
|
: isSandboxed
|
|
? 'Sandbox: commands run in a microVM'
|
|
: 'Sandbox: commands run on the host'
|
|
|
|
const toggle = () => {
|
|
if (disabled) return
|
|
setSandbox.mutate({ sandboxed: !isSandboxed })
|
|
}
|
|
|
|
return { isSandboxed, available, disabled, label, toggle, lockedReason, resources, effectiveResources }
|
|
}
|