|
9 | 9 | "path/filepath" |
10 | 10 | "syscall" |
11 | 11 |
|
| 12 | + "github.com/hackertron/Yantra/internal/gateway" |
12 | 13 | "github.com/hackertron/Yantra/internal/memory" |
13 | 14 | "github.com/hackertron/Yantra/internal/provider" |
14 | 15 | "github.com/hackertron/Yantra/internal/runtime" |
@@ -307,7 +308,63 @@ func runTUI(cmd *cobra.Command, args []string) error { |
307 | 308 | } |
308 | 309 |
|
309 | 310 | func runServe(cmd *cobra.Command, args []string) error { |
310 | | - fmt.Println("Starting Yantra API server...") |
311 | | - // TODO: implement API server |
312 | | - return fmt.Errorf("not yet implemented") |
| 311 | + ctx := cmd.Context() |
| 312 | + logger := slog.Default() |
| 313 | + |
| 314 | + cfg, err := types.LoadConfig(configPath) |
| 315 | + if err != nil { |
| 316 | + return fmt.Errorf("loading config: %w", err) |
| 317 | + } |
| 318 | + |
| 319 | + p, err := provider.BuildFromConfig(cfg) |
| 320 | + if err != nil { |
| 321 | + return fmt.Errorf("building provider: %w", err) |
| 322 | + } |
| 323 | + p = provider.NewReliable(p, provider.DefaultReliableConfig()) |
| 324 | + |
| 325 | + absWorkspace, err := filepath.Abs(".") |
| 326 | + if err != nil { |
| 327 | + return fmt.Errorf("resolving workspace: %w", err) |
| 328 | + } |
| 329 | + |
| 330 | + // Set up memory if enabled. |
| 331 | + var mem types.MemoryRetrieval |
| 332 | + var memDB *memory.DB |
| 333 | + var sessStore types.SessionStore |
| 334 | + |
| 335 | + if cfg.Memory.Enabled { |
| 336 | + dbPath := cfg.Memory.DBPath |
| 337 | + if dbPath == "" { |
| 338 | + dbPath = ".yantra/memory.db" |
| 339 | + } |
| 340 | + if !filepath.IsAbs(dbPath) { |
| 341 | + dbPath = filepath.Join(absWorkspace, dbPath) |
| 342 | + } |
| 343 | + |
| 344 | + memDB, err = memory.OpenDB(dbPath) |
| 345 | + if err != nil { |
| 346 | + slog.Warn("failed to open memory DB, continuing without memory", "error", err) |
| 347 | + } else { |
| 348 | + embedder, err := memory.NewEmbeddingBackend(cfg.Memory) |
| 349 | + if err != nil { |
| 350 | + slog.Warn("failed to create embedding backend, continuing without embeddings", "error", err) |
| 351 | + } |
| 352 | + mem = memory.NewStore(memDB, embedder, cfg.Memory.Retrieval) |
| 353 | + sessStore = memory.NewSessionStore(memDB) |
| 354 | + } |
| 355 | + } |
| 356 | + if memDB != nil { |
| 357 | + defer memDB.Close() |
| 358 | + } |
| 359 | + |
| 360 | + policy := tool.NewWorkspacePolicy(cfg.Tools.Shell) |
| 361 | + reg := tool.NewRegistry(policy) |
| 362 | + if err := tool.RegisterBuiltins(reg, cfg.Tools, mem); err != nil { |
| 363 | + return fmt.Errorf("registering tools: %w", err) |
| 364 | + } |
| 365 | + |
| 366 | + srv := gateway.NewServer(cfg.Gateway, cfg, p, reg, mem, sessStore, absWorkspace, logger) |
| 367 | + |
| 368 | + logger.Info("starting Yantra API server", "listen", cfg.Gateway.Listen) |
| 369 | + return srv.ListenAndServe(ctx) |
313 | 370 | } |
0 commit comments