Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(workbench): start agent turn from canvas + honor default backend

cyh2b86e0eea831
diff --git a/tests/test_ui_session_stream.py b/tests/test_ui_session_stream.py
index fc997ed29..5207582a0 100644
--- a/tests/test_ui_session_stream.py
+++ b/tests/test_ui_session_stream.py
@@ -154,6 +154,40 @@ def test_non_stream_route_unchanged(isolated_state, tmp_path):
assert payload["text"] == "no stream"
+def test_create_session_defaults_backend_to_config(isolated_state, tmp_path):
+ """POST /api/sessions with no ``agent_backend`` falls back to the
+ configured ``agents.default_backend`` instead of erroring or pinning
+ a hard-coded backend. This is what the Workbench canvas relies on so a
+ plain "new chat" routes through the user's configured default.
+ """
+
+ from core.services import settings as settings_service
+ from storage import projects_service
+ from storage.db import create_sqlite_engine
+ from vibe.runtime import default_config
+ from vibe.ui_server import app
+
+ engine = create_sqlite_engine()
+ with engine.begin() as conn:
+ project = projects_service.create_project(conn, folder_path=str(tmp_path))
+
+ # Seed a config on disk (the UI server's bare load_config() requires the
+ # file to exist) and read back the default the route should fall back to.
+ expected_backend = settings_service.load_config(
+ default_factory=default_config
+ ).agents.default_backend
+
+ client = app.test_client()
+ headers = csrf_headers(client)
+ response = client.post(
+ "/api/sessions",
+ json={"project_id": project["id"]},
+ headers=headers,
+ )
+ assert response.status_code == 201
+ assert response.get_json()["agent_backend"] == expected_backend
+
+
def test_cancel_route_proxies_to_internal_socket(isolated_state, tmp_path):
_, session_id = _make_session(tmp_path)
diff --git a/ui/src/components/Workbench.tsx b/ui/src/components/Workbench.tsx
index d79c21dad..0262481b1 100644
--- a/ui/src/components/Workbench.tsx
+++ b/ui/src/components/Workbench.tsx
@@ -61,18 +61,16 @@ export const Workbench: React.FC = () => {
setSending(true);
setError(null);
try {
- const session = await api.createSession({
- project_id: targetProject.id,
- agent_backend: 'claude',
+ // Omit agent_backend so the server routes the new chat through the
+ // configured agents.default_backend rather than a hard-coded one.
+ const session = await api.createSession({ project_id: targetProject.id });
+ // Hand the typed message to ChatPage as router state. ChatPage replays
+ // it through its own streaming compose path (POST ?stream=1), so the
+ // agent turn actually starts and the reply streams in — instead of
+ // persisting a user message here that no dispatch would ever pick up.
+ navigate(`/chat/${encodeURIComponent(session.id)}`, {
+ state: { initialMessage: text },
});
- // Seed the chat with the user's initial message; the agent picks
- // it up via the same dispatch path as the Chat-page compose.
- try {
- await api.sendSessionMessage(session.id, { text });
- } catch (err) {
- console.error('[workbench-canvas] seed message failed', err);
- }
- navigate(`/chat/${encodeURIComponent(session.id)}`);
} catch (err: any) {
setError(err?.message ?? String(err));
setSending(false);
diff --git a/ui/src/components/workbench/ChatPage.tsx b/ui/src/components/workbench/ChatPage.tsx
index 16297868a..7264a2d8b 100644
--- a/ui/src/components/workbench/ChatPage.tsx
+++ b/ui/src/components/workbench/ChatPage.tsx
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
-import { useNavigate, useParams } from 'react-router-dom';
+import { useLocation, useNavigate, useParams } from 'react-router-dom';
import { ArrowLeft, Bot, ChevronDown, Loader2, MessageSquare, Pencil, Send, StopCircle } from 'lucide-react';
import clsx from 'clsx';
@@ -30,6 +30,7 @@ export const ChatPage: React.FC = () => {
const { sessionId } = useParams<{ sessionId: string }>();
const { t } = useTranslation();
const navigate = useNavigate();
+ const location = useLocation();
const api = useApi();
const [session, setSession] = useState<WorkbenchSession | null>(null);
const [agents, setAgents] = useState<VibeAgentBrief[]>([]);
@@ -39,6 +40,9 @@ export const ChatPage: React.FC = () => {
const [streamChunks, setStreamChunks] = useState<PendingChunk[]>([]);
const [composing, setComposing] = useState(false);
+ // Guards the one-shot replay of a message handed off from the Workbench
+ // canvas (see the initial-message effect below).
+ const initialMessageSentRef = useRef(false);
const refresh = useCallback(async () => {
if (!sessionId) return;
@@ -168,6 +172,19 @@ export const ChatPage: React.FC = () => {
refresh();
}, [refresh]);
+ // The Workbench canvas creates the session and hands its first message
+ // over as router state. Replay it once through the streaming compose path
+ // so the agent turn actually starts. Clear the state afterwards so a manual
+ // page refresh (which preserves history state) doesn't resend it.
+ useEffect(() => {
+ const initialMessage = (location.state as { initialMessage?: string } | null)?.initialMessage;
+ if (!initialMessage || initialMessageSentRef.current) return;
+ if (loading || !session) return;
+ initialMessageSentRef.current = true;
+ navigate(location.pathname, { replace: true, state: null });
+ void sendMessage(initialMessage);
+ }, [location.state, location.pathname, loading, session, navigate, sendMessage]);
+
const patch = useCallback(
async (changes: Partial<WorkbenchSession>) => {
if (!session) return;
diff --git a/ui/src/context/ApiContext.tsx b/ui/src/context/ApiContext.tsx
index c39557133..787211df5 100644
--- a/ui/src/context/ApiContext.tsx
+++ b/ui/src/context/ApiContext.tsx
@@ -168,7 +168,8 @@ export type WorkbenchSession = {
export type WorkbenchSessionCreate = {
project_id: string;
- agent_backend: string;
+ // Optional: when omitted the server falls back to agents.default_backend.
+ agent_backend?: string;
agent_id?: string;
agent_name?: string;
agent_variant?: string;
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index 7ab9c7d22..5eb732c6e 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -2469,7 +2469,13 @@ def sessions_create():
if not project_id:
return jsonify({"error": "project_id is required"}), 400
if not agent_backend:
- return jsonify({"error": "agent_backend is required"}), 400
+ # Honor the configured global default (agents.default_backend) when the
+ # caller doesn't pin a backend. A plain "new chat" from the Workbench
+ # canvas should route through whatever the user configured (OpenCode by
+ # default), not a hard-coded backend.
+ from core.services import settings as settings_service
+
+ agent_backend = settings_service.load_config().agents.default_backend
scope_id = _project_to_scope_id(project_id)
engine = _projects_engine()