@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.
Files changed (41) hide show
  1. package/desktop/src/App.tsx +226 -74
  2. package/desktop/src/BubbleClip.tsx +58 -0
  3. package/desktop/src/PipelineTrack.tsx +19 -0
  4. package/desktop/src/PlatformPane.tsx +98 -0
  5. package/desktop/src/ReplySources.tsx +267 -0
  6. package/desktop/src/ShimmerPhrase.tsx +71 -0
  7. package/desktop/src/SkillsPanel.tsx +0 -7
  8. package/desktop/src/api.ts +24 -1
  9. package/desktop/src/app.css +906 -47
  10. package/desktop/src/clip.test.ts +16 -0
  11. package/desktop/src/clip.ts +26 -0
  12. package/desktop/src/pipeline.test.ts +86 -0
  13. package/desktop/src/pipeline.ts +131 -0
  14. package/desktop/src/platform.test.ts +30 -0
  15. package/desktop/src/platform.ts +76 -0
  16. package/desktop/src/preview-render.test.ts +79 -0
  17. package/desktop/src/preview-render.ts +254 -0
  18. package/desktop/src/queue.test.ts +18 -1
  19. package/desktop/src/queue.ts +8 -0
  20. package/desktop/src/reply-sources.test.ts +73 -0
  21. package/desktop/src/reply-sources.ts +116 -0
  22. package/desktop/src/rich-text.test.ts +26 -0
  23. package/desktop/src/rich-text.ts +51 -2
  24. package/desktop/src/stream.test.ts +41 -2
  25. package/desktop/src/stream.ts +22 -3
  26. package/desktop/src/styles/primitives.css +6 -3
  27. package/desktop/src/thought.test.ts +65 -18
  28. package/desktop/src/thought.ts +41 -11
  29. package/desktop/src/tool-label.test.ts +12 -0
  30. package/desktop/src/tool-label.ts +28 -0
  31. package/package.json +2 -2
  32. package/src/cli/models.ts +3 -1
  33. package/src/cli/openrouter-live.test.ts +29 -0
  34. package/src/cli/openrouter-live.ts +9 -1
  35. package/src/core/events.ts +1 -0
  36. package/src/core/run-turn.ts +7 -0
  37. package/src/core/session.ts +3 -0
  38. package/src/desktop/bridge.test.ts +51 -0
  39. package/src/desktop/bridge.ts +84 -6
  40. package/src/desktop/preview-kind.test.ts +20 -0
  41. package/src/desktop/preview-kind.ts +29 -0
@@ -1,7 +1,13 @@
1
1
  import { randomBytes } from "node:crypto";
2
+ import { readFile, stat } from "node:fs/promises";
3
+ import { isAbsolute, relative, resolve } from "node:path";
2
4
  import { mediaModelLabel } from "../cli/media-models.ts";
3
5
  import { HARNESS_MODELS, modelPickerItems } from "../cli/models.ts";
4
- import { cachedLiveTargetNames, loadLiveTargetNames } from "../cli/openrouter-live.ts";
6
+ import {
7
+ cachedLiveTargetNames,
8
+ loadLiveTargetNames,
9
+ prettyLiveModelName,
10
+ } from "../cli/openrouter-live.ts";
5
11
  import { cachedModalityModels } from "../cli/openrouter-modality.ts";
6
12
  import { sessionPickerItems } from "../cli/picker.ts";
7
13
  import { isHelpAlias } from "../cli/slash.ts";
@@ -45,8 +51,10 @@ import {
45
51
  searchSkillCatalog,
46
52
  skillNameFromCatalogId,
47
53
  } from "../skills/registry.ts";
54
+ import { resolveUnderCwd, toProjectRel } from "../tools/paths.ts";
48
55
  import { openResolvedPath, resolveLocalPath } from "./open-local.ts";
49
56
  import { readPreviewCache, writePreviewCache } from "./preview-cache.ts";
57
+ import { filePreviewKind, filePreviewMime } from "./preview-kind.ts";
50
58
  import { applyStoredOpenRouterKey, maskSecret, writeOpenRouterKey } from "./secrets.ts";
51
59
  import { composeUploadMessage, listUploads, parseIncomingUploads, saveUploads } from "./uploads.ts";
52
60
 
@@ -94,6 +102,23 @@ const CORS_HEADERS = {
94
102
  "access-control-allow-methods": "GET, POST, OPTIONS",
95
103
  };
96
104
 
105
+ function resolvePreviewPath(cwd: string, raw: string): string | undefined {
106
+ const trimmed = raw.trim();
107
+ if (!trimmed) return undefined;
108
+ try {
109
+ const abs =
110
+ !isAbsolute(trimmed) && !trimmed.startsWith("~") && !trimmed.startsWith("file://")
111
+ ? resolveUnderCwd(cwd, trimmed)
112
+ : resolveLocalPath(trimmed, cwd);
113
+ if (!abs) return undefined;
114
+ const rel = relative(resolve(cwd), abs);
115
+ if (rel.startsWith("..") || isAbsolute(rel)) return undefined;
116
+ return abs;
117
+ } catch {
118
+ return undefined;
119
+ }
120
+ }
121
+
97
122
  function modelLabel(id: string): string {
98
123
  return HARNESS_MODELS.find((model) => model.id === id)?.label ?? id;
99
124
  }
@@ -230,17 +255,16 @@ async function readJson(req: Request): Promise<Record<string, unknown>> {
230
255
 
231
256
  function snapshot(harness: HarnessRuntime, busy: boolean, title: string): DesktopState {
232
257
  const live = cachedLiveTargetNames();
233
- const target = live.get(harness.modelId);
258
+ const target = prettyLiveModelName(live.get(harness.modelId) ?? "").trim();
234
259
  const prefs = readMediaPrefs();
260
+ const label = modelLabel(harness.modelId);
235
261
  return {
236
262
  name: harness.config.name,
237
263
  cwd: harness.cwd,
238
264
  mode: harness.mode,
239
265
  modelId: harness.modelId,
240
- modelLabel: modelLabel(harness.modelId),
241
- ...(target && target.toLowerCase() !== modelLabel(harness.modelId).toLowerCase()
242
- ? { modelTarget: target }
243
- : {}),
266
+ modelLabel: label,
267
+ ...(target && target.toLowerCase() !== label.toLowerCase() ? { modelTarget: target } : {}),
244
268
  imageModelId: prefs.imageModel,
245
269
  imageModelLabel: mediaModelLabel(cachedModalityModels("image"), prefs.imageModel),
246
270
  videoModelId: prefs.videoModel,
@@ -512,6 +536,58 @@ export async function startDesktopBridge(options: StartDesktopBridgeOptions): Pr
512
536
  }
513
537
  };
514
538
 
539
+ const route_get_file_preview = async (_req: Request, url: URL): Promise<Response> => {
540
+ const abs = resolvePreviewPath(options.cwd, url.searchParams.get("path") ?? "");
541
+ if (!abs) return json({ error: "File is missing." }, 400);
542
+ try {
543
+ const info = await stat(abs);
544
+ if (!info.isFile()) return json({ error: "Not a file." }, 400);
545
+ const path = toProjectRel(options.cwd, abs);
546
+ const kind = filePreviewKind(abs);
547
+ if (kind === "image") {
548
+ return json({
549
+ path,
550
+ kind,
551
+ mime: filePreviewMime(abs) ?? "application/octet-stream",
552
+ });
553
+ }
554
+ const buf = await readFile(abs);
555
+ if (buf.includes(0)) return json({ error: "Not a text file." }, 400);
556
+ const text = buf.toString("utf8");
557
+ const max = 200_000;
558
+ const truncated = text.length > max;
559
+ return json({
560
+ path,
561
+ kind,
562
+ text: truncated ? `${text.slice(0, max)}\n…` : text,
563
+ truncated,
564
+ });
565
+ } catch (err) {
566
+ return json({ error: errorMessage(err) || "Could not read the file." }, 400);
567
+ }
568
+ };
569
+
570
+ const route_get_file_bytes = async (_req: Request, url: URL): Promise<Response> => {
571
+ const abs = resolvePreviewPath(options.cwd, url.searchParams.get("path") ?? "");
572
+ if (!abs) return json({ error: "File is missing." }, 400);
573
+ if (filePreviewKind(abs) !== "image") return json({ error: "Not an image." }, 400);
574
+ try {
575
+ const info = await stat(abs);
576
+ if (!info.isFile()) return json({ error: "Not a file." }, 400);
577
+ if (info.size > 8_000_000) return json({ error: "Image is too large." }, 400);
578
+ const buf = await readFile(abs);
579
+ return new Response(buf, {
580
+ headers: {
581
+ "content-type": filePreviewMime(abs) ?? "application/octet-stream",
582
+ "cache-control": "private, max-age=60",
583
+ ...CORS_HEADERS,
584
+ },
585
+ });
586
+ } catch (err) {
587
+ return json({ error: errorMessage(err) || "Could not read the file." }, 400);
588
+ }
589
+ };
590
+
515
591
  const route_post_embed = async (req: Request, _url: URL): Promise<Response> => {
516
592
  const body = await readJson(req);
517
593
  const href = publicHttpHref(typeof body.url === "string" ? body.url : "");
@@ -841,6 +917,8 @@ export async function startDesktopBridge(options: StartDesktopBridgeOptions): Pr
841
917
  "POST /skills/remove": route_post_skills_remove,
842
918
  "POST /open": route_post_open,
843
919
  "POST /open-path": route_post_open_path,
920
+ "GET /file-preview": route_get_file_preview,
921
+ "GET /file-bytes": route_get_file_bytes,
844
922
  "POST /embed": route_post_embed,
845
923
  "GET /embed": route_get_embed,
846
924
  "POST /transcribe": route_post_transcribe,
@@ -0,0 +1,20 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { fileExt, filePreviewKind, filePreviewMime } from "./preview-kind.ts";
3
+
4
+ describe("file preview kind", () => {
5
+ test("classifies markdown, html, images, and text", () => {
6
+ expect(filePreviewKind("README.md")).toBe("markdown");
7
+ expect(filePreviewKind("docs/note.markdown")).toBe("markdown");
8
+ expect(filePreviewKind("page.html")).toBe("html");
9
+ expect(filePreviewKind("brand/logo.png")).toBe("image");
10
+ expect(filePreviewKind("shot.JPEG")).toBe("image");
11
+ expect(filePreviewKind("mark.svg")).toBe("image");
12
+ expect(filePreviewKind("src/app.ts")).toBe("text");
13
+ });
14
+
15
+ test("maps image mime types", () => {
16
+ expect(fileExt("a.b.PNG")).toBe("png");
17
+ expect(filePreviewMime("wordmark.png")).toBe("image/png");
18
+ expect(filePreviewMime("note.md")).toBeUndefined();
19
+ });
20
+ });
@@ -0,0 +1,29 @@
1
+ export type FilePreviewKind = "markdown" | "html" | "image" | "text";
2
+
3
+ const IMAGE_MIME: Record<string, string> = {
4
+ png: "image/png",
5
+ jpg: "image/jpeg",
6
+ jpeg: "image/jpeg",
7
+ gif: "image/gif",
8
+ webp: "image/webp",
9
+ svg: "image/svg+xml",
10
+ };
11
+
12
+ export function fileExt(path: string): string {
13
+ const base = path.replaceAll("\\", "/").split("/").pop() ?? path;
14
+ const dot = base.lastIndexOf(".");
15
+ if (dot <= 0) return "";
16
+ return base.slice(dot + 1).toLowerCase();
17
+ }
18
+
19
+ export function filePreviewKind(path: string): FilePreviewKind {
20
+ const ext = fileExt(path);
21
+ if (ext === "md" || ext === "markdown") return "markdown";
22
+ if (ext === "html" || ext === "htm") return "html";
23
+ if (ext in IMAGE_MIME) return "image";
24
+ return "text";
25
+ }
26
+
27
+ export function filePreviewMime(path: string): string | undefined {
28
+ return IMAGE_MIME[fileExt(path)];
29
+ }