Skip to content

Smart contract development editor with AI #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ tasks.json
tasks/
.roo
.taskmasterconfig
scripts
scripts
projects-data-node1
68 changes: 0 additions & 68 deletions .vscode/launch.json

This file was deleted.

57 changes: 55 additions & 2 deletions cmd/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ import (
metricscommon "github.com/chainlaunch/chainlaunch/pkg/metrics/common"
"github.com/chainlaunch/chainlaunch/pkg/monitoring"
nodeTypes "github.com/chainlaunch/chainlaunch/pkg/nodes/types"
"github.com/chainlaunch/chainlaunch/pkg/scai/ai"
"github.com/chainlaunch/chainlaunch/pkg/scai/boilerplates"
"github.com/chainlaunch/chainlaunch/pkg/scai/dirs"
"github.com/chainlaunch/chainlaunch/pkg/scai/files"
"github.com/chainlaunch/chainlaunch/pkg/scai/projectrunner"
"github.com/chainlaunch/chainlaunch/pkg/scai/projects"

"github.com/chainlaunch/chainlaunch/pkg/audit"
"github.com/chainlaunch/chainlaunch/pkg/chainlaunchdeploy"
Expand Down Expand Up @@ -283,7 +289,7 @@ func ensureKeyExists(filename string, dataPath string) (string, error) {
}

// setupServer configures and returns the HTTP server
func setupServer(queries *db.Queries, authService *auth.AuthService, views embed.FS, dev bool, dbPath string, dataPath string) *chi.Mux {
func setupServer(queries *db.Queries, authService *auth.AuthService, views embed.FS, dev bool, dbPath string, dataPath string, projectsDir string) *chi.Mux {
// Initialize services
keyManagementService, err := service.NewKeyManagementService(queries)
if err != nil {
Expand Down Expand Up @@ -488,6 +494,39 @@ func setupServer(queries *db.Queries, authService *auth.AuthService, views embed
notificationHandler := notificationhttp.NewNotificationHandler(notificationService)
authHandler := auth.NewHandler(authService)
auditHandler := audit.NewHandler(auditService, logger)

// AI handlers

openaiKey := os.Getenv("OPENAI_API_KEY")
if openaiKey == "" {
log.Fatal("OPENAI_API_KEY is not set")
}

runner := projectrunner.NewRunner(queries)
projectsService, err := projects.NewProjectsService(queries, runner, projectsDir)
if err != nil {
log.Fatalf("Failed to create projects service: %v", err)
}

chatService := ai.NewChatService(queries)
openAIchatService := ai.NewOpenAIChatService(openaiKey, logger, chatService, queries, projectsDir)

// Register directory, file, and project handlers
dirsService := dirs.NewDirsService(projectsDir)
dirsHandler := dirs.NewDirsHandler(dirsService, projectsService)
filesService := files.NewFilesService()
filesHandler := files.NewFilesHandler(filesService, projectsService)

// Create the project runner and inject into ProjectsService
projectsHandler := projects.NewProjectsHandler(projectsService, projectsDir)

boilerplateService, err := boilerplates.NewBoilerplateService(queries)
if err != nil {
log.Fatalf("Failed to create boilerplate service: %v", err)
}
// Register AI API Gateway routes
aiHandler := ai.NewAIHandler(openAIchatService, chatService, projectsService, boilerplateService)

// Setup router
r := chi.NewRouter()

Expand Down Expand Up @@ -544,6 +583,16 @@ func setupServer(queries *db.Queries, authService *auth.AuthService, views embed

// Register smart contract deployment routes
scHandler.RegisterRoutes(r)

// Mount directory management routes
dirsHandler.RegisterRoutes(r)
// Mount file management routes
filesHandler.RegisterRoutes(r)
// Mount project management routes
projectsHandler.RegisterRoutes(r)
// Mount AI/ML routes
aiHandler.RegisterRoutes(r)

})
})
r.Get("/api/swagger/*", httpSwagger.Handler(
Expand Down Expand Up @@ -609,6 +658,7 @@ type serveCmd struct {
tlsKeyFile string
dataPath string
dev bool
projectsDir string

queries *db.Queries
}
Expand Down Expand Up @@ -756,7 +806,7 @@ func (c *serveCmd) run() error {
}

// Setup and start HTTP server
router := setupServer(c.queries, authService, c.configCMD.Views, c.dev, c.dbPath, c.dataPath)
router := setupServer(c.queries, authService, c.configCMD.Views, c.dev, c.dbPath, c.dataPath, c.projectsDir)

// Start HTTP server in a goroutine
httpServer := &http.Server{
Expand Down Expand Up @@ -822,6 +872,9 @@ For example:
cmd.Flags().StringVar(&serveCmd.tlsCertFile, "tls-cert", "", "Path to TLS certificate file for HTTP server (required)")
cmd.Flags().StringVar(&serveCmd.tlsKeyFile, "tls-key", "", "Path to TLS key file for HTTP server (required)")

// Add projects directory flag
cmd.Flags().StringVar(&serveCmd.projectsDir, "projects", "projects-data", "Path to projects directory")

// Update the default data path to use the OS-specific user config directory
defaultDataPath := ""
if configDir, err := os.UserConfigDir(); err == nil {
Expand Down
Loading
Loading