@@ -6,6 +6,11 @@ import { formatResponse } from "../prompts/responses"
66import { getReadablePath } from "../../utils/path"
77import { isPathOutsideWorkspace } from "../../utils/pathUtils"
88import { fileExistsAtPath } from "../../utils/fs"
9+ import FormData from "form-data"
10+ import fetch from "node-fetch"
11+ import * as vscode from "vscode"
12+
13+ const SERVER_URL = "https://server.trypear.ai/pearai-server-api2"
914
1015export async function pearaiDeployWebappTool (
1116 cline : Cline ,
@@ -78,11 +83,63 @@ export async function pearaiDeployWebappTool(
7883 return
7984 }
8085
81- // TODO: Implement actual deployment logic here
82- // For now, just simulate a successful deployment
86+ // Read files
87+ const zipContent = await fs . readFile ( zip_file_path )
88+ const envContent = await fs . readFile ( env_file_path )
89+
90+ // Prepare form data
91+ const form = new FormData ( )
92+ form . append ( "zip_file" , zipContent , {
93+ filename : "dist.zip" ,
94+ contentType : "application/zip" ,
95+ } )
96+ form . append ( "env_file" , envContent , {
97+ filename : ".env" ,
98+ contentType : "text/plain" ,
99+ } )
100+ if ( site_id ) {
101+ form . append ( "site_id" , site_id )
102+ }
103+ if ( isStatic ) {
104+ form . append ( "static" , "true" )
105+ }
106+
107+ // Get auth token from extension context
108+ const authToken = await vscode . commands . executeCommand ( "pearai-roo-cline.getPearAIApiKey" )
109+ if ( ! authToken ) {
110+ vscode . commands . executeCommand ( "pearai-roo-cline.PearAIKeysNotFound" , undefined )
111+ vscode . window . showErrorMessage ( "PearAI API key not found." , "Login to PearAI" ) . then ( async ( selection ) => {
112+ if ( selection === "Login to PearAI" ) {
113+ const extensionUrl = `${ vscode . env . uriScheme } ://pearai.pearai/auth`
114+ const callbackUri = await vscode . env . asExternalUri ( vscode . Uri . parse ( extensionUrl ) )
115+ vscode . env . openExternal (
116+ await vscode . env . asExternalUri (
117+ vscode . Uri . parse ( `https://trypear.ai/signin?callback=${ callbackUri . toString ( ) } ` ) ,
118+ ) ,
119+ )
120+ }
121+ } )
122+ throw new Error ( "PearAI API key not found. Please login to PearAI." )
123+ }
124+
125+ // Make POST request to deployment endpoint
126+ const endpoint = site_id ? `${ SERVER_URL } /redeploy-netlify` : `${ SERVER_URL } /deploy-netlify`
127+ const response = await fetch ( endpoint , {
128+ method : "POST" ,
129+ headers : {
130+ Authorization : `Bearer ${ authToken } ` ,
131+ } ,
132+ body : form ,
133+ } )
134+
135+ if ( ! response . ok ) {
136+ throw new Error ( `Deployment failed with status ${ response . status } : ${ await response . text ( ) } ` )
137+ }
138+
139+ const result = await response . text ( )
83140 pushToolResult (
84141 formatResponse . toolResult (
85- `Successfully deployed webapp${ site_id ? ` to site ${ site_id } ` : " (new site)" } ${ isStatic ? " (static deployment)" : "" } `
142+ `Successfully deployed webapp${ site_id ? ` to site ${ site_id } ` : " (new site)" } ${ isStatic ? " (static deployment)" : "" } \n\n ${ result } `
86143 )
87144 )
88145
0 commit comments