@@ -117,6 +117,10 @@ enum Command {
117117 /// Revoke an API key by name.
118118 #[ arg( long) ]
119119 revoke_api_key : Option < String > ,
120+
121+ /// Interactive setup for ChatGPT Actions integration.
122+ #[ arg( long) ]
123+ setup_chatgpt : bool ,
120124 } ,
121125
122126 /// Manage embedding models.
@@ -675,6 +679,7 @@ async fn main() -> Result<()> {
675679 key_permissions,
676680 list_api_keys,
677681 revoke_api_key,
682+ setup_chatgpt,
678683 } => {
679684 let mut cfg = Config :: load ( ) ?;
680685
@@ -816,6 +821,64 @@ async fn main() -> Result<()> {
816821 }
817822 }
818823
824+ if setup_chatgpt {
825+ println ! ( "Setting up engraph for ChatGPT Actions...\n " ) ;
826+
827+ if !cfg. http . enabled {
828+ cfg. http . enabled = true ;
829+ println ! ( "\u{2713} HTTP server enabled" ) ;
830+ } else {
831+ println ! ( "\u{2713} HTTP server already enabled" ) ;
832+ }
833+
834+ if cfg. http . api_keys . is_empty ( ) {
835+ let key = engraph:: http:: generate_api_key ( ) ;
836+ cfg. http . api_keys . push ( engraph:: config:: ApiKeyConfig {
837+ key : key. clone ( ) ,
838+ name : "chatgpt" . into ( ) ,
839+ permissions : "read" . into ( ) ,
840+ } ) ;
841+ println ! ( "\u{2713} API key created: {key}" ) ;
842+ println ! ( " Save this \u{2014} you'll need it for ChatGPT Action setup." ) ;
843+ } else {
844+ println ! ( "\u{2713} API key already configured" ) ;
845+ }
846+
847+ let chatgpt_origin = "https://chat.openai.com" . to_string ( ) ;
848+ if !cfg. http . cors_origins . contains ( & chatgpt_origin) {
849+ cfg. http . cors_origins . push ( chatgpt_origin) ;
850+ println ! ( "\u{2713} CORS origin added: https://chat.openai.com" ) ;
851+ } else {
852+ println ! ( "\u{2713} CORS already configured for ChatGPT" ) ;
853+ }
854+
855+ eprint ! ( "\n Public URL (leave empty to skip): " ) ;
856+ io:: stderr ( ) . flush ( ) . ok ( ) ;
857+ let mut url = String :: new ( ) ;
858+ io:: stdin ( ) . lock ( ) . read_line ( & mut url) . ok ( ) ;
859+ let url = url. trim ( ) ;
860+ if !url. is_empty ( ) {
861+ cfg. http . plugin . public_url = Some ( url. to_string ( ) ) ;
862+ println ! ( "\u{2713} Public URL: {url}" ) ;
863+ }
864+
865+ cfg. save ( ) ?;
866+ println ! ( "\n Setup complete. Next steps:" ) ;
867+ println ! ( "1. engraph serve --http" ) ;
868+ println ! (
869+ "2. Expose via tunnel: cloudflared tunnel --url http://localhost:{}" ,
870+ cfg. http. port
871+ ) ;
872+ if !url. is_empty ( ) {
873+ println ! (
874+ "3. ChatGPT \u{2192} Create GPT \u{2192} Add Action \u{2192} Import from: {url}/openapi.json"
875+ ) ;
876+ } else {
877+ println ! ( "3. ChatGPT \u{2192} Create GPT \u{2192} Add Action \u{2192} Import from: <your-tunnel-url>/openapi.json" ) ;
878+ }
879+ println ! ( "4. Auth: API Key, Bearer, paste your key" ) ;
880+ }
881+
819882 cfg. save ( ) ?;
820883 println ! (
821884 "Configuration saved to {}" ,
0 commit comments