@useavalon/caelence-agent 0.2.3-canary.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/desktop/src/App.tsx +9 -2919
- package/desktop/src/BubbleClip.tsx +1 -1
- package/desktop/src/ComposerAttach.tsx +2 -2
- package/desktop/src/DeskBoot.tsx +28 -0
- package/desktop/src/DeskChrome.tsx +360 -0
- package/desktop/src/DeskComposer.tsx +311 -0
- package/desktop/src/DeskSidebar.tsx +191 -0
- package/desktop/src/FilesPanel.tsx +104 -36
- package/desktop/src/FloatNotice.test.ts +12 -0
- package/desktop/src/FloatNotice.tsx +5 -2
- package/desktop/src/IntegrationsPanel.tsx +273 -0
- package/desktop/src/McpPanel.tsx +8 -8
- package/desktop/src/MemoryPanel.tsx +138 -0
- package/desktop/src/QueuePanel.tsx +123 -0
- package/desktop/src/SessionsPanel.tsx +174 -0
- package/desktop/src/SettingsPanel.tsx +181 -0
- package/desktop/src/SkillsPanel.tsx +28 -12
- package/desktop/src/TranscriptViews.tsx +637 -0
- package/desktop/src/api.ts +36 -0
- package/desktop/src/app.css +159 -11
- package/desktop/src/composer-files.ts +2 -2
- package/desktop/src/desk-keys.ts +45 -0
- package/desktop/src/desk-prefs.ts +29 -0
- package/desktop/src/desk-types.ts +92 -0
- package/desktop/src/desktop-turn.ts +271 -0
- package/desktop/src/queue.ts +1 -1
- package/desktop/src/session-search.test.ts +20 -0
- package/desktop/src/session-search.ts +13 -0
- package/desktop/src/session-select.test.ts +23 -0
- package/desktop/src/session-select.ts +32 -0
- package/desktop/src/useDeskDictation.ts +123 -0
- package/desktop/src/useDeskFiles.ts +180 -0
- package/desktop/src/useDeskNotice.ts +20 -0
- package/desktop/src/useDeskPicker.ts +189 -0
- package/desktop/src/useDeskPrefs.ts +30 -0
- package/desktop/src/useDeskRuntime.ts +109 -0
- package/desktop/src/useDeskSessions.ts +195 -0
- package/desktop/src/useDeskSlash.ts +31 -0
- package/desktop/src/useDeskTurns.ts +264 -0
- package/desktop/src/useDesktopApp.ts +286 -0
- package/desktop/src/user-display.ts +2 -2
- package/package.json +2 -2
- package/src/desktop/bridge.test.ts +13 -0
- package/src/desktop/bridge.ts +45 -19
- package/src/desktop/uploads.test.ts +6 -0
- package/src/desktop/uploads.ts +178 -66
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import type { DesktopState } from "./api";
|
|
3
|
+
import { releaseAttachment } from "./composer-files";
|
|
4
|
+
import { applySlashComposerKey, composerEscapeAction, slashMenuKey } from "./desk-keys";
|
|
5
|
+
import { composerMediaModels } from "./desk-types";
|
|
6
|
+
import type { StreamLine } from "./stream";
|
|
7
|
+
import { useDeskDictation } from "./useDeskDictation";
|
|
8
|
+
import { useDeskFiles } from "./useDeskFiles";
|
|
9
|
+
import { useDeskNotice } from "./useDeskNotice";
|
|
10
|
+
import { useDeskPicker } from "./useDeskPicker";
|
|
11
|
+
import { useDeskPrefs } from "./useDeskPrefs";
|
|
12
|
+
import { useDeskRuntime } from "./useDeskRuntime";
|
|
13
|
+
import { useDeskSessions } from "./useDeskSessions";
|
|
14
|
+
import { useDeskSlash } from "./useDeskSlash";
|
|
15
|
+
import { useDeskTurns } from "./useDeskTurns";
|
|
16
|
+
|
|
17
|
+
export function useDesktopApp() {
|
|
18
|
+
const prefs = useDeskPrefs();
|
|
19
|
+
const notices = useDeskNotice();
|
|
20
|
+
const runtime = useDeskRuntime();
|
|
21
|
+
const viewRef = useRef(runtime.view);
|
|
22
|
+
viewRef.current = runtime.view;
|
|
23
|
+
const transcriptRef = useRef<HTMLDivElement>(null);
|
|
24
|
+
const inputRef = useRef<HTMLTextAreaElement>(null);
|
|
25
|
+
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
26
|
+
const sendingRef = useRef(false);
|
|
27
|
+
const [draft, setDraft] = useState("");
|
|
28
|
+
const [editingUser, setEditingUser] = useState<{
|
|
29
|
+
index: number;
|
|
30
|
+
text: string;
|
|
31
|
+
suffix?: string;
|
|
32
|
+
} | null>(null);
|
|
33
|
+
|
|
34
|
+
const files = useDeskFiles({
|
|
35
|
+
view: runtime.view,
|
|
36
|
+
viewRef,
|
|
37
|
+
showNotice: notices.showNotice,
|
|
38
|
+
noticeError: notices.noticeError,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const dictation = useDeskDictation({
|
|
42
|
+
bridge: runtime.bridge,
|
|
43
|
+
status: runtime.status,
|
|
44
|
+
showNotice: notices.showNotice,
|
|
45
|
+
noticeError: notices.noticeError,
|
|
46
|
+
setDraft,
|
|
47
|
+
inputRef,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const slashOpen =
|
|
51
|
+
runtime.view === "chat" &&
|
|
52
|
+
draft.startsWith("/") &&
|
|
53
|
+
!dictation.listening &&
|
|
54
|
+
runtime.status !== "picker";
|
|
55
|
+
const slash = useDeskSlash({
|
|
56
|
+
bridge: runtime.bridge,
|
|
57
|
+
draft,
|
|
58
|
+
slashOpen,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const pushSystem = useCallback(
|
|
62
|
+
(text: string) => {
|
|
63
|
+
runtime.setLines((prev) => [
|
|
64
|
+
...prev,
|
|
65
|
+
{ key: `sys-${prev.length}-${Date.now()}`, type: "system", text },
|
|
66
|
+
]);
|
|
67
|
+
},
|
|
68
|
+
[runtime.setLines],
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const releaseLinePreviews = useCallback(
|
|
72
|
+
(next: StreamLine[]) => {
|
|
73
|
+
runtime.setLines((prev) => {
|
|
74
|
+
for (const line of prev) {
|
|
75
|
+
if (line.type !== "user") continue;
|
|
76
|
+
for (const item of line.attachments ?? []) releaseAttachment(item);
|
|
77
|
+
}
|
|
78
|
+
return next;
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
[runtime.setLines],
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const picker = useDeskPicker({
|
|
85
|
+
bridge: runtime.bridge,
|
|
86
|
+
state: runtime.state,
|
|
87
|
+
listening: dictation.listening,
|
|
88
|
+
status: runtime.status,
|
|
89
|
+
sendingRef,
|
|
90
|
+
setState: runtime.setState,
|
|
91
|
+
setStatus: runtime.setStatus,
|
|
92
|
+
setLines: runtime.setLines,
|
|
93
|
+
setDraft,
|
|
94
|
+
pushSystem,
|
|
95
|
+
refreshSessions: runtime.refreshSessions,
|
|
96
|
+
noticeError: notices.noticeError,
|
|
97
|
+
inputRef,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const turns = useDeskTurns({
|
|
101
|
+
bridge: runtime.bridge,
|
|
102
|
+
status: runtime.status,
|
|
103
|
+
draft,
|
|
104
|
+
listening: dictation.listening,
|
|
105
|
+
slashOpen,
|
|
106
|
+
slashItems: slash.slashItems,
|
|
107
|
+
slashIndex: slash.slashIndex,
|
|
108
|
+
editingUser,
|
|
109
|
+
pending: runtime.pending,
|
|
110
|
+
setState: runtime.setState,
|
|
111
|
+
setStatus: runtime.setStatus,
|
|
112
|
+
setView: runtime.setView,
|
|
113
|
+
setSkillQuery: runtime.setSkillQuery,
|
|
114
|
+
setDraft,
|
|
115
|
+
setLines: runtime.setLines,
|
|
116
|
+
setPending: runtime.setPending,
|
|
117
|
+
setPicker: picker.setPicker,
|
|
118
|
+
setEditingUser,
|
|
119
|
+
pushSystem,
|
|
120
|
+
refreshSessions: runtime.refreshSessions,
|
|
121
|
+
showNotice: notices.showNotice,
|
|
122
|
+
noticeError: notices.noticeError,
|
|
123
|
+
takeAttachments: files.takeAttachments,
|
|
124
|
+
attachmentsRef: files.attachmentsRef,
|
|
125
|
+
sendingRef,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const sessions = useDeskSessions({
|
|
129
|
+
bridge: runtime.bridge,
|
|
130
|
+
status: runtime.status,
|
|
131
|
+
setState: runtime.setState,
|
|
132
|
+
setView: runtime.setView,
|
|
133
|
+
setEditingUser,
|
|
134
|
+
setQueueSync: turns.setQueueSync,
|
|
135
|
+
releaseLinePreviews,
|
|
136
|
+
noticeError: notices.noticeError,
|
|
137
|
+
refreshSessions: runtime.refreshSessions,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
const node = transcriptRef.current;
|
|
142
|
+
if (node) node.scrollTop = node.scrollHeight;
|
|
143
|
+
}, [runtime.lines, runtime.pending]);
|
|
144
|
+
|
|
145
|
+
useEffect(() => () => dictation.stopRecorder(), [dictation.stopRecorder]);
|
|
146
|
+
|
|
147
|
+
const onKeyDown = useCallback(
|
|
148
|
+
(event: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
|
149
|
+
if (picker.picker) {
|
|
150
|
+
event.preventDefault();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (event.key === "Escape") {
|
|
154
|
+
const action = composerEscapeAction(Boolean(editingUser), runtime.status);
|
|
155
|
+
if (action === "cancel-edit") {
|
|
156
|
+
event.preventDefault();
|
|
157
|
+
setEditingUser(null);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (action === "stop") {
|
|
161
|
+
event.preventDefault();
|
|
162
|
+
void turns.stop();
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const slashKey = slashMenuKey(event.key, slashOpen, slash.slashItems.length);
|
|
167
|
+
if (
|
|
168
|
+
applySlashComposerKey(
|
|
169
|
+
slashKey,
|
|
170
|
+
slash.slashItems,
|
|
171
|
+
slash.slashIndex,
|
|
172
|
+
slash.setSlashIndex,
|
|
173
|
+
setDraft,
|
|
174
|
+
)
|
|
175
|
+
) {
|
|
176
|
+
event.preventDefault();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
180
|
+
event.preventDefault();
|
|
181
|
+
void turns.submit();
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
[
|
|
185
|
+
editingUser,
|
|
186
|
+
picker.picker,
|
|
187
|
+
runtime.status,
|
|
188
|
+
slash.slashIndex,
|
|
189
|
+
slash.slashItems,
|
|
190
|
+
slash.setSlashIndex,
|
|
191
|
+
slashOpen,
|
|
192
|
+
turns.stop,
|
|
193
|
+
turns.submit,
|
|
194
|
+
],
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
return {
|
|
198
|
+
bootError: runtime.bootError,
|
|
199
|
+
state: runtime.state,
|
|
200
|
+
bridge: runtime.bridge,
|
|
201
|
+
sessions: runtime.sessions,
|
|
202
|
+
lines: runtime.lines,
|
|
203
|
+
draft,
|
|
204
|
+
status: runtime.status,
|
|
205
|
+
view: runtime.view,
|
|
206
|
+
skillQuery: runtime.skillQuery,
|
|
207
|
+
theme: prefs.theme,
|
|
208
|
+
sideOpen: prefs.sideOpen,
|
|
209
|
+
mediaOpen: prefs.mediaOpen,
|
|
210
|
+
slashItems: slash.slashItems,
|
|
211
|
+
slashIndex: slash.slashIndex,
|
|
212
|
+
picker: picker.picker,
|
|
213
|
+
sessionMenu: sessions.sessionMenu,
|
|
214
|
+
renamingId: sessions.renamingId,
|
|
215
|
+
renameDraft: sessions.renameDraft,
|
|
216
|
+
pending: runtime.pending,
|
|
217
|
+
listening: dictation.listening,
|
|
218
|
+
queue: turns.queue,
|
|
219
|
+
editingUser,
|
|
220
|
+
editingQueuedId: turns.editingQueuedId,
|
|
221
|
+
queueOpen: turns.queueOpen,
|
|
222
|
+
notice: notices.notice,
|
|
223
|
+
attachments: files.attachments,
|
|
224
|
+
integrations: runtime.integrations,
|
|
225
|
+
fileDrag: files.fileDrag,
|
|
226
|
+
slashOpen,
|
|
227
|
+
transcriptRef,
|
|
228
|
+
inputRef,
|
|
229
|
+
fileInputRef,
|
|
230
|
+
pickerListRef: picker.pickerListRef,
|
|
231
|
+
sessionMenuRef: sessions.sessionMenuRef,
|
|
232
|
+
renameInputRef: sessions.renameInputRef,
|
|
233
|
+
skipRenameBlurRef: sessions.skipRenameBlurRef,
|
|
234
|
+
mediaModels: runtime.state ? composerMediaModels(runtime.state) : [],
|
|
235
|
+
setState: runtime.setState,
|
|
236
|
+
setStatus: runtime.setStatus,
|
|
237
|
+
setView: runtime.setView,
|
|
238
|
+
setSkillQuery: runtime.setSkillQuery,
|
|
239
|
+
setTheme: prefs.setTheme,
|
|
240
|
+
setSideOpen: prefs.setSideOpen,
|
|
241
|
+
setMediaOpen: prefs.setMediaOpen,
|
|
242
|
+
setSlashIndex: slash.setSlashIndex,
|
|
243
|
+
setDraft,
|
|
244
|
+
setRenamingId: sessions.setRenamingId,
|
|
245
|
+
setRenameDraft: sessions.setRenameDraft,
|
|
246
|
+
setEditingUser,
|
|
247
|
+
setEditingQueuedId: turns.setEditingQueuedId,
|
|
248
|
+
setQueueOpen: turns.setQueueOpen,
|
|
249
|
+
setQueueSync: turns.setQueueSync,
|
|
250
|
+
queueRef: turns.queueRef,
|
|
251
|
+
setSessionMenu: sessions.setSessionMenu,
|
|
252
|
+
setPicker: picker.setPicker,
|
|
253
|
+
dismissNotice: notices.dismissNotice,
|
|
254
|
+
showNotice: notices.showNotice,
|
|
255
|
+
noticeError: notices.noticeError,
|
|
256
|
+
addFiles: files.addFiles,
|
|
257
|
+
removeAttachment: files.removeAttachment,
|
|
258
|
+
onFileDragEnter: files.onFileDragEnter,
|
|
259
|
+
onFileDragOver: files.onFileDragOver,
|
|
260
|
+
onFileDragLeave: files.onFileDragLeave,
|
|
261
|
+
onFileDrop: files.onFileDrop,
|
|
262
|
+
sendTurn: turns.sendTurn,
|
|
263
|
+
openComposerPicker: picker.openComposerPicker,
|
|
264
|
+
submit: turns.submit,
|
|
265
|
+
sendQueuedNow: turns.sendQueuedNow,
|
|
266
|
+
stop: turns.stop,
|
|
267
|
+
commitEdit: turns.commitEdit,
|
|
268
|
+
choosePicker: picker.choosePicker,
|
|
269
|
+
cancelPicker: picker.cancelPicker,
|
|
270
|
+
openSession: sessions.openSession,
|
|
271
|
+
newChat: sessions.newChat,
|
|
272
|
+
commitRename: sessions.commitRename,
|
|
273
|
+
removeChat: sessions.removeChat,
|
|
274
|
+
removeChats: sessions.removeChats,
|
|
275
|
+
decide: turns.decide,
|
|
276
|
+
onKeyDown,
|
|
277
|
+
startDictation: dictation.startDictation,
|
|
278
|
+
stopDictation: dictation.stopDictation,
|
|
279
|
+
applySpoken: dictation.applySpoken,
|
|
280
|
+
ingestDropped: files.ingestDropped,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export type DeskReady = Exclude<ReturnType<typeof useDesktopApp>, { state: null }> & {
|
|
285
|
+
state: DesktopState;
|
|
286
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { joinUploadDisplay, parseUploadDisplay } from "../../src/desktop/upload-message
|
|
2
|
-
import { type AttachmentPreview, attachmentKind } from "./composer-files
|
|
1
|
+
import { joinUploadDisplay, parseUploadDisplay } from "../../src/desktop/upload-message";
|
|
2
|
+
import { type AttachmentPreview, attachmentKind } from "./composer-files";
|
|
3
3
|
|
|
4
4
|
export function userBubbleContent(
|
|
5
5
|
text: string,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useavalon/caelence-agent",
|
|
3
|
-
"version": "0.2.3
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Caelence agent: Strands turn loop, local tools, skills, evals, and a themable terminal UI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
],
|
|
40
40
|
"scripts": {
|
|
41
41
|
"start": "bun bin/harness.ts",
|
|
42
|
-
"test": "bun test src/core src/tools src/skills src/evals src/cli src/observability src/desktop src/integrations src/media src/memory src/init.test.ts src/runtime.test.ts desktop/src/rich-text.test.ts desktop/src/stream.test.ts desktop/src/dictation.test.ts desktop/src/thought.test.ts desktop/src/queue.test.ts desktop/src/composer-files.test.ts desktop/src/tool-label.test.ts desktop/src/reply-sources.test.ts desktop/src/pipeline.test.ts desktop/src/preview-render.test.ts",
|
|
42
|
+
"test": "bun test src/core src/tools src/skills src/evals src/cli src/observability src/desktop src/integrations src/media src/memory src/init.test.ts src/runtime.test.ts desktop/src/rich-text.test.ts desktop/src/stream.test.ts desktop/src/dictation.test.ts desktop/src/thought.test.ts desktop/src/queue.test.ts desktop/src/composer-files.test.ts desktop/src/tool-label.test.ts desktop/src/reply-sources.test.ts desktop/src/pipeline.test.ts desktop/src/preview-render.test.ts desktop/src/session-search.test.ts desktop/src/session-select.test.ts",
|
|
43
43
|
"typecheck": "bunx tsc --noEmit -p tsconfig.json",
|
|
44
44
|
"lint": "biome ci .",
|
|
45
45
|
"format": "biome format --write .",
|
|
@@ -460,6 +460,19 @@ describe("desktop bridge", () => {
|
|
|
460
460
|
expect(await readFile(join(ctx.cwd, ".harness", "uploads", file ?? ""), "utf8")).toBe(
|
|
461
461
|
"from the composer",
|
|
462
462
|
);
|
|
463
|
+
const state = (await (
|
|
464
|
+
await fetch(`${ctx.ready.url}/state`, { headers: ctx.headers })
|
|
465
|
+
).json()) as { uploads: Array<{ rel: string }> };
|
|
466
|
+
const rel = state.uploads[0]?.rel ?? "";
|
|
467
|
+
expect(rel).toContain("note.txt");
|
|
468
|
+
const removed = await fetch(`${ctx.ready.url}/uploads/delete`, {
|
|
469
|
+
method: "POST",
|
|
470
|
+
headers: ctx.headers,
|
|
471
|
+
body: JSON.stringify({ rels: [rel] }),
|
|
472
|
+
});
|
|
473
|
+
expect(removed.ok).toBe(true);
|
|
474
|
+
const after = (await removed.json()) as { state: { uploads: unknown[] } };
|
|
475
|
+
expect(after.state.uploads).toEqual([]);
|
|
463
476
|
} finally {
|
|
464
477
|
await ctx.close();
|
|
465
478
|
}
|
package/src/desktop/bridge.ts
CHANGED
|
@@ -58,7 +58,13 @@ import { openResolvedPath, resolveLocalPath } from "./open-local.ts";
|
|
|
58
58
|
import { readPreviewCache, writePreviewCache } from "./preview-cache.ts";
|
|
59
59
|
import { filePreviewKind, filePreviewMime } from "./preview-kind.ts";
|
|
60
60
|
import { applyStoredOpenRouterKey, maskSecret, writeOpenRouterKey } from "./secrets.ts";
|
|
61
|
-
import {
|
|
61
|
+
import {
|
|
62
|
+
composeUploadMessage,
|
|
63
|
+
deleteUploads,
|
|
64
|
+
listUploads,
|
|
65
|
+
parseIncomingUploads,
|
|
66
|
+
saveUploads,
|
|
67
|
+
} from "./uploads.ts";
|
|
62
68
|
|
|
63
69
|
export interface DesktopState {
|
|
64
70
|
name: string;
|
|
@@ -269,6 +275,30 @@ async function readJson(req: Request): Promise<Record<string, unknown>> {
|
|
|
269
275
|
return parsed && typeof parsed === "object" ? (parsed as Record<string, unknown>) : {};
|
|
270
276
|
}
|
|
271
277
|
|
|
278
|
+
function applyApprovalDecision(req: ApprovalRequest, decision: string): boolean {
|
|
279
|
+
if (
|
|
280
|
+
decision === "original" &&
|
|
281
|
+
typeof req.input.originalPath === "string" &&
|
|
282
|
+
req.input.originalPath.trim()
|
|
283
|
+
) {
|
|
284
|
+
req.input.path = req.input.originalPath;
|
|
285
|
+
}
|
|
286
|
+
return (
|
|
287
|
+
decision === "yes" || decision === "always" || decision === "copy" || decision === "original"
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function waitForApproval(
|
|
292
|
+
pending: Map<string, (decision: string) => void>,
|
|
293
|
+
req: ApprovalRequest,
|
|
294
|
+
): Promise<boolean> {
|
|
295
|
+
return new Promise((resolve) => {
|
|
296
|
+
pending.set(req.callId, (decision) => {
|
|
297
|
+
resolve(applyApprovalDecision(req, decision));
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
|
|
272
302
|
function snapshot(harness: HarnessRuntime, busy: boolean, title: string): DesktopState {
|
|
273
303
|
const live = cachedLiveTargetNames();
|
|
274
304
|
const target = prettyLiveModelName(live.get(harness.modelId) ?? "").trim();
|
|
@@ -701,6 +731,18 @@ export async function startDesktopBridge(options: StartDesktopBridgeOptions): Pr
|
|
|
701
731
|
return json({ ok: true, ...memoryPayload(harness) });
|
|
702
732
|
};
|
|
703
733
|
|
|
734
|
+
const route_post_uploads_delete = async (req: Request, _url: URL): Promise<Response> => {
|
|
735
|
+
const body = await readJson(req);
|
|
736
|
+
let rels: string[] = [];
|
|
737
|
+
if (Array.isArray(body.rels)) {
|
|
738
|
+
rels = body.rels.filter((item): item is string => typeof item === "string");
|
|
739
|
+
} else if (typeof body.rel === "string") {
|
|
740
|
+
rels = [body.rel];
|
|
741
|
+
}
|
|
742
|
+
deleteUploads(harness.cwd, rels);
|
|
743
|
+
return json({ ok: true, state: snapshot(harness, busy, title) });
|
|
744
|
+
};
|
|
745
|
+
|
|
704
746
|
const route_get_slash = async (_req: Request, url: URL): Promise<Response> => {
|
|
705
747
|
const { filterSlashCommands } = await import("../cli/slash.ts");
|
|
706
748
|
return json({ items: filterSlashCommands(url.searchParams.get("q") ?? "/") });
|
|
@@ -891,24 +933,7 @@ export async function startDesktopBridge(options: StartDesktopBridgeOptions): Pr
|
|
|
891
933
|
void harness
|
|
892
934
|
.runTurn(message, send, {
|
|
893
935
|
signal: abort?.signal,
|
|
894
|
-
approvalAsk: (req: ApprovalRequest) =>
|
|
895
|
-
new Promise<boolean>((resolve) => {
|
|
896
|
-
pending.set(req.callId, (decision) => {
|
|
897
|
-
if (
|
|
898
|
-
decision === "original" &&
|
|
899
|
-
typeof req.input.originalPath === "string" &&
|
|
900
|
-
req.input.originalPath.trim()
|
|
901
|
-
) {
|
|
902
|
-
req.input.path = req.input.originalPath;
|
|
903
|
-
}
|
|
904
|
-
resolve(
|
|
905
|
-
decision === "yes" ||
|
|
906
|
-
decision === "always" ||
|
|
907
|
-
decision === "copy" ||
|
|
908
|
-
decision === "original",
|
|
909
|
-
);
|
|
910
|
-
});
|
|
911
|
-
}),
|
|
936
|
+
approvalAsk: (req: ApprovalRequest) => waitForApproval(pending, req),
|
|
912
937
|
...(editUserTurn !== undefined ? { editUserTurn } : {}),
|
|
913
938
|
})
|
|
914
939
|
.catch((err) => {
|
|
@@ -968,6 +993,7 @@ export async function startDesktopBridge(options: StartDesktopBridgeOptions): Pr
|
|
|
968
993
|
"POST /transcribe": route_post_transcribe,
|
|
969
994
|
"GET /memory": route_get_memory,
|
|
970
995
|
"POST /memory": route_post_memory,
|
|
996
|
+
"POST /uploads/delete": route_post_uploads_delete,
|
|
971
997
|
"POST /settings": route_post_settings,
|
|
972
998
|
"GET /slash": route_get_slash,
|
|
973
999
|
"POST /session": route_post_session,
|
|
@@ -4,6 +4,7 @@ import { tmpdir } from "node:os";
|
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import {
|
|
6
6
|
composeUploadMessage,
|
|
7
|
+
deleteUploads,
|
|
7
8
|
isTextUpload,
|
|
8
9
|
listUploads,
|
|
9
10
|
matchUploadEdit,
|
|
@@ -58,6 +59,11 @@ describe("uploads", () => {
|
|
|
58
59
|
expect(composeUploadMessage("look", saved)).toContain("```\nhello\n```");
|
|
59
60
|
expect(composeUploadMessage("", saved)).toContain(saved[1]?.rel ?? "");
|
|
60
61
|
expect(listUploads(cwd).map((item) => item.name)).toEqual(["shot.png", "note.txt"]);
|
|
62
|
+
const noteRel = saved[0]?.rel ?? "";
|
|
63
|
+
expect(deleteUploads(cwd, [noteRel, "../secret"]).map((item) => item.name)).toEqual([
|
|
64
|
+
"shot.png",
|
|
65
|
+
]);
|
|
66
|
+
expect(listUploads(cwd).map((item) => item.name)).toEqual(["shot.png"]);
|
|
61
67
|
} finally {
|
|
62
68
|
await rm(cwd, { recursive: true, force: true });
|
|
63
69
|
}
|