dbus: add Generate and Route methods

Generate: stateless one-shot LLM call (prompt, system, backend, model)
Route: classify task, return best backend+model from available models

Both delegate to core backend.Generate() and backend.Route().
KDE frontends can use Route as a preprocessing step before CreateSession.
This commit is contained in:
Levi Neely 2026-07-18 17:21:50 +02:00
parent 935c234ce9
commit 8bd59a6509
1 changed files with 38 additions and 0 deletions

38
main.go
View File

@ -1019,6 +1019,32 @@ func (m *SessionManager) restoreSession(ps *agent.PersistedSession) error {
// --- Completion ---
// Generate performs a stateless one-shot LLM generation.
func (m *SessionManager) Generate(prompt, system, backendName, model string) (string, *dbus.Error) {
result, err := backend.Generate(context.Background(), backend.GenerateRequest{
Prompt: prompt,
System: system,
Backend: backendName,
Model: model,
})
if err != nil {
return "", dbus.MakeFailedError(err)
}
return result, nil
}
// Route classifies a task and selects the best available backend+model.
func (m *SessionManager) Route(task, backendName string) (string, *dbus.Error) {
result, err := backend.Route(context.Background(), backend.RouteRequest{
Task: task,
Backend: backendName,
})
if err != nil {
return "", dbus.MakeFailedError(err)
}
return fmt.Sprintf("backend=%s model=%s", result.Backend, result.Model), nil
}
// Complete performs a single-shot code completion using a dedicated copilot session.
// It takes context about the cursor position and returns raw completion text.
func (m *SessionManager) Complete(cwd, filePath, prefix, suffix, extraContext string) (string, *dbus.Error) {
@ -1328,6 +1354,18 @@ const introspectXML = `<node>
<arg name="prompt" type="s" direction="in"/>
<arg name="success" type="b" direction="out"/>
</method>
<method name="Generate">
<arg name="prompt" type="s" direction="in"/>
<arg name="system" type="s" direction="in"/>
<arg name="backend" type="s" direction="in"/>
<arg name="model" type="s" direction="in"/>
<arg name="result" type="s" direction="out"/>
</method>
<method name="Route">
<arg name="task" type="s" direction="in"/>
<arg name="backend" type="s" direction="in"/>
<arg name="result" type="s" direction="out"/>
</method>
<method name="Complete">
<arg name="cwd" type="s" direction="in"/>
<arg name="file" type="s" direction="in"/>