Files
t3code/apps/web/src/components/settings/ProviderAuthTerminal.tsx
T
+36 de34391427 feat(orchestrator): introduce new orchestrator (#2829)
Co-authored-by: maria-rcks <[email protected]>
Co-authored-by: Bilal Bakr <[email protected]>
Co-authored-by: shivam <[email protected]>
Co-authored-by: Vitalii Yehorov <[email protected]>
Co-authored-by: Jake Leventhal <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: Alex Southwell <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Nicholas Wasmiller <[email protected]>
Co-authored-by: PB <[email protected]>
Co-authored-by: Exotic <[email protected]>
Co-authored-by: Yash Singh <[email protected]>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Theo Browne <[email protected]>
Co-authored-by: Gabriel De Andrade <[email protected]>
Co-authored-by: Dara Adedeji <[email protected]>
Co-authored-by: scratchyone <[email protected]>
Co-authored-by: Dominic Roy <[email protected]>
Co-authored-by: chukfinley <[email protected]>
Co-authored-by: Primož Ajdišek <[email protected]>
Co-authored-by: benthecarman <[email protected]>
Co-authored-by: NaveDanan <[email protected]>
Co-authored-by: aaditagrawal <[email protected]>
Co-authored-by: Aditya Garud <[email protected]>
Co-authored-by: Nick Anisimov <[email protected]>
Co-authored-by: MacKinley Smith <[email protected]>
Co-authored-by: Yordis Prieto <[email protected]>
Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com>
Co-authored-by: AKolenda <[email protected]>
Co-authored-by: Guillermo Casanova <[email protected]>
Co-authored-by: Otavio Salvador <[email protected]>
Co-authored-by: Shirish Pothi <[email protected]>
Co-authored-by: Ishaan Kothari <[email protected]>
Co-authored-by: Bob Fowler <[email protected]>
Co-authored-by: Anton Bezdenezhnykh <[email protected]>
Co-authored-by: ValeraZSD <[email protected]>
Co-authored-by: Ephraim <[email protected]>
Co-authored-by: Ryan Ilano <[email protected]>
Co-authored-by: Alex <[email protected]>
Co-authored-by: maco <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Tristan Knight <[email protected]>
Co-authored-by: PR Batch Tester <[email protected]>
Co-authored-by: oliver <[email protected]>
Co-authored-by: kamkm <[email protected]>
Signed-off-by: Yordis Prieto <[email protected]>
2026-10-02 12:22:22 -07:00

81 lines
2.9 KiB
TypeScript

import type { ProviderAuthResponse } from "@t3tools/contracts";
import { useEffect, useRef, useState } from "react";
import { GhosttyTerminalSurface } from "../../terminal/ghostty/surface";
import { ensureLocalApi } from "../../localApi";
import { terminalThemeFromApp } from "../ThreadTerminalDrawer";
/** Loaded only for an interactive login. PTY input is serialized by the parent. */
export default function ProviderAuthTerminal({
output,
outputOffset,
onResponse,
}: {
readonly output: string;
readonly outputOffset?: number | undefined;
readonly onResponse: (response: Extract<ProviderAuthResponse, { type: "terminal" }>) => void;
}) {
const mount = useRef<HTMLDivElement>(null);
const surface = useRef<GhosttyTerminalSurface | null>(null);
const latest = useRef({ output, offset: outputOffset ?? output.length, onResponse });
const written = useRef(0);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
latest.current = { output, offset: outputOffset ?? output.length, onResponse };
const terminal = surface.current;
if (!terminal) return;
const delta = latest.current.offset - written.current;
if (delta > 0 && delta <= output.length) terminal.write(output.slice(-delta));
else if (delta !== 0) terminal.resetAndWrite(output);
written.current = latest.current.offset;
}, [output, outputOffset, onResponse]);
useEffect(() => {
const element = mount.current;
if (!element) return;
let disposed = false;
void GhosttyTerminalSurface.create(element, {
theme: terminalThemeFromApp(element),
font: { size: 13 },
onData: (data) => latest.current.onResponse({ type: "terminal", data }),
onResize: (cols, rows) =>
latest.current.onResponse({ type: "terminal", data: "", size: { cols, rows } }),
onSelectionChange: () => {},
beforeKey: (event) => event.key !== "Tab",
onLinkActivate: (url) => {
if (/^https?:\/\//i.test(url))
void ensureLocalApi()
.shell.openExternal(url)
.catch(() => setError("Could not open the provider link."));
},
})
.then((terminal) => {
if (disposed) {
terminal.dispose();
return;
}
surface.current = terminal;
terminal.write(latest.current.output);
written.current = latest.current.offset;
})
.catch(() => setError("Could not load the sign-in terminal. Cancel and retry sign-in."));
return () => {
disposed = true;
surface.current?.dispose();
surface.current = null;
};
}, []);
return (
<>
<div
ref={mount}
aria-label="Provider sign-in terminal"
className="relative h-64 overflow-hidden rounded-md border border-border"
/>
{error ? (
<p role="alert" className="text-destructive">
{error}
</p>
) : null}
</>
);
}