diff --git a/app/api/openshell/terminal/introspect/route.ts b/app/api/openshell/terminal/introspect/route.ts new file mode 100644 index 0000000..635a994 --- /dev/null +++ b/app/api/openshell/terminal/introspect/route.ts @@ -0,0 +1,31 @@ +import { NextResponse } from 'next/server' +import { dockerExecInOpenShell, OPENSHELL_NAMESPACE } from '../../../../lib/openshellHost' + +export async function GET(request: Request) { + try { + const { searchParams } = new URL(request.url) + const sandboxId = searchParams.get('sandboxId') + + if (!sandboxId) { + return NextResponse.json({ error: 'sandboxId is required' }, { status: 400 }) + } + + const jsonpath = `{.spec.containers[*].name}{"\n"}{.spec.containers[*].image}{"\n"}{.status.containerStatuses[*].name}{"\n"}` + const result = await dockerExecInOpenShell( + `kubectl -n ${OPENSHELL_NAMESPACE} get pod ${sandboxId} -o jsonpath='${jsonpath}'` + ) + + return NextResponse.json({ + ok: true, + sandboxId, + raw: result.stdout.trim(), + stderr: result.stderr.trim(), + note: 'Pod/container introspection succeeded. Use this to select the right exec target for terminal attach.' + }) + } catch (error) { + return NextResponse.json({ + ok: false, + error: error instanceof Error ? error.message : 'Failed to introspect sandbox pod' + }, { status: 500 }) + } +} diff --git a/app/components/SandboxList.tsx b/app/components/SandboxList.tsx index 16799e9..7e9ce02 100644 --- a/app/components/SandboxList.tsx +++ b/app/components/SandboxList.tsx @@ -202,7 +202,11 @@ export default function SandboxList({ if (data.ok) { setTerminalMessage(`Terminal probe succeeded for ${selectedSandbox}: ${data.output || 'attached'}`) } else { - setTerminalMessage(data.error || 'Failed to attach to OpenShell terminal.') + const inspectRes = await fetch(`/api/openshell/terminal/introspect?sandboxId=${encodeURIComponent(selectedSandbox)}`) + const inspectData = await inspectRes.json() + setTerminalMessage(inspectData.ok + ? `Terminal probe failed. Pod introspection for ${selectedSandbox}: ${inspectData.raw}` + : (data.error || 'Failed to attach to OpenShell terminal.')) } } catch (error) { setTerminalMessage('Failed to attach to OpenShell terminal.')