dbus: add GetPlan, SetPlan, GetSystemPrompt, GetContextSize, GetPreviousPrompt, Compact, ClearContext
Closes remaining feature gaps vs 9p interface.
This commit is contained in:
parent
d907aa53f4
commit
e1ce5df53c
127
main.go
127
main.go
|
|
@ -33,14 +33,16 @@ const (
|
||||||
|
|
||||||
// managedSession wraps a Core with its context and metadata.
|
// managedSession wraps a Core with its context and metadata.
|
||||||
type managedSession struct {
|
type managedSession struct {
|
||||||
core agent.Core
|
core agent.Core
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
id string
|
id string
|
||||||
agent string
|
agent string
|
||||||
log []byte
|
log []byte
|
||||||
logMu sync.Mutex
|
logMu sync.Mutex
|
||||||
peers map[string]bool
|
peers map[string]bool
|
||||||
|
plan string
|
||||||
|
prevPrompt string
|
||||||
}
|
}
|
||||||
|
|
||||||
// chatEmitter batches ChatUpdated D-Bus signals to avoid flooding the bus.
|
// chatEmitter batches ChatUpdated D-Bus signals to avoid flooding the bus.
|
||||||
|
|
@ -369,6 +371,7 @@ func (m *SessionManager) Submit(sessionID, prompt string) (bool, *dbus.Error) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sess.prevPrompt = prompt
|
||||||
go sess.core.Submit(sess.ctx, prompt)
|
go sess.core.Submit(sess.ctx, prompt)
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
@ -519,6 +522,85 @@ func (m *SessionManager) GetContext(sessionID string) (string, *dbus.Error) {
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- Plan/scratchpad ---
|
||||||
|
|
||||||
|
func (m *SessionManager) GetPlan(sessionID string) (string, *dbus.Error) {
|
||||||
|
m.mu.RLock()
|
||||||
|
sess, ok := m.sessions[sessionID]
|
||||||
|
m.mu.RUnlock()
|
||||||
|
if !ok {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
return sess.plan, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SessionManager) SetPlan(sessionID, plan string) (bool, *dbus.Error) {
|
||||||
|
m.mu.RLock()
|
||||||
|
sess, ok := m.sessions[sessionID]
|
||||||
|
m.mu.RUnlock()
|
||||||
|
if !ok {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
sess.plan = plan
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- System prompt / context size / previous prompt ---
|
||||||
|
|
||||||
|
func (m *SessionManager) GetSystemPrompt(sessionID string) (string, *dbus.Error) {
|
||||||
|
m.mu.RLock()
|
||||||
|
sess, ok := m.sessions[sessionID]
|
||||||
|
m.mu.RUnlock()
|
||||||
|
if !ok {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
return sess.core.SystemPrompt(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SessionManager) GetContextSize(sessionID string) (string, *dbus.Error) {
|
||||||
|
m.mu.RLock()
|
||||||
|
sess, ok := m.sessions[sessionID]
|
||||||
|
m.mu.RUnlock()
|
||||||
|
if !ok {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
return sess.core.CtxSz(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SessionManager) GetPreviousPrompt(sessionID string) (string, *dbus.Error) {
|
||||||
|
m.mu.RLock()
|
||||||
|
sess, ok := m.sessions[sessionID]
|
||||||
|
m.mu.RUnlock()
|
||||||
|
if !ok {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
return sess.prevPrompt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Compact / Clear ---
|
||||||
|
|
||||||
|
func (m *SessionManager) Compact(sessionID string) (bool, *dbus.Error) {
|
||||||
|
m.mu.RLock()
|
||||||
|
sess, ok := m.sessions[sessionID]
|
||||||
|
m.mu.RUnlock()
|
||||||
|
if !ok {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
sess.core.Submit(sess.ctx, "/compact")
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SessionManager) ClearContext(sessionID string) (bool, *dbus.Error) {
|
||||||
|
m.mu.RLock()
|
||||||
|
sess, ok := m.sessions[sessionID]
|
||||||
|
m.mu.RUnlock()
|
||||||
|
if !ok {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
sess.core.Submit(sess.ctx, "/clear")
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
// --- Backends/models/agents ---
|
// --- Backends/models/agents ---
|
||||||
|
|
||||||
func (m *SessionManager) ListBackends() ([]string, *dbus.Error) {
|
func (m *SessionManager) ListBackends() ([]string, *dbus.Error) {
|
||||||
|
|
@ -1356,6 +1438,35 @@ const introspectXML = `<node>
|
||||||
<arg name="prompt" type="s" direction="in"/>
|
<arg name="prompt" type="s" direction="in"/>
|
||||||
<arg name="success" type="b" direction="out"/>
|
<arg name="success" type="b" direction="out"/>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="GetPlan">
|
||||||
|
<arg name="session_id" type="s" direction="in"/>
|
||||||
|
<arg name="plan" type="s" direction="out"/>
|
||||||
|
</method>
|
||||||
|
<method name="SetPlan">
|
||||||
|
<arg name="session_id" type="s" direction="in"/>
|
||||||
|
<arg name="plan" type="s" direction="in"/>
|
||||||
|
<arg name="success" type="b" direction="out"/>
|
||||||
|
</method>
|
||||||
|
<method name="GetSystemPrompt">
|
||||||
|
<arg name="session_id" type="s" direction="in"/>
|
||||||
|
<arg name="result" type="s" direction="out"/>
|
||||||
|
</method>
|
||||||
|
<method name="GetContextSize">
|
||||||
|
<arg name="session_id" type="s" direction="in"/>
|
||||||
|
<arg name="result" type="s" direction="out"/>
|
||||||
|
</method>
|
||||||
|
<method name="GetPreviousPrompt">
|
||||||
|
<arg name="session_id" type="s" direction="in"/>
|
||||||
|
<arg name="result" type="s" direction="out"/>
|
||||||
|
</method>
|
||||||
|
<method name="Compact">
|
||||||
|
<arg name="session_id" type="s" direction="in"/>
|
||||||
|
<arg name="success" type="b" direction="out"/>
|
||||||
|
</method>
|
||||||
|
<method name="ClearContext">
|
||||||
|
<arg name="session_id" type="s" direction="in"/>
|
||||||
|
<arg name="success" type="b" direction="out"/>
|
||||||
|
</method>
|
||||||
<method name="Generate">
|
<method name="Generate">
|
||||||
<arg name="prompt" type="s" direction="in"/>
|
<arg name="prompt" type="s" direction="in"/>
|
||||||
<arg name="system" type="s" direction="in"/>
|
<arg name="system" type="s" direction="in"/>
|
||||||
|
|
|
||||||
Reference in New Issue