mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-15 09:01:17 +00:00
refactor: create session on + click, remove session input
This commit is contained in:
parent
bc943af447
commit
b489e9d30d
2 changed files with 27 additions and 49 deletions
|
|
@ -539,41 +539,10 @@
|
||||||
color: var(--muted);
|
color: var(--muted);
|
||||||
}
|
}
|
||||||
|
|
||||||
.session-input {
|
.session-id-display {
|
||||||
font-family: ui-monospace, SFMono-Regular, 'SF Mono', Consolas, monospace;
|
font-family: ui-monospace, SFMono-Regular, 'SF Mono', Consolas, monospace;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: var(--text);
|
color: var(--text-secondary);
|
||||||
background: var(--surface);
|
|
||||||
border: 1px solid var(--border-2);
|
|
||||||
padding: 4px 10px;
|
|
||||||
border-radius: 4px;
|
|
||||||
outline: none;
|
|
||||||
width: 140px;
|
|
||||||
transition: border-color var(--transition);
|
|
||||||
}
|
|
||||||
|
|
||||||
.session-input:focus {
|
|
||||||
border-color: var(--accent);
|
|
||||||
}
|
|
||||||
|
|
||||||
.session-input::placeholder {
|
|
||||||
color: var(--muted-2);
|
|
||||||
}
|
|
||||||
|
|
||||||
.session-new-btn {
|
|
||||||
background: var(--accent);
|
|
||||||
border: none;
|
|
||||||
border-radius: 4px;
|
|
||||||
padding: 4px 10px;
|
|
||||||
font-size: 11px;
|
|
||||||
font-weight: 600;
|
|
||||||
color: #fff;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: background var(--transition);
|
|
||||||
}
|
|
||||||
|
|
||||||
.session-new-btn:hover {
|
|
||||||
background: var(--accent-hover);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.messages-container {
|
.messages-container {
|
||||||
|
|
|
||||||
|
|
@ -424,13 +424,34 @@ export default function App() {
|
||||||
setSessionError(null);
|
setSessionError(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateSessionId = () => {
|
const createNewSession = async () => {
|
||||||
const chars = "abcdefghijklmnopqrstuvwxyz0123456789";
|
const chars = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||||
let id = "session-";
|
let id = "session-";
|
||||||
for (let i = 0; i < 8; i++) {
|
for (let i = 0; i < 8; i++) {
|
||||||
id += chars[Math.floor(Math.random() * chars.length)];
|
id += chars[Math.floor(Math.random() * chars.length)];
|
||||||
}
|
}
|
||||||
setSessionId(id);
|
setSessionId(id);
|
||||||
|
setEvents([]);
|
||||||
|
setOffset(0);
|
||||||
|
offsetRef.current = 0;
|
||||||
|
setSessionError(null);
|
||||||
|
|
||||||
|
// Create the session
|
||||||
|
try {
|
||||||
|
const body: Record<string, string> = { agent: agentId };
|
||||||
|
if (agentMode) body.agentMode = agentMode;
|
||||||
|
if (permissionMode) body.permissionMode = permissionMode;
|
||||||
|
if (model) body.model = model;
|
||||||
|
if (variant) body.variant = variant;
|
||||||
|
|
||||||
|
await apiFetch(`${API_PREFIX}/sessions/${id}`, {
|
||||||
|
method: "POST",
|
||||||
|
body
|
||||||
|
});
|
||||||
|
await fetchSessions();
|
||||||
|
} catch (error) {
|
||||||
|
setSessionError(error instanceof Error ? error.message : "Unable to create session");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const appendEvents = useCallback((incoming: UniversalEvent[]) => {
|
const appendEvents = useCallback((incoming: UniversalEvent[]) => {
|
||||||
|
|
@ -774,8 +795,8 @@ export default function App() {
|
||||||
<span className="sidebar-title">Sessions</span>
|
<span className="sidebar-title">Sessions</span>
|
||||||
<button
|
<button
|
||||||
className="sidebar-add-btn"
|
className="sidebar-add-btn"
|
||||||
onClick={generateSessionId}
|
onClick={createNewSession}
|
||||||
title="New session ID"
|
title="New session"
|
||||||
>
|
>
|
||||||
<Plus size={14} />
|
<Plus size={14} />
|
||||||
</button>
|
</button>
|
||||||
|
|
@ -818,19 +839,7 @@ export default function App() {
|
||||||
<div className="panel-header-left">
|
<div className="panel-header-left">
|
||||||
<MessageSquare className="button-icon" />
|
<MessageSquare className="button-icon" />
|
||||||
<span className="panel-title">Session</span>
|
<span className="panel-title">Session</span>
|
||||||
<input
|
<span className="session-id-display">{sessionId}</span>
|
||||||
className="session-input"
|
|
||||||
value={sessionId}
|
|
||||||
onChange={(e) => setSessionId(e.target.value)}
|
|
||||||
placeholder="session-id"
|
|
||||||
/>
|
|
||||||
<button
|
|
||||||
className="session-new-btn"
|
|
||||||
onClick={createSession}
|
|
||||||
title="Create new session"
|
|
||||||
>
|
|
||||||
New
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
{polling && (
|
{polling && (
|
||||||
<span className="pill accent">Live</span>
|
<span className="pill accent">Live</span>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue