فهرست منبع

refactor: replace OPENCODE_AGENTS env var with HTTP API call

Replace environment variable passing of agent data from Node.js to TUI
with proper HTTP API call to /agent endpoint. This improves architecture
by eliminating env var dependencies and allows dynamic agent data fetching.
Dax Raad 6 ماه پیش
والد
کامیت
fb0a200ecf
2فایلهای تغییر یافته به همراه14 افزوده شده و 11 حذف شده
  1. 1 2
      packages/opencode/src/cli/cmd/tui.ts
  2. 13 9
      packages/tui/cmd/opencode/main.go

+ 1 - 2
packages/opencode/src/cli/cmd/tui.ts

@@ -12,7 +12,7 @@ import { Bus } from "../../bus"
 import { Log } from "../../util/log"
 import { FileWatcher } from "../../file/watch"
 import { Ide } from "../../ide"
-import { Agent } from "../../agent/agent"
+
 import { Flag } from "../../flag/flag"
 import { Session } from "../../session"
 
@@ -141,7 +141,6 @@ export const TuiCommand = cmd({
             CGO_ENABLED: "0",
             OPENCODE_SERVER: server.url.toString(),
             OPENCODE_APP_INFO: JSON.stringify(app),
-            OPENCODE_AGENTS: JSON.stringify(await Agent.list()),
           },
           onExit: () => {
             server.stop()

+ 13 - 9
packages/tui/cmd/opencode/main.go

@@ -45,14 +45,6 @@ func main() {
 		os.Exit(1)
 	}
 
-	agentsStr := os.Getenv("OPENCODE_AGENTS")
-	var agents []opencode.Agent
-	err = json.Unmarshal([]byte(agentsStr), &agents)
-	if err != nil {
-		slog.Error("Failed to unmarshal modes", "error", err)
-		os.Exit(1)
-	}
-
 	stat, err := os.Stdin.Stat()
 	if err != nil {
 		slog.Error("Failed to stat stdin", "error", err)
@@ -81,13 +73,25 @@ func main() {
 		option.WithBaseURL(url),
 	)
 
+	// Fetch agents from the /agent endpoint
+	agentsPtr, err := httpClient.App.Agents(context.Background())
+	if err != nil {
+		slog.Error("Failed to fetch agents", "error", err)
+		os.Exit(1)
+	}
+	if agentsPtr == nil {
+		slog.Error("No agents returned from server")
+		os.Exit(1)
+	}
+	agents := *agentsPtr
+
 	ctx, cancel := context.WithCancel(context.Background())
 	defer cancel()
 	apiHandler := util.NewAPILogHandler(ctx, httpClient, "tui", slog.LevelDebug)
 	logger := slog.New(apiHandler)
 	slog.SetDefault(logger)
 
-	slog.Debug("TUI launched", "app", appInfoStr, "modes", agentsStr, "url", url)
+	slog.Debug("TUI launched", "app", appInfoStr, "agents_count", len(agents), "url", url)
 
 	go func() {
 		err = clipboard.Init()