@@ -2323,6 +2323,102 @@ export const webviewMessageHandler = async (
23232323
23242324 break
23252325 }
2326+ case "codexCliNativeCheckToken" : {
2327+ // Check if token exists in secrets
2328+ const token = await provider . context . secrets . get ( "codexCliOpenAiNativeToken" )
2329+ await provider . postMessageToWebview ( {
2330+ type : "codexCliNativeTokenStatus" ,
2331+ hasToken : ! ! token ,
2332+ } )
2333+ break
2334+ }
2335+ case "codexCliNativeSignIn" : {
2336+ try {
2337+ // Import the CLI handler module
2338+ const { CodexCliHandler } = await import ( "../../services/codex-cli/CodexCliHandler" )
2339+
2340+ // Get the CLI path from settings or use default
2341+ const cliPath = message . text || "codex"
2342+
2343+ // Run the sign-in flow
2344+ const handler = new CodexCliHandler ( cliPath )
2345+ const token = await handler . signIn ( )
2346+
2347+ if ( token ) {
2348+ // Store the token in secrets
2349+ await provider . context . secrets . store ( "codexCliOpenAiNativeToken" , token )
2350+
2351+ // Notify the webview of success
2352+ await provider . postMessageToWebview ( {
2353+ type : "codexCliNativeSignInResult" ,
2354+ success : true ,
2355+ } )
2356+
2357+ // Update the state to reflect the new token
2358+ await provider . postStateToWebview ( )
2359+ } else {
2360+ throw new Error ( "Failed to obtain token from CLI" )
2361+ }
2362+ } catch ( error ) {
2363+ provider . log ( `CodexCliNative sign-in failed: ${ error } ` )
2364+ await provider . postMessageToWebview ( {
2365+ type : "codexCliNativeSignInResult" ,
2366+ success : false ,
2367+ error : error instanceof Error ? error . message : String ( error ) ,
2368+ } )
2369+ }
2370+ break
2371+ }
2372+ case "codexCliNativeSignOut" : {
2373+ try {
2374+ // Clear the token from secrets
2375+ await provider . context . secrets . delete ( "codexCliOpenAiNativeToken" )
2376+
2377+ // Notify the webview of success
2378+ await provider . postMessageToWebview ( {
2379+ type : "codexCliNativeSignOutResult" ,
2380+ success : true ,
2381+ } )
2382+
2383+ // Update the state
2384+ await provider . postStateToWebview ( )
2385+ } catch ( error ) {
2386+ provider . log ( `CodexCliNative sign-out failed: ${ error } ` )
2387+ await provider . postMessageToWebview ( {
2388+ type : "codexCliNativeSignOutResult" ,
2389+ success : false ,
2390+ error : error instanceof Error ? error . message : String ( error ) ,
2391+ } )
2392+ }
2393+ break
2394+ }
2395+ case "codexCliNativeDetect" : {
2396+ try {
2397+ // Import the CLI handler module
2398+ const { CodexCliHandler } = await import ( "../../services/codex-cli/CodexCliHandler" )
2399+
2400+ // Get the CLI path from settings or use default
2401+ const cliPath = message . text || "codex"
2402+
2403+ // Check if CLI is available
2404+ const handler = new CodexCliHandler ( cliPath )
2405+ const isAvailable = await handler . detect ( )
2406+
2407+ await provider . postMessageToWebview ( {
2408+ type : "codexCliNativeDetectResult" ,
2409+ available : isAvailable ,
2410+ path : isAvailable ? cliPath : undefined ,
2411+ } )
2412+ } catch ( error ) {
2413+ provider . log ( `CodexCliNative detect failed: ${ error } ` )
2414+ await provider . postMessageToWebview ( {
2415+ type : "codexCliNativeDetectResult" ,
2416+ available : false ,
2417+ error : error instanceof Error ? error . message : String ( error ) ,
2418+ } )
2419+ }
2420+ break
2421+ }
23262422 case "rooCloudManualUrl" : {
23272423 try {
23282424 if ( ! message . text ) {
0 commit comments