Skip to content

Commit 8cbf488

Browse files
committed
(human) move veg agent db location; move helper to bottom of file
1 parent aec5ac5 commit 8cbf488

File tree

6 files changed

+133
-94
lines changed

6 files changed

+133
-94
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ require (
7272
golang.org/x/sync v0.18.0
7373
golang.org/x/term v0.37.0
7474
golang.org/x/text v0.31.0
75-
google.golang.org/adk v0.1.1-0.20251119080121-e0c09d1636bb
76-
google.golang.org/genai v1.36.0
75+
google.golang.org/adk v0.3.0
76+
google.golang.org/genai v1.40.0
7777
google.golang.org/protobuf v1.36.10
7878
gopkg.in/errgo.v2 v2.1.0
7979
gopkg.in/inconshreveable/log15.v2 v2.16.0

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ cuelang.org/go v0.15.3 h1:JKR/lZVwuIGlLTGIaJ0jONz9+CK3UDx06sQ6DDxNkaE=
1111
cuelang.org/go v0.15.3/go.mod h1:NYw6n4akZcTjA7QQwJ1/gqWrrhsN4aZwhcAL0jv9rZE=
1212
cyphar.com/go-pathrs v0.2.1 h1:9nx1vOgwVvX1mNBWDu93+vaceedpbsDqo+XuBGL40b8=
1313
cyphar.com/go-pathrs v0.2.1/go.mod h1:y8f1EMG7r+hCuFf/rXsKqMJrJAUoADZGNh5/vZPKcGc=
14-
dagger.io/dagger v0.19.9 h1:JoLrmoaPQmxbTmGv1Rs6dMOHn69aYjZi2Bddnxo3u1I=
15-
dagger.io/dagger v0.19.9/go.mod h1:BjAJWl4Lx7XRW7nooNjBi0ZAC5Ici2pkthkdBIZdbTI=
1614
dagger.io/dagger v0.19.10 h1:farO4CggSoWCId92QeZWKpP5mY9YwsVhNYuUzpqsKqw=
1715
dagger.io/dagger v0.19.10/go.mod h1:BjAJWl4Lx7XRW7nooNjBi0ZAC5Ici2pkthkdBIZdbTI=
1816
dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
@@ -887,8 +885,8 @@ google.golang.org/api v0.252.0 h1:xfKJeAJaMwb8OC9fesr369rjciQ704AjU/psjkKURSI=
887885
google.golang.org/api v0.252.0/go.mod h1:dnHOv81x5RAmumZ7BWLShB/u7JZNeyalImxHmtTHxqw=
888886
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
889887
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
890-
google.golang.org/genai v1.36.0 h1:sJCIjqTAmwrtAIaemtTiKkg2TO1RxnYEusTmEQ3nGxM=
891-
google.golang.org/genai v1.36.0/go.mod h1:A3kkl0nyBjyFlNjgxIwKq70julKbIxpSxqKO5gw/gmk=
888+
google.golang.org/genai v1.40.0 h1:kYxyQSH+vsib8dvsgyLJzsVEIv5k3ZmHJyVqdvGncmc=
889+
google.golang.org/genai v1.40.0/go.mod h1:A3kkl0nyBjyFlNjgxIwKq70julKbIxpSxqKO5gw/gmk=
892890
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
893891
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
894892
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=

lib/agent/runtime/handlers/ws/chat.go

Lines changed: 86 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -19,97 +19,17 @@ import (
1919
)
2020

2121
type ChatPayload struct {
22-
Text string `json:"text"`
23-
Sid string `json:"sid"`
24-
Agent string `json:"agent"`
25-
Model string `json:"model"`
22+
Text string `json:"text"`
23+
Sid string `json:"sid"`
24+
Agent string `json:"agent"`
25+
Model string `json:"model"`
26+
Environ string `json:"environ"`
2627
}
2728

2829
type ChatResponsePayload struct {
2930
ResponseText string `json:"responseText"`
3031
}
3132

32-
func sessionCancel(r *runtime.Runtime, c *runtime.Client, m *runtime.Message) {
33-
var p SidRequest
34-
if err := json.Unmarshal(m.Payload, &p); err != nil {
35-
log.Printf("Error unmarshaling 'session.cancel' payload: %v", err)
36-
return
37-
}
38-
39-
s, ok := r.GetSession(p.Sid)
40-
if !ok && s == nil {
41-
c.Mail("session.cancel.error", map[string]string{
42-
"sid": p.Sid,
43-
"error": "unknown sid",
44-
})
45-
return
46-
}
47-
48-
fmt.Println("cancelling:", p.Sid)
49-
50-
s.StopFunc()
51-
c.Mail("session.cancel.resp", map[string]string{
52-
"sid": p.Sid,
53-
})
54-
55-
// lookup session
56-
resp, err := r.S.Get(r.Ctx, &session.GetRequest{
57-
AppName: r.AppName,
58-
UserID: c.User,
59-
SessionID: p.Sid,
60-
})
61-
if err != nil {
62-
// log.Printf("session.get: %v", err)
63-
c.Mail("session.cancel.error", map[string]string{
64-
"sid": p.Sid,
65-
"error": err.Error(),
66-
})
67-
return
68-
}
69-
agent, err := resp.Session.State().Get("agent")
70-
if err != nil {
71-
// log.Printf("session.get: %v", err)
72-
c.Mail("session.cancel.error", map[string]string{
73-
"sid": p.Sid,
74-
"error": err.Error(),
75-
})
76-
return
77-
}
78-
79-
cEvt := &session.Event{
80-
LLMResponse: model.LLMResponse{
81-
FinishReason: "OTHER",
82-
TurnComplete: true,
83-
Interrupted: true,
84-
},
85-
Author: agent.(string),
86-
ID: uuid.NewString(),
87-
InvocationID: uuid.NewString(),
88-
Timestamp: time.Now().UTC(),
89-
Actions: session.EventActions{
90-
StateDelta: map[string]any{
91-
"canceled": true,
92-
},
93-
},
94-
}
95-
fmt.Println("saving:", p.Sid, cEvt)
96-
// "create" (put) the session (by using the same Sid)
97-
err = r.S.AppendEvent(r.Ctx, resp.Session, cEvt)
98-
99-
if err != nil {
100-
// log.Printf("session.get: %v", err)
101-
c.Mail("session.cancel.error", map[string]string{
102-
"sid": p.Sid,
103-
"error": err.Error(),
104-
})
105-
return
106-
}
107-
108-
c.Mail("session.cancel.resp", map[string]string{
109-
"sid": p.Sid,
110-
})
111-
}
112-
11333
func chatUserMessage(r *runtime.Runtime, c *runtime.Client, m *runtime.Message) {
11434

11535
var p ChatPayload
@@ -234,3 +154,84 @@ func chatUserMessage(r *runtime.Runtime, c *runtime.Client, m *runtime.Message)
234154
}
235155

236156
}
157+
158+
func sessionCancel(r *runtime.Runtime, c *runtime.Client, m *runtime.Message) {
159+
var p SidRequest
160+
if err := json.Unmarshal(m.Payload, &p); err != nil {
161+
log.Printf("Error unmarshaling 'session.cancel' payload: %v", err)
162+
return
163+
}
164+
165+
s, ok := r.GetSession(p.Sid)
166+
if !ok && s == nil {
167+
c.Mail("session.cancel.error", map[string]string{
168+
"sid": p.Sid,
169+
"error": "unknown sid",
170+
})
171+
return
172+
}
173+
174+
fmt.Println("cancelling:", p.Sid)
175+
176+
s.StopFunc()
177+
c.Mail("session.cancel.resp", map[string]string{
178+
"sid": p.Sid,
179+
})
180+
181+
// lookup session
182+
resp, err := r.S.Get(r.Ctx, &session.GetRequest{
183+
AppName: r.AppName,
184+
UserID: c.User,
185+
SessionID: p.Sid,
186+
})
187+
if err != nil {
188+
// log.Printf("session.get: %v", err)
189+
c.Mail("session.cancel.error", map[string]string{
190+
"sid": p.Sid,
191+
"error": err.Error(),
192+
})
193+
return
194+
}
195+
agent, err := resp.Session.State().Get("agent")
196+
if err != nil {
197+
// log.Printf("session.get: %v", err)
198+
c.Mail("session.cancel.error", map[string]string{
199+
"sid": p.Sid,
200+
"error": err.Error(),
201+
})
202+
return
203+
}
204+
205+
cEvt := &session.Event{
206+
LLMResponse: model.LLMResponse{
207+
FinishReason: "OTHER",
208+
TurnComplete: true,
209+
Interrupted: true,
210+
},
211+
Author: agent.(string),
212+
ID: uuid.NewString(),
213+
InvocationID: uuid.NewString(),
214+
Timestamp: time.Now().UTC(),
215+
Actions: session.EventActions{
216+
StateDelta: map[string]any{
217+
"canceled": true,
218+
},
219+
},
220+
}
221+
fmt.Println("saving:", p.Sid, cEvt)
222+
// "create" (put) the session (by using the same Sid)
223+
err = r.S.AppendEvent(r.Ctx, resp.Session, cEvt)
224+
225+
if err != nil {
226+
// log.Printf("session.get: %v", err)
227+
c.Mail("session.cancel.error", map[string]string{
228+
"sid": p.Sid,
229+
"error": err.Error(),
230+
})
231+
return
232+
}
233+
234+
c.Mail("session.cancel.resp", map[string]string{
235+
"sid": p.Sid,
236+
})
237+
}

lib/agent/runtime/runtime.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ import (
2929
const CONFIG_PATH = `.veg`
3030
const DATA_PATH = `.veg/data`
3131

32+
const VEG_SYS_DATA_DIR_VAR = "VEG_SYS_DATA_DIR"
33+
const VEG_USER_DATA_DIR_VAR = "VEG_USER_DATA_DIR"
34+
const VEG_SYS_DATA_DIR_DEFAULT = "/var/lib/veg/data"
35+
36+
var VEG_SYS_DATA_DIR string
37+
var VEG_USER_DATA_DIR string
38+
3239
type Runtime struct {
3340
AppName string
3441

@@ -96,6 +103,20 @@ func (r *Runtime) handleMessage(c *Client, m *Message) {
96103
}
97104

98105
func (R *Runtime) init() (err error) {
106+
VEG_SYS_DATA_DIR = os.Getenv(VEG_SYS_DATA_DIR_VAR)
107+
if VEG_SYS_DATA_DIR == "" {
108+
VEG_SYS_DATA_DIR = VEG_SYS_DATA_DIR_VAR
109+
}
110+
111+
VEG_USER_DATA_DIR = os.Getenv(VEG_USER_DATA_DIR_VAR)
112+
if VEG_USER_DATA_DIR == "" {
113+
configDir, err := os.UserConfigDir()
114+
if err != nil {
115+
return err
116+
}
117+
VEG_USER_DATA_DIR = filepath.Join(configDir, "veg", "data")
118+
}
119+
99120
err = R.ReadConfig()
100121
if err != nil {
101122
return fmt.Errorf("while reading config: %w", err)
@@ -178,8 +199,12 @@ func (R *Runtime) initModels() (err error) {
178199
}
179200

180201
func (R *Runtime) initServices() error {
202+
203+
// VEG|RENAME: make this a multi-tier lookup and unify system
204+
// generally for all the subsystems
205+
181206
// open comms to the db
182-
dia := sqlite.Open(filepath.Join(DATA_PATH, "veg.db"))
207+
dia := sqlite.Open(filepath.Join(VEG_USER_DATA_DIR, "veg.db"))
183208
db, err := gorm.Open(dia, &gorm.Config{})
184209
if err != nil {
185210
return fmt.Errorf("error creating database session service: %w", err)

lib/env/cmd/infra.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func ensureRegistry() error {
7676
if err != nil {
7777
return err
7878
}
79-
registryData = filepath.Join(cacheDir, "veg", "registry")
79+
registryData = filepath.Join(cacheDir, "veg", "data", "registry")
8080
}
8181

8282
params := &container.Params{
@@ -147,7 +147,7 @@ func ensureDagger() error {
147147
Restart: "always",
148148
Privileged: true,
149149
Volume: []string{
150-
"veg-dagger-engine:/var/lib/dagger",
150+
"/var/lib/dagger",
151151
fmt.Sprintf("%s:/etc/dagger/engine.json", enginePath),
152152
},
153153
AddHost: []string{"host.docker.internal:host-gateway"},

notes/rename.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# RENAME|REWRITE hof -> veg
2+
3+
also moving to verdverm account
4+
5+
6+
## rewrite
7+
8+
- dynamic gen'd from CUE cli, shouldn't need to recompile, available to users too
9+
- more minimal CI, veg <user-cmd> should work, probably other env/flow like commands too
10+
- include config in this dynamic system, make it work with multi-tier coming up, this system should be WATCHED
11+
- consolidate core subsystems: veg's, libs, runtime, args/flags
12+
- build multi-tier lookup / unify
13+
- more contextual awareness, especially as it relates to commands being invoked via vscode/remote/rest/websocket
14+
- offline mode, if have remote settings and not connecting, create local db/reg, sync when connected again later
15+
- or have this system also aware and multi-db/reg capable

0 commit comments

Comments
 (0)