Skip to content

Commit 998f5f0

Browse files
committed
(veggie) refactor lib/agent/runtime/handlers over several sessions
1 parent 08bb707 commit 998f5f0

File tree

25 files changed

+382
-683
lines changed

25 files changed

+382
-683
lines changed

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ This is all we are working on currently.
3232

3333
- **ADK + VS Code Coding Agent**
3434
- lib/agent/... (core runtime in Go using ADK)
35+
- lib/agent/config/... (CUE-based configuration for agents, tools, and environments)
3536
- extensions/vscode/
3637
- extension/... (core extension)
3738
- webviews/... (webview components)

lib/agent/cmd/chat_subops.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/hofstadter-io/hof/cmd/hof/flags"
1010
"github.com/hofstadter-io/hof/lib/agent/runtime/handlers/common"
11+
"github.com/hofstadter-io/hof/lib/consts"
1112
"github.com/hofstadter-io/hof/lib/yagu"
1213
"github.com/olekukonko/tablewriter"
1314
)
@@ -33,7 +34,7 @@ func ChatList(args []string, rflags flags.RootPflagpole, aflags flags.AgentPflag
3334

3435
// these loops need to be switched
3536
// REALLY, we need a third list to calc intermediate rows with comparable data
36-
sessions, err := common.SessionList(R, AR)
37+
sessions, err := common.SessionList(R.Ctx, AR, consts.VEG_DEFAULT_USER)
3738
rows := make([][]string, 0, len(sessions))
3839
for _, s := range sessions {
3940
id := s.ID()

lib/agent/cmd/runtime.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ func prepRuntime(args []string, rflags flags.RootPflagpole) (*runtime.Runtime, *
4747
return nil, nil, err
4848
}
4949

50-
ar, err := aruntime.NewRuntime(
51-
r.DB,
52-
r.Envs,
53-
r.Agentics,
54-
)
50+
ar, err := aruntime.NewRuntime(r)
5551
if err != nil {
5652
return nil, nil, fmt.Errorf("failed to create agent runtime: %v", err)
5753
}

lib/agent/cmd/tui/list.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
tea "github.com/charmbracelet/bubbletea"
1414
"github.com/charmbracelet/lipgloss"
1515
"github.com/hofstadter-io/hof/lib/agent/runtime/handlers/common"
16+
"github.com/hofstadter-io/hof/lib/consts"
1617
"google.golang.org/adk/session"
1718
)
1819

@@ -287,7 +288,7 @@ func (m *listModel) updateRows() {
287288
}
288289

289290
func (m *listModel) updateSessions() error {
290-
sessions, err := common.SessionList(m.root.R, m.root.AR)
291+
sessions, err := common.SessionList(m.root.R.Ctx, m.root.AR, consts.VEG_DEFAULT_USER)
291292
if err != nil {
292293
return err
293294
}

lib/agent/cmd/tui/root.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type Model struct {
6262
currSid string
6363
currSessTitle string
6464
session session.Session
65-
asession *aruntime.Session
65+
asession *common.Session
6666
}
6767

6868
var views = []string{"list", "chat", "info"}
@@ -331,7 +331,7 @@ func (m *Model) currDims() {
331331
func (m *Model) createSession() error {
332332
m.clearSession()
333333

334-
session, err := common.SessionCreate(m.R, m.AR, common.CreatePayload{
334+
session, err := common.SessionCreate(m.R.Ctx, m.AR, common.CreatePayload{
335335
User: consts.VEG_DEFAULT_USER,
336336
Agent: "veggie",
337337
Model: "gemini-3-flash",
@@ -346,7 +346,7 @@ func (m *Model) createSession() error {
346346
}
347347

348348
func (m *Model) loadSession(sid string) error {
349-
session, err := common.SessionGet(m.R, m.AR, sid)
349+
session, err := common.SessionGet(m.R.Ctx, m.AR, consts.VEG_DEFAULT_USER, sid)
350350
if err != nil {
351351
m.err = err
352352
return err
@@ -372,7 +372,7 @@ func (m *Model) sendMessage(text string) error {
372372
}
373373

374374
func (m *Model) delSession(sid string) error {
375-
err := common.SessionDel(m.R, m.AR, sid)
375+
err := common.SessionDel(m.R.Ctx, m.AR, consts.VEG_DEFAULT_USER, sid)
376376
if err != nil {
377377
m.err = err
378378
return err

lib/agent/runtime/handlers/api/env.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package api
33
import (
44
"net/http"
55

6-
"github.com/hofstadter-io/hof/lib/agent/services/environ"
6+
"github.com/hofstadter-io/hof/lib/agent/runtime/handlers/common"
77
"github.com/labstack/echo/v4"
88
)
99

1010
func envList(c echo.Context) error {
11-
envs, err := environ.Client().ListEnvirons()
11+
envs, err := common.ListEnvirons()
1212
if err != nil {
1313
// fmt.Println("error:", err)
1414
return c.String(http.StatusBadRequest, err.Error())

lib/agent/runtime/handlers/api/runtime.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package api
22

33
import (
4+
"fmt"
5+
46
"github.com/labstack/echo/v4"
7+
"google.golang.org/adk/artifact"
8+
"google.golang.org/adk/model"
59
"google.golang.org/adk/session"
610

711
"github.com/hofstadter-io/hof/lib/agent/config"
12+
"github.com/hofstadter-io/hof/lib/agent/runtime/handlers/common"
813
)
914

1015
type Runtime struct {
@@ -13,6 +18,34 @@ type Runtime struct {
1318
Agentic *config.Config
1419
}
1520

21+
func (r *Runtime) GetAppName() string {
22+
return r.AppName
23+
}
24+
25+
func (r *Runtime) GetSessionService() session.Service {
26+
return r.S
27+
}
28+
29+
func (r *Runtime) GetAgenticConfig() *config.Config {
30+
return r.Agentic
31+
}
32+
33+
func (r *Runtime) GetArtifactService() artifact.Service {
34+
return nil
35+
}
36+
37+
func (r *Runtime) GetModels() map[string]model.LLM {
38+
return nil
39+
}
40+
41+
func (r *Runtime) ReadEnvConfig() error {
42+
return fmt.Errorf("ReadEnvConfig not implemented for api.Runtime")
43+
}
44+
45+
func (r *Runtime) SetSession(s *common.Session) {
46+
// api doesn't track active sessions this way
47+
}
48+
1649
func Setup(appName string, e *echo.Echo, s session.Service, a *config.Config) (*Runtime, error) {
1750
r := &Runtime{
1851
AppName: appName,
@@ -36,8 +69,15 @@ func Setup(appName string, e *echo.Echo, s session.Service, a *config.Config) (*
3669
e.POST("/env/list", envList)
3770
e.POST("/prompt/render", r.promptRender)
3871

72+
e.POST("/session/list", r.sessionList)
73+
e.POST("/session/get", r.sessionGet)
74+
e.POST("/session/create", r.sessionCreate)
75+
e.POST("/session/delete", r.sessionDelete)
3976
e.POST("/session/clone", r.sessionClone)
4077
e.POST("/session/splice", r.sessionSplice)
78+
e.POST("/session/state/get", r.sessionStateGet)
79+
e.POST("/session/state/put", r.sessionStatePut)
80+
e.POST("/session/state/del", r.sessionStateDel)
4181

4282
return r, nil
4383
}

0 commit comments

Comments
 (0)