11import { Effect , Match , pipe } from "effect"
22
33import {
4+ type ApiTerminalSession ,
45 codexImport ,
56 codexLogin ,
67 codexLogout ,
@@ -9,19 +10,19 @@ import {
910 githubLogin ,
1011 githubLogout ,
1112 githubStatus ,
12- grokLogout ,
13- grokStatus ,
1413 gitlabLogin ,
1514 gitlabLogout ,
1615 gitlabStatus ,
16+ grokLogout ,
17+ grokStatus ,
1718 type JsonValue ,
1819 renderJsonPayload
1920} from "./api-client.js"
2021import { type ControllerRuntime , ensureControllerReady } from "./controller.js"
2122import type { Command } from "./frontend-lib/core/domain.js"
22- import type { ApiRequestError , CliError } from "./host-errors.js"
23+ import type { ApiRequestError , CliError , ControllerBootstrapError } from "./host-errors.js"
2324import { terminalAuthTitle } from "./menu-auth-shared.js"
24- import { attachTerminalSession } from "./terminal-session-client.js"
25+ import { attachTerminalSession , type TerminalSessionClientError } from "./terminal-session-client.js"
2526
2627type OperationalCommand = Exclude < Command , { readonly _tag : "Help" } >
2728
@@ -45,7 +46,9 @@ export type RoutedAuthCommand = Extract<
4546 }
4647>
4748
48- const withControllerReady = < E , R > ( effect : Effect . Effect < void , E , R > ) =>
49+ const withControllerReady = < E extends CliError , R > (
50+ effect : Effect . Effect < void , E , R >
51+ ) : Effect . Effect < void , E | ControllerBootstrapError , R | ControllerRuntime > =>
4952 pipe ( ensureControllerReady ( ) , Effect . zipRight ( effect ) )
5053
5154const renderAuthPayload = ( payload : JsonValue ) => Effect . log ( renderJsonPayload ( payload ) )
@@ -57,6 +60,17 @@ const missingAuthTerminalSessionError = (provider: "GrokOauth"): ApiRequestError
5760 message : `Controller did not create a terminal session for ${ provider } .`
5861} )
5962
63+ const attachGrokTerminalSession = (
64+ session : ApiTerminalSession | null
65+ ) : Effect . Effect < void , ApiRequestError | TerminalSessionClientError > =>
66+ session === null
67+ ? Effect . fail ( missingAuthTerminalSessionError ( "GrokOauth" ) )
68+ : attachTerminalSession ( {
69+ header : terminalAuthTitle ( "GrokOauth" ) ,
70+ session,
71+ websocketPath : `/auth/terminal-sessions/${ encodeURIComponent ( session . id ) } /ws`
72+ } )
73+
6074const routedAuthTags : Readonly < Record < string , true > > = {
6175 AuthCodexImport : true ,
6276 AuthCodexLogin : true ,
@@ -111,15 +125,7 @@ const handleGrokLoginCommand = (
111125) =>
112126 withControllerReady (
113127 createAuthTerminalSession ( "GrokOauth" , command . label ) . pipe (
114- Effect . flatMap ( ( session ) =>
115- session === null
116- ? Effect . fail ( missingAuthTerminalSessionError ( "GrokOauth" ) )
117- : attachTerminalSession ( {
118- header : terminalAuthTitle ( "GrokOauth" ) ,
119- session,
120- websocketPath : `/auth/terminal-sessions/${ encodeURIComponent ( session . id ) } /ws`
121- } )
122- )
128+ Effect . flatMap ( ( session ) => attachGrokTerminalSession ( session ) )
123129 )
124130 )
125131
0 commit comments