The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { useAtomValue } from "@effect/atom-react"; |
| 2 | import type { EnvironmentId, ProviderInstanceId } from "@t3tools/contracts"; |
| 3 | import { T, useGT, useMessages } from "gt-react"; |
| 4 | |
| 5 | import { useEnvironmentQuery } from "../../state/query"; |
| 6 | import { EMPTY_SERVER_PROVIDERS, serverEnvironment } from "../../state/server"; |
| 7 | import { Button } from "../ui/button"; |
| 8 | import { WizardFooter, WizardPanel } from "../ui/wizard"; |
| 9 | import { ProviderAuthenticationSection } from "./ProviderAuthenticationSection"; |
| 10 | import { SettingsGroup } from "./SettingsGroup"; |
| 11 | import { SettingsRow } from "./settingsLayout"; |
| 12 | |
| 13 | export function ProviderWizardAuthenticationStep({ |
| 14 | environmentId, |
| 15 | environmentLabel, |
| 16 | instanceId, |
| 17 | onFinish, |
| 18 | }: { |
| 19 | readonly environmentId: EnvironmentId; |
| 20 | readonly environmentLabel: string; |
| 21 | readonly instanceId: ProviderInstanceId; |
| 22 | readonly onFinish: () => void; |
| 23 | }) { |
| 24 | const gt = useGT(); |
| 25 | const providers = |
| 26 | useAtomValue(serverEnvironment.providersValueAtom(environmentId)) ?? EMPTY_SERVER_PROVIDERS; |
| 27 | const provider = providers.find((candidate) => candidate.instanceId === instanceId); |
| 28 | const query = useEnvironmentQuery( |
| 29 | serverEnvironment.providerAuthState({ environmentId, input: { instanceId } }), |
| 30 | useMessages(), |
| 31 | ); |
| 32 | const auth = query.data; |
| 33 | const active = |
| 34 | auth?.phase === "starting" || auth?.phase === "waiting" || auth?.phase === "verifying"; |
| 35 | const signedIn = |
| 36 | provider?.auth.status === "authenticated" || |
| 37 | (provider?.auth.status === "unknown" && auth?.phase === "succeeded"); |
| 38 | const isDiscovering = !signedIn && !query.error && auth?.methods === undefined; |
| 39 | const canAuthenticate = (auth?.methods?.length ?? 0) > 0; |
| 40 | |
| 41 | return ( |
| 42 | <> |
| 43 | <WizardPanel className="min-h-72"> |
| 44 | <SettingsGroup variant="plain"> |
| 45 | {provider && (canAuthenticate || signedIn) ? ( |
| 46 | <ProviderAuthenticationSection |
| 47 | environmentId={environmentId} |
| 48 | environmentLabel={environmentLabel} |
| 49 | instanceId={instanceId} |
| 50 | provider={{ |
| 51 | ...provider, |
| 52 | setup: { |
| 53 | ...provider.setup, |
| 54 | canInstall: provider.setup?.canInstall ?? false, |
| 55 | canAuthenticate, |
| 56 | }, |
| 57 | }} |
| 58 | readOnly={false} |
| 59 | /> |
| 60 | ) : ( |
| 61 | <SettingsRow |
| 62 | title={gt("Account")} |
| 63 | description={ |
| 64 | isDiscovering |
| 65 | ? gt("Discovering sign-in methods…") |
| 66 | : (query.error ?? |
| 67 | auth?.message ?? |
| 68 | gt("No in-app sign-in advertised. Follow the provider's docs to finish setup.")) |
| 69 | } |
| 70 | control={ |
| 71 | isDiscovering ? ( |
| 72 | <Button disabled size="sm" variant="outline"> |
| 73 | <T>Sign in</T> |
| 74 | </Button> |
| 75 | ) : provider?.setup?.documentationUrl ? ( |
| 76 | <Button |
| 77 | size="sm" |
| 78 | variant="outline" |
| 79 | render={ |
| 80 | <a href={provider.setup.documentationUrl} target="_blank" rel="noreferrer" /> |
| 81 | } |
| 82 | > |
| 83 | <T>Open docs</T> |
| 84 | </Button> |
| 85 | ) : undefined |
| 86 | } |
| 87 | /> |
| 88 | )} |
| 89 | </SettingsGroup> |
| 90 | </WizardPanel> |
| 91 | <WizardFooter> |
| 92 | <Button |
| 93 | size="sm" |
| 94 | variant={signedIn ? "default" : "outline"} |
| 95 | disabled={active} |
| 96 | onClick={onFinish} |
| 97 | > |
| 98 | {signedIn ? gt("Done") : gt("Skip for now")} |
| 99 | </Button> |
| 100 | </WizardFooter> |
| 101 | </> |
| 102 | ); |
| 103 | } |