Reduce permission polling and show verified inference routes
This commit is contained in:
@@ -144,7 +144,7 @@ export default function InferenceEndpointPanel() {
|
||||
function useNvidiaInferencePreset() {
|
||||
setName("nvidia-inference")
|
||||
setType("openai")
|
||||
setModel("us/aws/anthropic/bedrock-claude-opus-4-6")
|
||||
setModel("aws/anthropic/claude-opus-4-5")
|
||||
setBaseUrl("https://inference-api.nvidia.com/v1")
|
||||
setCredentialKey("NVIDIA_API_KEY")
|
||||
setRoute("gateway")
|
||||
|
||||
@@ -9,6 +9,14 @@ type ProviderSummary = {
|
||||
type: string | null
|
||||
}
|
||||
|
||||
type InferenceRouteStatus = {
|
||||
configured: boolean
|
||||
provider: string | null
|
||||
model: string | null
|
||||
version: string | null
|
||||
timeout: string | null
|
||||
}
|
||||
|
||||
type OllamaModel = {
|
||||
name: string
|
||||
sizeLabel: string | null
|
||||
@@ -68,6 +76,7 @@ export default function SandboxInferencePanel({
|
||||
const [applying, setApplying] = useState(false)
|
||||
const [message, setMessage] = useState("")
|
||||
const [providers, setProviders] = useState<ProviderSummary[]>([])
|
||||
const [verifiedRoutes, setVerifiedRoutes] = useState<Array<SandboxInferenceRoute & { scope: "Sandbox" | "System" }>>([])
|
||||
const [routes, setRoutes] = useState<SandboxInferenceRoute[]>([])
|
||||
const [primaryRouteId, setPrimaryRouteId] = useState("")
|
||||
const [draftProvider, setDraftProvider] = useState("")
|
||||
@@ -111,8 +120,18 @@ export default function SandboxInferencePanel({
|
||||
|
||||
const nextProviders = Array.isArray(inferenceData.providers) ? inferenceData.providers : []
|
||||
const config = configData.config as SandboxInferenceConfig
|
||||
const fallbackProvider = inferenceData.gateway?.provider || nextProviders[0]?.name || ""
|
||||
const fallbackModel = inferenceData.gateway?.model || ""
|
||||
const gatewayRoute = inferenceData.gateway as InferenceRouteStatus | undefined
|
||||
const systemRoute = inferenceData.system as InferenceRouteStatus | undefined
|
||||
const nextVerifiedRoutes = [
|
||||
gatewayRoute?.configured && gatewayRoute.provider && gatewayRoute.model
|
||||
? { ...makeRoute(gatewayRoute.provider, gatewayRoute.model, "Active sandbox route"), scope: "Sandbox" as const }
|
||||
: null,
|
||||
systemRoute?.configured && systemRoute.provider && systemRoute.model
|
||||
? { ...makeRoute(systemRoute.provider, systemRoute.model, "Active system route"), scope: "System" as const }
|
||||
: null,
|
||||
].filter((route): route is SandboxInferenceRoute & { scope: "Sandbox" | "System" } => Boolean(route))
|
||||
const fallbackProvider = gatewayRoute?.provider || nextProviders[0]?.name || ""
|
||||
const fallbackModel = gatewayRoute?.model || ""
|
||||
const nextRoutes = dedupeRoutes(Array.isArray(config?.routes) && config.routes.length > 0
|
||||
? config.routes
|
||||
: fallbackProvider && fallbackModel
|
||||
@@ -120,6 +139,7 @@ export default function SandboxInferencePanel({
|
||||
: [])
|
||||
|
||||
setProviders(nextProviders)
|
||||
setVerifiedRoutes(nextVerifiedRoutes)
|
||||
setRoutes(nextRoutes)
|
||||
setPrimaryRouteId(config?.primaryRouteId || nextRoutes[0]?.id || "")
|
||||
setDraftProvider(fallbackProvider)
|
||||
@@ -273,6 +293,32 @@ export default function SandboxInferencePanel({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{verifiedRoutes.length > 0 && (
|
||||
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4">
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<h5 className="text-xs uppercase tracking-wider text-[var(--foreground)]">Verified Working Routes</h5>
|
||||
<span className="text-[10px] uppercase tracking-wider text-[var(--nvidia-green)]">OpenShell active</span>
|
||||
</div>
|
||||
<div className="mt-3 grid grid-cols-1 gap-2 md:grid-cols-2">
|
||||
{verifiedRoutes.map((route) => (
|
||||
<button
|
||||
key={`${route.scope}-${route.id}`}
|
||||
type="button"
|
||||
onClick={() => addRoute(route.provider, route.model, route.label)}
|
||||
className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-3 text-left hover:border-[var(--nvidia-green)]"
|
||||
>
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<span className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">{route.scope}</span>
|
||||
<span className="text-[10px] uppercase tracking-wider text-[var(--nvidia-green)]">Add</span>
|
||||
</div>
|
||||
<div className="mt-2 text-xs font-mono text-[var(--foreground)]">{route.provider}</div>
|
||||
<div className="mt-1 break-all text-[11px] font-mono text-[var(--foreground-dim)]">{route.model}</div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="grid grid-cols-1 lg:grid-cols-[minmax(180px,240px)_minmax(0,1fr)_minmax(160px,220px)_auto] gap-3 items-end">
|
||||
<div className="space-y-2">
|
||||
<label className="text-[10px] uppercase tracking-wider text-[var(--foreground-dim)]">Endpoint</label>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"use client"
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import type { ReactNode } from 'react'
|
||||
import ConfigurationPanel from './ConfigurationPanel'
|
||||
import SandboxArchivePanel from './SandboxArchivePanel'
|
||||
@@ -150,34 +150,35 @@ export default function SandboxList({
|
||||
}
|
||||
}, [selectedSandboxId])
|
||||
|
||||
const loadPermissionFeed = useCallback(async (sandbox: SandboxInventoryItem) => {
|
||||
try {
|
||||
const response = await fetch(`/api/sandbox/${encodeURIComponent(sandbox.id)}/permissions`, { cache: 'no-store' })
|
||||
const data = await response.json()
|
||||
const feed = response.ok ? data.feed : { rejectedCount: 1, latest: { status: 'Unavailable', error: data.error } }
|
||||
setPermissionFeeds((current) => ({ ...current, [sandbox.id]: feed }))
|
||||
} catch (error) {
|
||||
setPermissionFeeds((current) => ({
|
||||
...current,
|
||||
[sandbox.id]: { rejectedCount: 1, latest: { status: 'Unavailable', error: error instanceof Error ? error.message : 'Permission feed unavailable' } },
|
||||
}))
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
if (sandboxes.length === 0) {
|
||||
setPermissionFeeds({})
|
||||
return
|
||||
}
|
||||
|
||||
let active = true
|
||||
const loadPermissionFeeds = async () => {
|
||||
const entries = await Promise.all(sandboxes.map(async (sandbox) => {
|
||||
try {
|
||||
const response = await fetch(`/api/sandbox/${encodeURIComponent(sandbox.id)}/permissions`, { cache: 'no-store' })
|
||||
const data = await response.json()
|
||||
return [sandbox.id, response.ok ? data.feed : { rejectedCount: 1, latest: { status: 'Unavailable', error: data.error } }] as const
|
||||
} catch (error) {
|
||||
return [sandbox.id, { rejectedCount: 1, latest: { status: 'Unavailable', error: error instanceof Error ? error.message : 'Permission feed unavailable' } }] as const
|
||||
}
|
||||
}))
|
||||
if (active) setPermissionFeeds(Object.fromEntries(entries))
|
||||
}
|
||||
|
||||
loadPermissionFeeds()
|
||||
const interval = window.setInterval(loadPermissionFeeds, 12000)
|
||||
return () => {
|
||||
active = false
|
||||
window.clearInterval(interval)
|
||||
}
|
||||
setPermissionFeeds((current) => Object.fromEntries(
|
||||
Object.entries(current).filter(([sandboxId]) => sandboxes.some((sandbox) => sandbox.id === sandboxId)),
|
||||
))
|
||||
}, [sandboxes])
|
||||
|
||||
useEffect(() => {
|
||||
if (!selectedSandbox || !openDrawers.policy || permissionFeeds[selectedSandbox.id]) return
|
||||
loadPermissionFeed(selectedSandbox)
|
||||
}, [loadPermissionFeed, openDrawers.policy, permissionFeeds, selectedSandbox])
|
||||
|
||||
useEffect(() => {
|
||||
let active = true
|
||||
const loadMcpAccess = async () => {
|
||||
@@ -232,7 +233,11 @@ export default function SandboxList({
|
||||
}
|
||||
|
||||
const toggleDrawer = (key: DrawerKey) => {
|
||||
const opening = !openDrawers[key]
|
||||
setOpenDrawers((current) => ({ ...current, [key]: !current[key] }))
|
||||
if (key === 'policy' && opening && selectedSandbox) {
|
||||
loadPermissionFeed(selectedSandbox)
|
||||
}
|
||||
}
|
||||
|
||||
const sandboxCanAccessMcpServer = (sandbox: SandboxInventoryItem, server: McpServerAccess) => {
|
||||
@@ -677,6 +682,20 @@ export default function SandboxList({
|
||||
onToggle={() => toggleDrawer('policy')}
|
||||
>
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between gap-4 rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4 max-sm:flex-col max-sm:items-start">
|
||||
<div>
|
||||
<h4 className="text-xs font-semibold uppercase tracking-wider text-[var(--foreground)]">Network Permission Feed</h4>
|
||||
<p className="mt-1 text-xs text-[var(--foreground-dim)]">Loaded on demand for the selected sandbox to avoid background permission polling.</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
disabled={grantingSandboxId === selectedSandbox.id}
|
||||
onClick={() => loadPermissionFeed(selectedSandbox)}
|
||||
className="action-button px-3 py-2 max-sm:w-full"
|
||||
>
|
||||
Refresh Requests
|
||||
</button>
|
||||
</div>
|
||||
{(() => {
|
||||
const feed = permissionFeeds[selectedSandbox.id]
|
||||
const pending = feed?.pending || []
|
||||
|
||||
@@ -74,7 +74,7 @@ assert.match(inferenceRouteSource, /\["inference", "set", "--provider", name, "-
|
||||
assert.match(inferenceRouteSource, /OPENAI_BASE_URL=\$\{baseUrl\}/, 'inference route must pass endpoint URL as provider config')
|
||||
assert.match(inferencePanelSource, /INFERENCE ENDPOINTS/, 'settings UI must expose inference endpoint configuration')
|
||||
assert.match(inferencePanelSource, /https:\/\/inference-api\.nvidia\.com\/v1/, 'settings UI must provide the NVIDIA inference API preset')
|
||||
assert.match(inferencePanelSource, /bedrock-claude-opus-4-6/, 'settings UI must include the requested NVIDIA inference model preset')
|
||||
assert.match(inferencePanelSource, /aws\/anthropic\/claude-opus-4-5/, 'settings UI must include the requested NVIDIA inference model preset')
|
||||
assert.match(inferencePanelSource, /method: "DELETE"/, 'settings UI must expose provider deletion')
|
||||
assert.match(inferencePanelSource, /\/api\/ollama\/models/, 'settings UI must poll local Ollama models')
|
||||
assert.match(inferencePanelSource, /window\.setInterval\(\(\) => loadOllamaModels\(\{ silent: true \}\), 10000\)/, 'settings UI must autopoll Ollama while selected')
|
||||
@@ -85,6 +85,8 @@ assert.match(sandboxInferenceRouteSource, /primaryRouteId/, 'sandbox inference r
|
||||
assert.match(sandboxInferenceRouteSource, /saveSandboxInferenceConfig/, 'sandbox inference route must persist per-sandbox inference profiles')
|
||||
assert.match(sandboxInferencePanelSource, /Save Sandbox Routes/, 'selected sandbox UI must expose multi-route inference saving')
|
||||
assert.match(sandboxInferencePanelSource, /Apply to Running Container/, 'selected sandbox UI must expose live apply for running containers')
|
||||
assert.match(sandboxInferencePanelSource, /Verified Working Routes/, 'selected sandbox UI must list verified active inference routes')
|
||||
assert.match(sandboxInferencePanelSource, /inferenceData\.system/, 'selected sandbox UI must include system route status when available')
|
||||
assert.match(sandboxInferencePanelSource, /\/api\/sandbox\/\$\{encodeURIComponent\(sandbox\.id\)\}\/inference/, 'selected sandbox UI must load and save sandbox-specific inference profiles')
|
||||
assert.match(sandboxInferencePanelSource, /\/api\/sandbox\/\$\{encodeURIComponent\(sandbox\.id\)\}\/inference\/apply/, 'selected sandbox UI must call live apply endpoint')
|
||||
assert.match(sandboxInferencePanelSource, /\/api\/ollama\/models/, 'selected sandbox UI must offer Ollama model selection')
|
||||
@@ -97,6 +99,8 @@ assert.match(sandboxRestartRouteSource, /\["delete", "pod", sandboxName, "-n", O
|
||||
assert.match(sandboxRestartRouteSource, /waitForSandboxReady\(sandboxName, 90000, 2000\)/, 'restart route must wait for OpenShell to report the sandbox ready')
|
||||
assert.match(sandboxListSource, /Restart Sandbox/, 'sandbox details must expose a restart sandbox button')
|
||||
assert.match(sandboxListSource, /\/api\/sandbox\/\$\{encodeURIComponent\(selectedSandbox\.id\)\}\/restart/, 'restart button must call the sandbox restart endpoint')
|
||||
assert.doesNotMatch(sandboxListSource, /setInterval\(loadPermissionFeeds/, 'sandbox list must not poll every sandbox permission feed')
|
||||
assert.match(sandboxListSource, /loadPermissionFeed\(selectedSandbox\)/, 'policy drawer must load the selected sandbox permission feed on demand')
|
||||
assert.match(sandboxListSource, /<SandboxInferencePanel sandbox=\{selectedSandbox\}/, 'sandbox list must render the per-sandbox inference profile panel for the selected sandbox')
|
||||
assert.match(sidebarSource, />Inference</, 'sidebar settings item must expose inference settings')
|
||||
assert.match(pageSource, /<InferenceEndpointPanel \/>/, 'settings view must render inference endpoint panel')
|
||||
|
||||
Reference in New Issue
Block a user