Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/client/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,24 @@ export function App() {
setBusy(false);
}
};

const deleteConversation = async (id: string) => {
const conversation = workspace?.conversations.find(
(item) => item.id === id,
);
if (
!conversation ||
!window.confirm(`Delete “${conversation.title}”? This cannot be undone.`)
)
return;
if (!(await mutate(`/conversations/${encodeURIComponent(id)}`, 'DELETE')))
return;
if (selectedThread === id) {
const next = workspace?.conversations.find((item) => item.id !== id);
setSelectedThread(next?.id);
}
};

if (needsAuth)
return (
<main className="unlock">
Expand Down Expand Up @@ -465,6 +483,7 @@ export function App() {
setMobile(false);
}}
onNew={() => void newConversation()}
onDelete={(id) => void deleteConversation(id)}
/>
) : (
<div className="sidebar-empty">
Expand Down
35 changes: 25 additions & 10 deletions src/client/ThreadList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useThreads } from '@copilotkit/react-core/v2';
import { MessageCircle, Plus } from 'lucide-react';
import { MessageCircle, Plus, Trash2 } from 'lucide-react';
import type { Conversation, Dot } from '../shared/types';
export function ThreadList({
dots,
Expand All @@ -8,13 +8,15 @@ export function ThreadList({
selected,
onSelect,
onNew,
onDelete,
}: {
dots: Dot[];
dotId: string;
local: Conversation[];
selected?: string;
onSelect: (id: string) => void;
onNew: () => void;
onDelete: (id: string) => void;
}) {
const threads = useThreads({
agentId: dotId,
Expand Down Expand Up @@ -42,17 +44,30 @@ export function ThreadList({
{local.map((thread) => {
const remote = threads.threads.find((item) => item.id === thread.id);
return (
<button
<div
key={thread.id}
className={`nav-item ${selected === thread.id ? 'active' : ''}`}
onClick={() => onSelect(thread.id)}
className={`nav-item thread-row ${selected === thread.id ? 'active' : ''}`}
>
<MessageCircle size={15} />
<span className="thread-summary">
<span>{remote?.name || thread.title}</span>
<small>{dots.find((dot) => dot.id === thread.dotId)?.name}</small>
</span>
</button>
<button
className="thread-select"
onClick={() => onSelect(thread.id)}
>
<MessageCircle size={15} />
<span className="thread-summary">
<span>{remote?.name || thread.title}</span>
<small>
{dots.find((dot) => dot.id === thread.dotId)?.name}
</small>
</span>
</button>
<button
className="icon-button thread-delete"
aria-label={`Delete ${remote?.name || thread.title}`}
onClick={() => onDelete(thread.id)}
>
<Trash2 size={13} />
</button>
</div>
);
})}
{!local.length && (
Expand Down
23 changes: 23 additions & 0 deletions src/client/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1976,6 +1976,29 @@ h3 {
padding: 9px 12px;
font-size: 10px;
}
.thread-row {
display: flex;
align-items: center;
gap: 4px;
}
.thread-select {
display: flex;
align-items: center;
gap: 9px;
flex: 1;
min-width: 0;
color: inherit;
background: transparent;
border: 0;
text-align: left;
}
.thread-delete {
opacity: 0;
}
.thread-row:hover .thread-delete,
.thread-row:focus-within .thread-delete {
opacity: 1;
}
.thread-list .nav-item > span {
overflow: hidden;
text-overflow: ellipsis;
Expand Down
12 changes: 12 additions & 0 deletions src/server/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ export class Platform {
.join('\n')
.slice(-12000);
}

async deleteConversation(threadId: string) {
this.requireReady();
const thread = this.workspace.requireThread(threadId);
await this.intelligence!.deleteThread({
threadId,
userId: this.workspace.ownerId,
agentId: thread.dotId,
});
this.workspace.deleteThread(threadId);
}

async handle(request: Request): Promise<Response> {
if (!this.handler)
return Response.json(
Expand Down
6 changes: 6 additions & 0 deletions src/server/workspace-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ export function workspaceRoutes(platform: Platform, voice: VoiceService) {
201,
);
});

app.delete('/conversations/:id', async (c) => {
await platform.deleteConversation(c.req.param('id'));
return c.json({ ok: true });
});

app.get('/conversations/:id/capture', (c) =>
c.json(platform.workspace.capture(c.req.param('id'))),
);
Expand Down
25 changes: 25 additions & 0 deletions src/server/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,31 @@ export class WorkspaceStore {
throw new Error('Conversation does not belong to this Dot and owner.');
return thread;
}

deleteThread(id: string) {
this.requireThread(id);
this.db.exec('BEGIN');
try {
for (const [table, column] of [
['task_threads', 'threadId'],
['calls', 'threadId'],
['captures', 'threadId'],
['page_reviews', 'threadId'],
['page_threads', 'threadId'],
['mcp_approvals', 'threadId'],
['mcp_actions', 'threadId'],
])
this.db.prepare(`DELETE FROM ${table} WHERE ${column}=?`).run(id);
this.db
.prepare('DELETE FROM thread_bindings WHERE id=? AND ownerId=?')
.run(id, this.ownerId);
this.db.exec('COMMIT');
} catch (error) {
this.db.exec('ROLLBACK');
throw error;
}
}

bindTask(taskId: string, threadId: string) {
this.requireThread(threadId);
this.db
Expand Down
15 changes: 15 additions & 0 deletions tests/workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ it('rejects a dot in a nonexistent space and does not rebind an existing thread'
store.close();
});

it('deletes a thread binding and all thread-specific local records', () => {
const store = new WorkspaceStore(':memory:', 'owner');
const dot = store.dots()[0];
store.bindThread('deleted', dot.id, 'Delete me');
const call = store.createCall('deleted');
store.saveCapture('deleted', { value: true });
store.deleteThread('deleted');

expect(store.conversations()).toHaveLength(0);
expect(() => store.requireThread('deleted')).toThrow();
expect(() => store.call(call.id)).toThrow();
expect(() => store.capture('deleted')).toThrow();
store.close();
});

it('migrates legacy Space ownership once and never restores revoked access on restart', () => {
const dir = mkdtempSync(join(tmpdir(), 'opendots-access-'));
const path = join(dir, 'workspace.sqlite');
Expand Down