@useavalon/caelence-agent 0.2.2-canary.5 → 0.2.2-canary.7
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 +226 -74
- package/desktop/src/BubbleClip.tsx +58 -0
- package/desktop/src/PipelineTrack.tsx +19 -0
- package/desktop/src/PlatformPane.tsx +98 -0
- package/desktop/src/ReplySources.tsx +267 -0
- package/desktop/src/ShimmerPhrase.tsx +71 -0
- package/desktop/src/SkillsPanel.tsx +0 -7
- package/desktop/src/api.ts +24 -1
- package/desktop/src/app.css +906 -47
- package/desktop/src/clip.test.ts +16 -0
- package/desktop/src/clip.ts +26 -0
- package/desktop/src/pipeline.test.ts +86 -0
- package/desktop/src/pipeline.ts +131 -0
- package/desktop/src/platform.test.ts +30 -0
- package/desktop/src/platform.ts +76 -0
- package/desktop/src/preview-render.test.ts +79 -0
- package/desktop/src/preview-render.ts +254 -0
- package/desktop/src/queue.test.ts +18 -1
- package/desktop/src/queue.ts +8 -0
- package/desktop/src/reply-sources.test.ts +73 -0
- package/desktop/src/reply-sources.ts +116 -0
- package/desktop/src/rich-text.test.ts +26 -0
- package/desktop/src/rich-text.ts +51 -2
- package/desktop/src/stream.test.ts +41 -2
- package/desktop/src/stream.ts +22 -3
- package/desktop/src/styles/primitives.css +6 -3
- package/desktop/src/thought.test.ts +65 -18
- package/desktop/src/thought.ts +41 -11
- package/desktop/src/tool-label.test.ts +12 -0
- package/desktop/src/tool-label.ts +28 -0
- package/package.json +2 -2
- package/src/cli/models.ts +3 -1
- package/src/cli/openrouter-live.test.ts +29 -0
- package/src/cli/openrouter-live.ts +9 -1
- package/src/core/events.ts +1 -0
- package/src/core/run-turn.ts +7 -0
- package/src/core/session.ts +3 -0
- package/src/desktop/bridge.test.ts +51 -0
- package/src/desktop/bridge.ts +84 -6
- package/src/desktop/preview-kind.test.ts +20 -0
- package/src/desktop/preview-kind.ts +29 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { FolderSimpleIcon } from "@phosphor-icons/react/dist/csr/FolderSimple";
|
|
2
|
+
import { XIcon } from "@phosphor-icons/react/dist/csr/X";
|
|
3
|
+
import { type ReactElement, useEffect, useRef, useState } from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
import { type BridgeClient, fileBytesUrl, readFilePreview } from "./api";
|
|
6
|
+
import { renderPreviewHtml, rewritePreviewAssets } from "./preview-render";
|
|
7
|
+
import { type ReplySource, replySourcesForAssistant } from "./reply-sources";
|
|
8
|
+
import { looksLikeWebUrl, webHref } from "./rich-text";
|
|
9
|
+
import type { StreamLine } from "./stream";
|
|
10
|
+
|
|
11
|
+
export function ReplySources(
|
|
12
|
+
props: Readonly<{
|
|
13
|
+
lines: StreamLine[];
|
|
14
|
+
assistantKey: string;
|
|
15
|
+
bridge: BridgeClient | null;
|
|
16
|
+
onOpenUrl?: (url: string) => void;
|
|
17
|
+
onOpenFile?: (path: string, reveal: boolean) => void;
|
|
18
|
+
}>,
|
|
19
|
+
): ReactElement | null {
|
|
20
|
+
const sources = replySourcesForAssistant(props.lines, props.assistantKey);
|
|
21
|
+
const [active, setActive] = useState<ReplySource | null>(null);
|
|
22
|
+
if (sources.length === 0) return null;
|
|
23
|
+
return (
|
|
24
|
+
<>
|
|
25
|
+
<details className="desk-sources">
|
|
26
|
+
<summary>Sources</summary>
|
|
27
|
+
<ul>
|
|
28
|
+
{sources.map((source) => (
|
|
29
|
+
<li key={`${source.kind}:${source.path}`}>
|
|
30
|
+
<SourceItem
|
|
31
|
+
source={source}
|
|
32
|
+
onOpenUrl={props.onOpenUrl}
|
|
33
|
+
onOpenFile={props.onOpenFile}
|
|
34
|
+
onPreview={setActive}
|
|
35
|
+
/>
|
|
36
|
+
</li>
|
|
37
|
+
))}
|
|
38
|
+
</ul>
|
|
39
|
+
</details>
|
|
40
|
+
{active ? (
|
|
41
|
+
<SourcePreviewModal
|
|
42
|
+
source={active}
|
|
43
|
+
bridge={props.bridge}
|
|
44
|
+
onClose={() => setActive(null)}
|
|
45
|
+
onOpenFile={props.onOpenFile}
|
|
46
|
+
onOpenUrl={props.onOpenUrl}
|
|
47
|
+
/>
|
|
48
|
+
) : null}
|
|
49
|
+
</>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function SourceItem(
|
|
54
|
+
props: Readonly<{
|
|
55
|
+
source: ReplySource;
|
|
56
|
+
onOpenUrl?: (url: string) => void;
|
|
57
|
+
onOpenFile?: (path: string, reveal: boolean) => void;
|
|
58
|
+
onPreview: (source: ReplySource) => void;
|
|
59
|
+
}>,
|
|
60
|
+
): ReactElement {
|
|
61
|
+
const { source } = props;
|
|
62
|
+
if (source.kind === "web" || looksLikeWebUrl(source.path)) {
|
|
63
|
+
const href = webHref(source.path);
|
|
64
|
+
return (
|
|
65
|
+
<button type="button" className="desk-sources__name" onClick={() => props.onOpenUrl?.(href)}>
|
|
66
|
+
{source.label}
|
|
67
|
+
</button>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
return (
|
|
71
|
+
<div className="desk-sources__file">
|
|
72
|
+
<button type="button" className="desk-sources__name" onClick={() => props.onPreview(source)}>
|
|
73
|
+
{source.label}
|
|
74
|
+
</button>
|
|
75
|
+
<button
|
|
76
|
+
type="button"
|
|
77
|
+
className="desk-link desk-link--icon"
|
|
78
|
+
aria-label={`Show ${source.label} in folder`}
|
|
79
|
+
onClick={() => props.onOpenFile?.(source.path, true)}
|
|
80
|
+
>
|
|
81
|
+
<FolderSimpleIcon size={14} weight="regular" aria-hidden="true" />
|
|
82
|
+
</button>
|
|
83
|
+
</div>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function SourcePreviewModal(
|
|
88
|
+
props: Readonly<{
|
|
89
|
+
source: ReplySource;
|
|
90
|
+
bridge: BridgeClient | null;
|
|
91
|
+
onClose: () => void;
|
|
92
|
+
onOpenFile?: (path: string, reveal: boolean) => void;
|
|
93
|
+
onOpenUrl?: (url: string) => void;
|
|
94
|
+
}>,
|
|
95
|
+
): ReactElement {
|
|
96
|
+
const onCloseRef = useRef(props.onClose);
|
|
97
|
+
onCloseRef.current = props.onClose;
|
|
98
|
+
const { source, onClose } = props;
|
|
99
|
+
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
const previous = document.body.style.overflow;
|
|
102
|
+
document.body.style.overflow = "hidden";
|
|
103
|
+
const onKey = (event: KeyboardEvent) => {
|
|
104
|
+
if (event.key !== "Escape") return;
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
onCloseRef.current();
|
|
107
|
+
};
|
|
108
|
+
document.addEventListener("keydown", onKey);
|
|
109
|
+
return () => {
|
|
110
|
+
document.body.style.overflow = previous;
|
|
111
|
+
document.removeEventListener("keydown", onKey);
|
|
112
|
+
};
|
|
113
|
+
}, []);
|
|
114
|
+
|
|
115
|
+
return createPortal(
|
|
116
|
+
<div className="desk-source-modal-root">
|
|
117
|
+
<button
|
|
118
|
+
type="button"
|
|
119
|
+
className="desk-source-modal__scrim"
|
|
120
|
+
aria-label="Close preview"
|
|
121
|
+
onClick={onClose}
|
|
122
|
+
/>
|
|
123
|
+
<div
|
|
124
|
+
className="desk-source-modal"
|
|
125
|
+
role="dialog"
|
|
126
|
+
aria-modal="true"
|
|
127
|
+
aria-labelledby="desk-source-modal-title"
|
|
128
|
+
>
|
|
129
|
+
<header className="desk-source-modal__head">
|
|
130
|
+
<h2 id="desk-source-modal-title">{source.label}</h2>
|
|
131
|
+
<button
|
|
132
|
+
type="button"
|
|
133
|
+
className="desk-link desk-link--icon"
|
|
134
|
+
aria-label={`Show ${source.label} in folder`}
|
|
135
|
+
onClick={() => props.onOpenFile?.(source.path, true)}
|
|
136
|
+
>
|
|
137
|
+
<FolderSimpleIcon size={16} weight="regular" />
|
|
138
|
+
</button>
|
|
139
|
+
<button
|
|
140
|
+
type="button"
|
|
141
|
+
className="desk-source-modal__close"
|
|
142
|
+
aria-label="Close preview"
|
|
143
|
+
onClick={onClose}
|
|
144
|
+
>
|
|
145
|
+
<XIcon size={16} weight="regular" />
|
|
146
|
+
</button>
|
|
147
|
+
</header>
|
|
148
|
+
<div className="desk-source-modal__body">
|
|
149
|
+
<FilePreview path={source.path} bridge={props.bridge} onOpenUrl={props.onOpenUrl} />
|
|
150
|
+
</div>
|
|
151
|
+
</div>
|
|
152
|
+
</div>,
|
|
153
|
+
document.body,
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function FilePreview(
|
|
158
|
+
props: Readonly<{
|
|
159
|
+
path: string;
|
|
160
|
+
bridge: BridgeClient | null;
|
|
161
|
+
onOpenUrl?: (url: string) => void;
|
|
162
|
+
}>,
|
|
163
|
+
): ReactElement {
|
|
164
|
+
const [html, setHtml] = useState<string | null>(null);
|
|
165
|
+
const [imageSrc, setImageSrc] = useState<string | null>(null);
|
|
166
|
+
const [text, setText] = useState<string | null>(null);
|
|
167
|
+
const [error, setError] = useState<string | null>(null);
|
|
168
|
+
const [truncated, setTruncated] = useState(false);
|
|
169
|
+
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
const bridge = props.bridge;
|
|
172
|
+
if (!bridge) {
|
|
173
|
+
setError("Preview needs the desktop window.");
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
setHtml(null);
|
|
177
|
+
setImageSrc(null);
|
|
178
|
+
setText(null);
|
|
179
|
+
setError(null);
|
|
180
|
+
setTruncated(false);
|
|
181
|
+
let cancelled = false;
|
|
182
|
+
void (async () => {
|
|
183
|
+
try {
|
|
184
|
+
const result = await readFilePreview(bridge, props.path);
|
|
185
|
+
if (cancelled) return;
|
|
186
|
+
setTruncated(result.truncated === true);
|
|
187
|
+
if (result.kind === "image") {
|
|
188
|
+
setImageSrc(fileBytesUrl(bridge, result.path));
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const raw = result.text ?? "";
|
|
192
|
+
if (result.kind === "markdown" || result.kind === "html") {
|
|
193
|
+
const rendered = rewritePreviewAssets(
|
|
194
|
+
renderPreviewHtml(raw, result.kind),
|
|
195
|
+
result.path,
|
|
196
|
+
(rel) => fileBytesUrl(bridge, rel),
|
|
197
|
+
);
|
|
198
|
+
setHtml(rendered);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
setText(raw);
|
|
202
|
+
} catch (err) {
|
|
203
|
+
if (!cancelled)
|
|
204
|
+
setError(err instanceof Error ? err.message : "Could not preview the file.");
|
|
205
|
+
}
|
|
206
|
+
})();
|
|
207
|
+
return () => {
|
|
208
|
+
cancelled = true;
|
|
209
|
+
};
|
|
210
|
+
}, [props.bridge, props.path]);
|
|
211
|
+
|
|
212
|
+
if (error) return <p className="desk-sources__empty">{error}</p>;
|
|
213
|
+
if (imageSrc) {
|
|
214
|
+
return <img className="desk-source-modal__img" src={imageSrc} alt="" />;
|
|
215
|
+
}
|
|
216
|
+
if (html != null) {
|
|
217
|
+
return (
|
|
218
|
+
<>
|
|
219
|
+
{truncated ? (
|
|
220
|
+
<p className="desk-sources__empty">Showing the first part of the file.</p>
|
|
221
|
+
) : null}
|
|
222
|
+
<RenderedHtml html={html} onOpenUrl={props.onOpenUrl} />
|
|
223
|
+
</>
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
if (text != null) {
|
|
227
|
+
return (
|
|
228
|
+
<>
|
|
229
|
+
{truncated ? (
|
|
230
|
+
<p className="desk-sources__empty">Showing the first part of the file.</p>
|
|
231
|
+
) : null}
|
|
232
|
+
<pre className="cel-code desk-sources__preview">{text}</pre>
|
|
233
|
+
</>
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
return <p className="desk-sources__empty">Loading</p>;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function RenderedHtml(
|
|
240
|
+
props: Readonly<{ html: string; onOpenUrl?: (url: string) => void }>,
|
|
241
|
+
): ReactElement {
|
|
242
|
+
const rootRef = useRef<HTMLDivElement>(null);
|
|
243
|
+
useEffect(() => {
|
|
244
|
+
const root = rootRef.current;
|
|
245
|
+
if (!root) return;
|
|
246
|
+
const onClick = (event: MouseEvent) => {
|
|
247
|
+
const target = event.target;
|
|
248
|
+
if (!(target instanceof HTMLAnchorElement)) return;
|
|
249
|
+
const href = target.getAttribute("href");
|
|
250
|
+
if (!href || href.startsWith("#")) return;
|
|
251
|
+
if (!looksLikeWebUrl(href) && !/^https?:\/\//i.test(href)) return;
|
|
252
|
+
event.preventDefault();
|
|
253
|
+
props.onOpenUrl?.(webHref(href));
|
|
254
|
+
};
|
|
255
|
+
root.addEventListener("click", onClick);
|
|
256
|
+
return () => root.removeEventListener("click", onClick);
|
|
257
|
+
}, [props.html, props.onOpenUrl]);
|
|
258
|
+
return (
|
|
259
|
+
<div
|
|
260
|
+
ref={rootRef}
|
|
261
|
+
className="desk-md"
|
|
262
|
+
// Local project files only. Scripts and handlers are stripped first.
|
|
263
|
+
// biome-ignore lint/security/noDangerouslySetInnerHtml: sanitized local preview
|
|
264
|
+
dangerouslySetInnerHTML={{ __html: props.html }}
|
|
265
|
+
/>
|
|
266
|
+
);
|
|
267
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactElement, useEffect, useRef, useState } from "react";
|
|
2
|
+
|
|
3
|
+
const CYCLE_MS = 2400;
|
|
4
|
+
const SWAP_MS = 320;
|
|
5
|
+
|
|
6
|
+
export function ShimmerPhrase(
|
|
7
|
+
props: Readonly<{ phrases: readonly string[]; live: boolean; tone?: "pipe" }>,
|
|
8
|
+
): ReactElement {
|
|
9
|
+
const phrases = props.phrases.length > 0 ? props.phrases : ["Thinking"];
|
|
10
|
+
const key = phrases.join("\0");
|
|
11
|
+
const phrasesRef = useRef(phrases);
|
|
12
|
+
phrasesRef.current = phrases;
|
|
13
|
+
const [index, setIndex] = useState(0);
|
|
14
|
+
const [outgoing, setOutgoing] = useState<string | null>(null);
|
|
15
|
+
const shown = phrases[index % phrases.length] ?? phrases[0] ?? "Thinking";
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
setIndex(0);
|
|
19
|
+
setOutgoing(null);
|
|
20
|
+
}, [key]);
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!props.live) return;
|
|
24
|
+
const timer = window.setInterval(() => {
|
|
25
|
+
const list = phrasesRef.current;
|
|
26
|
+
if (list.length < 2) return;
|
|
27
|
+
setIndex((current) => {
|
|
28
|
+
setOutgoing(list[current % list.length] ?? null);
|
|
29
|
+
return (current + 1) % list.length;
|
|
30
|
+
});
|
|
31
|
+
}, CYCLE_MS);
|
|
32
|
+
return () => window.clearInterval(timer);
|
|
33
|
+
}, [key, props.live]);
|
|
34
|
+
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (!outgoing) return;
|
|
37
|
+
const timer = window.setTimeout(() => setOutgoing(null), SWAP_MS);
|
|
38
|
+
return () => window.clearTimeout(timer);
|
|
39
|
+
}, [outgoing]);
|
|
40
|
+
|
|
41
|
+
const tone = props.tone === "pipe" ? " desk-shimmer--pipe" : "";
|
|
42
|
+
|
|
43
|
+
if (!props.live) {
|
|
44
|
+
return <span className={`desk-shimmer${tone}`}>{shown}</span>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<span className={`desk-shimmer${tone}`} aria-live="polite">
|
|
49
|
+
{outgoing ? (
|
|
50
|
+
<span className="desk-shimmer__line is-out" aria-hidden="true">
|
|
51
|
+
<ShimmerLetters text={outgoing} />
|
|
52
|
+
</span>
|
|
53
|
+
) : null}
|
|
54
|
+
<span className={`desk-shimmer__line${outgoing ? " is-in" : ""}`}>
|
|
55
|
+
<ShimmerLetters text={shown} />
|
|
56
|
+
</span>
|
|
57
|
+
</span>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function ShimmerLetters(props: Readonly<{ text: string }>): ReactElement {
|
|
62
|
+
return (
|
|
63
|
+
<span className="desk-shimmer__letters">
|
|
64
|
+
{[...props.text].map((letter, index) => (
|
|
65
|
+
<span key={`${index}-${letter}`} style={{ "--i": index } as CSSProperties}>
|
|
66
|
+
{letter === " " ? "\u00a0" : letter}
|
|
67
|
+
</span>
|
|
68
|
+
))}
|
|
69
|
+
</span>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
@@ -343,10 +343,6 @@ export function SkillsPanel(
|
|
|
343
343
|
|
|
344
344
|
return (
|
|
345
345
|
<div className="desk-integrations">
|
|
346
|
-
<p className="desk-integrations-lead">
|
|
347
|
-
Instruction files the agent reads when a task matches. Bundled skills stay off until you add
|
|
348
|
-
them. Disable a project skill to keep it out of the prompt without deleting the file.
|
|
349
|
-
</p>
|
|
350
346
|
<label className="desk-field">
|
|
351
347
|
<span className="visually-hidden">Search skills</span>
|
|
352
348
|
<input
|
|
@@ -379,9 +375,6 @@ export function SkillsPanel(
|
|
|
379
375
|
{searching ? null : (
|
|
380
376
|
<div className="desk-integration-split">
|
|
381
377
|
<p>Bundled</p>
|
|
382
|
-
<em>
|
|
383
|
-
Shipped with Caelence. Off until you add them; they do not start in the prompt.
|
|
384
|
-
</em>
|
|
385
378
|
</div>
|
|
386
379
|
)}
|
|
387
380
|
<SkillList
|
package/desktop/src/api.ts
CHANGED
|
@@ -9,6 +9,7 @@ export type ChatTranscriptLine =
|
|
|
9
9
|
status: "ok" | "fail";
|
|
10
10
|
preview: string;
|
|
11
11
|
error?: string;
|
|
12
|
+
output?: string;
|
|
12
13
|
};
|
|
13
14
|
|
|
14
15
|
export interface DesktopState {
|
|
@@ -81,6 +82,7 @@ export type AgentEvent =
|
|
|
81
82
|
callId: string;
|
|
82
83
|
success: boolean;
|
|
83
84
|
result?: unknown;
|
|
85
|
+
output?: string;
|
|
84
86
|
error?: string;
|
|
85
87
|
}
|
|
86
88
|
| { kind: "approval_request"; callId: string; toolName: string; input: Record<string, unknown> }
|
|
@@ -334,6 +336,24 @@ export function openPath(
|
|
|
334
336
|
});
|
|
335
337
|
}
|
|
336
338
|
|
|
339
|
+
export function readFilePreview(
|
|
340
|
+
bridge: BridgeClient,
|
|
341
|
+
path: string,
|
|
342
|
+
): Promise<{
|
|
343
|
+
path: string;
|
|
344
|
+
kind: "markdown" | "html" | "image" | "text";
|
|
345
|
+
text?: string;
|
|
346
|
+
mime?: string;
|
|
347
|
+
truncated?: boolean;
|
|
348
|
+
}> {
|
|
349
|
+
return request(bridge, `/file-preview?path=${encodeURIComponent(path)}`);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export function fileBytesUrl(bridge: BridgeClient, path: string): string {
|
|
353
|
+
const params = new URLSearchParams({ path, token: bridge.token });
|
|
354
|
+
return `${bridge.url}/file-bytes?${params}`;
|
|
355
|
+
}
|
|
356
|
+
|
|
337
357
|
export async function openLocalFile(
|
|
338
358
|
path: string,
|
|
339
359
|
reveal = false,
|
|
@@ -470,7 +490,9 @@ export async function filesFromDroppedPaths(paths: string[]): Promise<File[]> {
|
|
|
470
490
|
});
|
|
471
491
|
const raw = atob(item.data);
|
|
472
492
|
const bytes = Uint8Array.from(raw, (ch) => ch.codePointAt(0) ?? 0);
|
|
473
|
-
|
|
493
|
+
const file = new File([bytes], item.name, { type: item.mime });
|
|
494
|
+
Object.assign(file, { path: trimmed });
|
|
495
|
+
files.push(file);
|
|
474
496
|
} catch {
|
|
475
497
|
// skip unreadable paths
|
|
476
498
|
}
|
|
@@ -482,6 +504,7 @@ export interface TurnAttachmentPayload {
|
|
|
482
504
|
name: string;
|
|
483
505
|
mime: string;
|
|
484
506
|
data: string;
|
|
507
|
+
sourcePath?: string;
|
|
485
508
|
}
|
|
486
509
|
|
|
487
510
|
export async function startTurn(
|