mirror of
https://github.com/aljazceru/opencode.git
synced 2026-01-10 11:24:59 +01:00
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.
This commit is contained in:
@@ -12,7 +12,7 @@ import { Bus } from "../../bus"
|
|||||||
import { Log } from "../../util/log"
|
import { Log } from "../../util/log"
|
||||||
import { FileWatcher } from "../../file/watch"
|
import { FileWatcher } from "../../file/watch"
|
||||||
import { Ide } from "../../ide"
|
import { Ide } from "../../ide"
|
||||||
import { Agent } from "../../agent/agent"
|
|
||||||
import { Flag } from "../../flag/flag"
|
import { Flag } from "../../flag/flag"
|
||||||
import { Session } from "../../session"
|
import { Session } from "../../session"
|
||||||
|
|
||||||
@@ -141,7 +141,6 @@ export const TuiCommand = cmd({
|
|||||||
CGO_ENABLED: "0",
|
CGO_ENABLED: "0",
|
||||||
OPENCODE_SERVER: server.url.toString(),
|
OPENCODE_SERVER: server.url.toString(),
|
||||||
OPENCODE_APP_INFO: JSON.stringify(app),
|
OPENCODE_APP_INFO: JSON.stringify(app),
|
||||||
OPENCODE_AGENTS: JSON.stringify(await Agent.list()),
|
|
||||||
},
|
},
|
||||||
onExit: () => {
|
onExit: () => {
|
||||||
server.stop()
|
server.stop()
|
||||||
|
|||||||
@@ -45,14 +45,6 @@ func main() {
|
|||||||
os.Exit(1)
|
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()
|
stat, err := os.Stdin.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("Failed to stat stdin", "error", err)
|
slog.Error("Failed to stat stdin", "error", err)
|
||||||
@@ -81,13 +73,25 @@ func main() {
|
|||||||
option.WithBaseURL(url),
|
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())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
apiHandler := util.NewAPILogHandler(ctx, httpClient, "tui", slog.LevelDebug)
|
apiHandler := util.NewAPILogHandler(ctx, httpClient, "tui", slog.LevelDebug)
|
||||||
logger := slog.New(apiHandler)
|
logger := slog.New(apiHandler)
|
||||||
slog.SetDefault(logger)
|
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() {
|
go func() {
|
||||||
err = clipboard.Init()
|
err = clipboard.Init()
|
||||||
|
|||||||
Reference in New Issue
Block a user