@useavalon/caelence-agent 0.2.0 → 0.2.1-canary.1
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/README.md +8 -5
- package/desktop/README.md +26 -0
- package/desktop/bun.lock +321 -0
- package/desktop/index.html +20 -0
- package/desktop/package.json +28 -0
- package/desktop/scripts/make-icons.ts +105 -0
- package/desktop/scripts/run-tauri.ts +40 -0
- package/desktop/src/App.tsx +2657 -0
- package/desktop/src/ComposerAttach.tsx +111 -0
- package/desktop/src/FloatNotice.test.ts +23 -0
- package/desktop/src/FloatNotice.tsx +30 -0
- package/desktop/src/LogoMark.tsx +37 -0
- package/desktop/src/SkillsPanel.tsx +409 -0
- package/desktop/src/api.ts +503 -0
- package/desktop/src/app.css +1749 -0
- package/desktop/src/composer-files.test.ts +46 -0
- package/desktop/src/composer-files.ts +135 -0
- package/desktop/src/dictation.test.ts +22 -0
- package/desktop/src/dictation.ts +59 -0
- package/desktop/src/integration-search.test.ts +13 -0
- package/desktop/src/integration-search.ts +8 -0
- package/desktop/src/main.tsx +43 -0
- package/desktop/src/picker-nav.test.ts +27 -0
- package/desktop/src/picker-nav.ts +26 -0
- package/desktop/src/queue.test.ts +37 -0
- package/desktop/src/queue.ts +40 -0
- package/desktop/src/rich-text.test.ts +85 -0
- package/desktop/src/rich-text.ts +193 -0
- package/desktop/src/session-menu.test.ts +19 -0
- package/desktop/src/session-menu.ts +12 -0
- package/desktop/src/skill-search.test.ts +37 -0
- package/desktop/src/skill-search.ts +25 -0
- package/desktop/src/stream.test.ts +93 -0
- package/desktop/src/stream.ts +197 -0
- package/desktop/src/styles/fonts/chivo-mono-latin-ext-wght-normal.woff2 +0 -0
- package/desktop/src/styles/fonts/chivo-mono-latin-wght-normal.ttf +0 -0
- package/desktop/src/styles/fonts/chivo-mono-latin-wght-normal.woff2 +0 -0
- package/desktop/src/styles/fonts/instrument-sans-latin-ext-wght-normal.woff2 +0 -0
- package/desktop/src/styles/fonts/instrument-sans-latin-wght-normal.ttf +0 -0
- package/desktop/src/styles/fonts/instrument-sans-latin-wght-normal.woff2 +0 -0
- package/desktop/src/styles/fonts.css +53 -0
- package/desktop/src/styles/primitives.css +600 -0
- package/desktop/src/styles/tokens-matte.css +354 -0
- package/desktop/src/thought.test.ts +96 -0
- package/desktop/src/thought.ts +87 -0
- package/desktop/src/tool-label.test.ts +17 -0
- package/desktop/src/tool-label.ts +70 -0
- package/desktop/src/vite-env.d.ts +15 -0
- package/desktop/src-tauri/Cargo.lock +4791 -0
- package/desktop/src-tauri/Cargo.toml +21 -0
- package/desktop/src-tauri/Entitlements.plist +8 -0
- package/desktop/src-tauri/Info.plist +12 -0
- package/desktop/src-tauri/build.rs +16 -0
- package/desktop/src-tauri/capabilities/default.json +15 -0
- package/desktop/src-tauri/icons/128x128.png +0 -0
- package/desktop/src-tauri/icons/16x16.png +0 -0
- package/desktop/src-tauri/icons/32x32.png +0 -0
- package/desktop/src-tauri/icons/henry.w@example.net +0 -0
- package/desktop/src-tauri/icons/icon.icns +0 -0
- package/desktop/src-tauri/icons/icon.ico +0 -0
- package/desktop/src-tauri/icons/icon.png +0 -0
- package/desktop/src-tauri/icons/icon.svg +7 -0
- package/desktop/src-tauri/permissions/bridge.toml +24 -0
- package/desktop/src-tauri/src/main.rs +312 -0
- package/desktop/src-tauri/src/mic.rs +216 -0
- package/desktop/src-tauri/tauri.conf.json +46 -0
- package/desktop/tsconfig.json +21 -0
- package/desktop/vite.config.ts +18 -0
- package/package.json +5 -4
- package/src/cli/main.test.ts +6 -0
- package/src/cli/main.ts +5 -2
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
export type RichPart =
|
|
2
|
+
| { type: "text"; text: string }
|
|
3
|
+
| { type: "link"; href: string; label: string }
|
|
4
|
+
| { type: "file"; path: string; label: string }
|
|
5
|
+
| { type: "image"; src: string; alt: string };
|
|
6
|
+
|
|
7
|
+
const MD_LINK = /\[([^\]]+)\]\(((?:https?:\/\/|file:\/\/|~\/|\/)[^)\s]+)\)/gi;
|
|
8
|
+
const BARE_URL = /https?:\/\/[^\s<>"'\])]+/gi;
|
|
9
|
+
const DIR_REF =
|
|
10
|
+
/(?:^|[\s(])((?:~|\/(?:Users|home|Volumes|private|tmp|opt|var|Applications|Library))[^\s):,]*)/g;
|
|
11
|
+
|
|
12
|
+
export function isImageUrl(href: string): boolean {
|
|
13
|
+
try {
|
|
14
|
+
const url = new URL(href);
|
|
15
|
+
if (/\.(png|jpe?g|gif|webp|svg)$/i.test(url.pathname)) return true;
|
|
16
|
+
if (url.hostname === "media.canva.com") return true;
|
|
17
|
+
if (url.pathname.includes("/document-image")) return true;
|
|
18
|
+
return false;
|
|
19
|
+
} catch {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function canvaViewUrl(href: string): string | undefined {
|
|
25
|
+
try {
|
|
26
|
+
const url = new URL(href);
|
|
27
|
+
if (url.hostname === "www.canva.com" || url.hostname === "canva.com") {
|
|
28
|
+
const short = /^\/d\/([^/]+)/.exec(url.pathname)?.[1];
|
|
29
|
+
if (short) return `https://www.canva.com/d/${short}`;
|
|
30
|
+
}
|
|
31
|
+
const designId = /\/id:([^/]+)/.exec(url.pathname)?.[1];
|
|
32
|
+
if (url.hostname === "media.canva.com" && designId) {
|
|
33
|
+
return `https://www.canva.com/design/${designId}/view`;
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
} catch {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function linkLabel(href: string): string {
|
|
42
|
+
try {
|
|
43
|
+
const url = new URL(href);
|
|
44
|
+
const path = url.pathname === "/" ? "" : url.pathname.replace(/\/+$/, "");
|
|
45
|
+
return `${url.host}${path}`;
|
|
46
|
+
} catch {
|
|
47
|
+
return href;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function isLocalFileHref(href: string): boolean {
|
|
52
|
+
if (href.startsWith("file:")) return true;
|
|
53
|
+
if (href.startsWith("~/") || href === "~") return true;
|
|
54
|
+
return /^(?:\/(?:Users|home|Volumes|private|tmp|opt|var|Applications|Library)(?:\/|$))/.test(
|
|
55
|
+
href,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function joinLocalPath(dir: string, name: string): string {
|
|
60
|
+
if (isLocalFileHref(name) || name.startsWith("./") || name.startsWith("../")) return name;
|
|
61
|
+
return `${dir.replace(/\/+$/, "")}/${name}`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function looksLikeFilename(name: string): boolean {
|
|
65
|
+
if (!name || name.length > 240) return false;
|
|
66
|
+
if (isLocalFileHref(name) || name.includes("/")) return true;
|
|
67
|
+
return /\.[A-Za-z0-9]{1,10}$/.test(name);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function splitRichText(text: string): RichPart[] {
|
|
71
|
+
if (!text) return [];
|
|
72
|
+
const taken: Array<{ start: number; end: number; part: RichPart }> = [];
|
|
73
|
+
|
|
74
|
+
for (const match of text.matchAll(MD_LINK)) {
|
|
75
|
+
const hrefRaw = match[2];
|
|
76
|
+
const label = match[1];
|
|
77
|
+
if (!hrefRaw || label === undefined || match.index === undefined) continue;
|
|
78
|
+
const href = decodeHref(hrefRaw);
|
|
79
|
+
taken.push({
|
|
80
|
+
start: match.index,
|
|
81
|
+
end: match.index + match[0].length,
|
|
82
|
+
part: fileOrWebPart(href, label || (isLocalFileHref(href) ? href : linkLabel(href))),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
for (const match of text.matchAll(BARE_URL)) {
|
|
87
|
+
if (match.index === undefined) continue;
|
|
88
|
+
const start = match.index;
|
|
89
|
+
const end = start + match[0].length;
|
|
90
|
+
if (overlaps(taken, start, end)) continue;
|
|
91
|
+
const href = decodeHref(trimTrailingPunct(match[0]));
|
|
92
|
+
taken.push({
|
|
93
|
+
start,
|
|
94
|
+
end: start + href.length,
|
|
95
|
+
part: isImageUrl(href)
|
|
96
|
+
? { type: "image", src: href, alt: "Preview" }
|
|
97
|
+
: { type: "link", href, label: linkLabel(href) },
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
for (const hit of collectLocalFiles(text)) {
|
|
102
|
+
if (overlaps(taken, hit.start, hit.end)) continue;
|
|
103
|
+
taken.push({
|
|
104
|
+
start: hit.start,
|
|
105
|
+
end: hit.end,
|
|
106
|
+
part: { type: "file", path: hit.path, label: hit.label },
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
taken.sort((a, b) => a.start - b.start);
|
|
111
|
+
const parts: RichPart[] = [];
|
|
112
|
+
let cursor = 0;
|
|
113
|
+
for (const item of taken) {
|
|
114
|
+
if (item.start > cursor) {
|
|
115
|
+
parts.push({ type: "text", text: text.slice(cursor, item.start) });
|
|
116
|
+
}
|
|
117
|
+
parts.push(item.part);
|
|
118
|
+
cursor = item.end;
|
|
119
|
+
}
|
|
120
|
+
if (cursor < text.length) parts.push({ type: "text", text: text.slice(cursor) });
|
|
121
|
+
return parts.length > 0 ? parts : [{ type: "text", text }];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function fileOrWebPart(href: string, label: string): RichPart {
|
|
125
|
+
if (isLocalFileHref(href)) return { type: "file", path: href, label };
|
|
126
|
+
if (isImageUrl(href)) return { type: "image", src: href, alt: label };
|
|
127
|
+
return { type: "link", href, label };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function overlaps(
|
|
131
|
+
taken: Array<{ start: number; end: number }>,
|
|
132
|
+
start: number,
|
|
133
|
+
end: number,
|
|
134
|
+
): boolean {
|
|
135
|
+
return taken.some((item) => start < item.end && end > item.start);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function collectLocalFiles(
|
|
139
|
+
text: string,
|
|
140
|
+
): Array<{ start: number; end: number; path: string; label: string }> {
|
|
141
|
+
const hits: Array<{ start: number; end: number; path: string; label: string }> = [];
|
|
142
|
+
const dirs: Array<{ start: number; path: string }> = [];
|
|
143
|
+
|
|
144
|
+
for (const match of text.matchAll(DIR_REF)) {
|
|
145
|
+
const raw = match[1];
|
|
146
|
+
if (!raw || match.index === undefined) continue;
|
|
147
|
+
const start = match.index + match[0].length - raw.length;
|
|
148
|
+
const path = trimTrailingPunct(raw).replace(/\/+$/, "") || raw;
|
|
149
|
+
if (path.length < 2) continue;
|
|
150
|
+
dirs.push({ start, path });
|
|
151
|
+
hits.push({ start, end: start + raw.length, path, label: path });
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
let cursor = 0;
|
|
155
|
+
for (const line of text.split("\n")) {
|
|
156
|
+
const prefix = /^(\s*(?:\d+\.|[-*])\s+)/u.exec(line);
|
|
157
|
+
if (prefix) {
|
|
158
|
+
const restStart = prefix[0].length;
|
|
159
|
+
const dash = line.search(/\s+[—–]\s+/u);
|
|
160
|
+
const name = (dash >= restStart ? line.slice(restStart, dash) : line.slice(restStart)).trim();
|
|
161
|
+
if (looksLikeFilename(name)) {
|
|
162
|
+
const nearby = [...dirs].reverse().find((dir) => dir.start <= cursor) ?? dirs[0];
|
|
163
|
+
const path =
|
|
164
|
+
isLocalFileHref(name) || name.includes("/")
|
|
165
|
+
? name
|
|
166
|
+
: nearby
|
|
167
|
+
? joinLocalPath(nearby.path, name)
|
|
168
|
+
: "";
|
|
169
|
+
if (path) {
|
|
170
|
+
const start = cursor + restStart + line.slice(restStart).indexOf(name);
|
|
171
|
+
hits.push({ start, end: start + name.length, path, label: name });
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
cursor += line.length + 1;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
hits.sort((a, b) => a.start - b.start || a.end - b.end);
|
|
179
|
+
const out: typeof hits = [];
|
|
180
|
+
for (const hit of hits) {
|
|
181
|
+
if (out.some((item) => hit.start < item.end && hit.end > item.start)) continue;
|
|
182
|
+
out.push(hit);
|
|
183
|
+
}
|
|
184
|
+
return out;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function decodeHref(raw: string): string {
|
|
188
|
+
return raw.replaceAll("&", "&");
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function trimTrailingPunct(raw: string): string {
|
|
192
|
+
return raw.replace(/[.,;:!?]+$/u, "");
|
|
193
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { clampMenuPosition } from "./session-menu";
|
|
3
|
+
|
|
4
|
+
describe("session menu", () => {
|
|
5
|
+
test("keeps the menu on screen", () => {
|
|
6
|
+
expect(
|
|
7
|
+
clampMenuPosition(10, 10, { width: 160, height: 80 }, { width: 800, height: 600 }),
|
|
8
|
+
).toEqual({
|
|
9
|
+
x: 10,
|
|
10
|
+
y: 10,
|
|
11
|
+
});
|
|
12
|
+
expect(
|
|
13
|
+
clampMenuPosition(780, 580, { width: 160, height: 80 }, { width: 800, height: 600 }),
|
|
14
|
+
).toEqual({
|
|
15
|
+
x: 632,
|
|
16
|
+
y: 512,
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function clampMenuPosition(
|
|
2
|
+
x: number,
|
|
3
|
+
y: number,
|
|
4
|
+
menu: { width: number; height: number },
|
|
5
|
+
viewport: { width: number; height: number },
|
|
6
|
+
pad = 8,
|
|
7
|
+
): { x: number; y: number } {
|
|
8
|
+
return {
|
|
9
|
+
x: Math.min(Math.max(pad, x), Math.max(pad, viewport.width - menu.width - pad)),
|
|
10
|
+
y: Math.min(Math.max(pad, y), Math.max(pad, viewport.height - menu.height - pad)),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { formatSkillInstalls, omitCatalogSkill, skillMatches } from "./skill-search.ts";
|
|
3
|
+
|
|
4
|
+
describe("skillMatches", () => {
|
|
5
|
+
const item = {
|
|
6
|
+
name: "frontend-design",
|
|
7
|
+
source: "anthropics/skills",
|
|
8
|
+
description: "Distinctive UI, typography, motion, and color.",
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
test("matches name prefixes and sources", () => {
|
|
12
|
+
expect(skillMatches(item, "")).toBe(true);
|
|
13
|
+
expect(skillMatches(item, "front")).toBe(true);
|
|
14
|
+
expect(skillMatches(item, "anthropics")).toBe(true);
|
|
15
|
+
expect(skillMatches(item, "billing")).toBe(false);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("uses description only for longer queries", () => {
|
|
19
|
+
expect(skillMatches(item, "ty")).toBe(false);
|
|
20
|
+
expect(skillMatches(item, "typography")).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("formats install counts", () => {
|
|
24
|
+
expect(formatSkillInstalls(891_500)).toBe("891.5K");
|
|
25
|
+
expect(formatSkillInstalls(3_400_000)).toBe("3.4M");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("omits a catalog row after add fails", () => {
|
|
29
|
+
const items = [
|
|
30
|
+
{ id: "openai/skills/frontend-skill", name: "frontend-skill" },
|
|
31
|
+
{ id: "openai/skills/chatgpt-apps", name: "chatgpt-apps" },
|
|
32
|
+
];
|
|
33
|
+
expect(
|
|
34
|
+
omitCatalogSkill(items, "openai/skills@frontend-skill").map((item) => item.name),
|
|
35
|
+
).toEqual(["chatgpt-apps"]);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export function formatSkillInstalls(count: number): string {
|
|
2
|
+
if (count >= 1_000_000) return `${(count / 1_000_000).toFixed(1).replace(/\.0$/, "")}M`;
|
|
3
|
+
if (count >= 1_000) return `${(count / 1_000).toFixed(1).replace(/\.0$/, "")}K`;
|
|
4
|
+
return String(count);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/** Match skill name, source, or a longer description snippet. */
|
|
8
|
+
export function skillMatches(
|
|
9
|
+
item: { name: string; source: string; description?: string },
|
|
10
|
+
query: string,
|
|
11
|
+
): boolean {
|
|
12
|
+
const q = query.trim().toLowerCase();
|
|
13
|
+
if (!q) return true;
|
|
14
|
+
const name = item.name.toLowerCase();
|
|
15
|
+
if (name.startsWith(q) || name.includes(q)) return true;
|
|
16
|
+
const source = item.source.toLowerCase().replace(/[/@_-]+/g, " ");
|
|
17
|
+
if (source.split(/\s+/).some((word) => word.startsWith(q) || word.includes(q))) return true;
|
|
18
|
+
if (q.length >= 3 && (item.description ?? "").toLowerCase().includes(q)) return true;
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function omitCatalogSkill<T extends { id: string }>(items: T[], id: string): T[] {
|
|
23
|
+
const key = id.trim().replaceAll("@", "/").toLowerCase();
|
|
24
|
+
return items.filter((item) => item.id.replaceAll("@", "/").toLowerCase() !== key);
|
|
25
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
applyEvent,
|
|
4
|
+
linesFromTranscript,
|
|
5
|
+
type StreamLine,
|
|
6
|
+
truncateAfterUserTurn,
|
|
7
|
+
} from "./stream.ts";
|
|
8
|
+
|
|
9
|
+
describe("applyEvent", () => {
|
|
10
|
+
test("does not reprint the conversation title from session_meta", () => {
|
|
11
|
+
const start: StreamLine[] = [
|
|
12
|
+
{ key: "u-0", type: "user", text: "show me the latest cv", userTurnIndex: 0 },
|
|
13
|
+
];
|
|
14
|
+
const next = applyEvent(start, {
|
|
15
|
+
kind: "session_meta",
|
|
16
|
+
sessionId: "s1",
|
|
17
|
+
title: "show me the latest cv",
|
|
18
|
+
});
|
|
19
|
+
expect(next).toEqual(start);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("truncateAfterUserTurn keeps the edited user line and drops what followed", () => {
|
|
23
|
+
const lines: StreamLine[] = [
|
|
24
|
+
{ key: "u-0", type: "user", text: "one", userTurnIndex: 0 },
|
|
25
|
+
{ key: "a-1", type: "assistant", text: "reply" },
|
|
26
|
+
{ key: "u-2", type: "user", text: "two", userTurnIndex: 1 },
|
|
27
|
+
];
|
|
28
|
+
expect(truncateAfterUserTurn(lines, 0, "one edited")).toEqual([
|
|
29
|
+
{ key: "u-0", type: "user", text: "one edited", userTurnIndex: 0 },
|
|
30
|
+
]);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("linesFromTranscript keeps tool calls between turns", () => {
|
|
34
|
+
const lines = linesFromTranscript([
|
|
35
|
+
{ kind: "user", text: "list pages" },
|
|
36
|
+
{
|
|
37
|
+
kind: "tool",
|
|
38
|
+
name: "notion__notion_fetch",
|
|
39
|
+
callId: "call-1",
|
|
40
|
+
status: "ok",
|
|
41
|
+
preview: '{"id":"abc"}',
|
|
42
|
+
},
|
|
43
|
+
{ kind: "assistant", text: "done" },
|
|
44
|
+
]);
|
|
45
|
+
expect(lines.map((line) => line.type)).toEqual(["user", "tool", "assistant"]);
|
|
46
|
+
expect(lines[1]).toMatchObject({
|
|
47
|
+
type: "tool",
|
|
48
|
+
name: "notion__notion_fetch",
|
|
49
|
+
status: "ok",
|
|
50
|
+
label: "Notion fetch",
|
|
51
|
+
count: 1,
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("coalesces back-to-back identical tool starts", () => {
|
|
56
|
+
const first = applyEvent([], {
|
|
57
|
+
kind: "tool_call_start",
|
|
58
|
+
toolName: "notion__notion_fetch",
|
|
59
|
+
callId: "a",
|
|
60
|
+
input: { id: "1" },
|
|
61
|
+
});
|
|
62
|
+
const second = applyEvent(first, {
|
|
63
|
+
kind: "tool_call_start",
|
|
64
|
+
toolName: "notion__notion_fetch",
|
|
65
|
+
callId: "b",
|
|
66
|
+
input: { id: "2" },
|
|
67
|
+
});
|
|
68
|
+
expect(second).toHaveLength(1);
|
|
69
|
+
expect(second[0]).toMatchObject({ type: "tool", label: "Notion fetch", count: 2, callId: "b" });
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("appends reasoning deltas onto a thought line", () => {
|
|
73
|
+
const first = applyEvent([], { kind: "reasoning_delta", text: "look up " });
|
|
74
|
+
const second = applyEvent(first, { kind: "reasoning_delta", text: "the page" });
|
|
75
|
+
expect(second).toEqual([{ key: "th-0", type: "thought", text: "look up the page" }]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("linesFromTranscript keeps thoughts between turns", () => {
|
|
79
|
+
const lines = linesFromTranscript([
|
|
80
|
+
{ kind: "user", text: "list pages" },
|
|
81
|
+
{ kind: "thought", text: "I should search Notion." },
|
|
82
|
+
{
|
|
83
|
+
kind: "tool",
|
|
84
|
+
name: "notion__notion_fetch",
|
|
85
|
+
callId: "call-1",
|
|
86
|
+
status: "ok",
|
|
87
|
+
preview: '{"id":"abc"}',
|
|
88
|
+
},
|
|
89
|
+
{ kind: "assistant", text: "done" },
|
|
90
|
+
]);
|
|
91
|
+
expect(lines.map((line) => line.type)).toEqual(["user", "thought", "tool", "assistant"]);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import type { AgentEvent } from "./api";
|
|
2
|
+
import type { AttachmentPreview } from "./composer-files";
|
|
3
|
+
import { inputFromPreview, toolLabel } from "./tool-label";
|
|
4
|
+
|
|
5
|
+
export type ToolStatus = "running" | "ok" | "fail";
|
|
6
|
+
|
|
7
|
+
export type StreamLine =
|
|
8
|
+
| {
|
|
9
|
+
key: string;
|
|
10
|
+
type: "user";
|
|
11
|
+
text: string;
|
|
12
|
+
userTurnIndex: number;
|
|
13
|
+
attachments?: AttachmentPreview[];
|
|
14
|
+
}
|
|
15
|
+
| { key: string; type: "assistant"; text: string }
|
|
16
|
+
| { key: string; type: "thought"; text: string }
|
|
17
|
+
| {
|
|
18
|
+
key: string;
|
|
19
|
+
type: "tool";
|
|
20
|
+
name: string;
|
|
21
|
+
callId: string;
|
|
22
|
+
status: ToolStatus;
|
|
23
|
+
label: string;
|
|
24
|
+
count: number;
|
|
25
|
+
preview: string;
|
|
26
|
+
error?: string;
|
|
27
|
+
}
|
|
28
|
+
| { key: string; type: "system"; text: string }
|
|
29
|
+
| { key: string; type: "error"; text: string }
|
|
30
|
+
| { key: string; type: "todos"; text: string }
|
|
31
|
+
| {
|
|
32
|
+
key: string;
|
|
33
|
+
type: "media";
|
|
34
|
+
kind: "image" | "video";
|
|
35
|
+
src: string;
|
|
36
|
+
caption: string;
|
|
37
|
+
mimeType: string;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export function nextUserTurnIndex(lines: StreamLine[]): number {
|
|
41
|
+
let count = 0;
|
|
42
|
+
for (const line of lines) if (line.type === "user") count++;
|
|
43
|
+
return count;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function truncateAfterUserTurn(
|
|
47
|
+
lines: StreamLine[],
|
|
48
|
+
userTurnIndex: number,
|
|
49
|
+
text: string,
|
|
50
|
+
): StreamLine[] {
|
|
51
|
+
const idx = lines.findIndex(
|
|
52
|
+
(line) => line.type === "user" && line.userTurnIndex === userTurnIndex,
|
|
53
|
+
);
|
|
54
|
+
if (idx < 0) return lines;
|
|
55
|
+
const current = lines[idx];
|
|
56
|
+
if (current?.type !== "user") return lines;
|
|
57
|
+
return [...lines.slice(0, idx), { ...current, text }];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function previewInput(input: Record<string, unknown>): string {
|
|
61
|
+
const cmd = typeof input.command === "string" ? input.command : undefined;
|
|
62
|
+
const path = typeof input.path === "string" ? input.path : undefined;
|
|
63
|
+
const pattern = typeof input.pattern === "string" ? input.pattern : undefined;
|
|
64
|
+
const prompt = typeof input.prompt === "string" ? input.prompt : undefined;
|
|
65
|
+
const label = typeof input.label === "string" ? input.label : undefined;
|
|
66
|
+
const raw = label ?? cmd ?? path ?? pattern ?? prompt ?? JSON.stringify(input);
|
|
67
|
+
return raw.length > 80 ? `${raw.slice(0, 79)}…` : raw;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function applyEvent(lines: StreamLine[], event: AgentEvent): StreamLine[] {
|
|
71
|
+
switch (event.kind) {
|
|
72
|
+
case "text_delta": {
|
|
73
|
+
const last = lines[lines.length - 1];
|
|
74
|
+
if (last?.type === "assistant") {
|
|
75
|
+
return [...lines.slice(0, -1), { ...last, text: last.text + event.text }];
|
|
76
|
+
}
|
|
77
|
+
return [...lines, { key: `a-${lines.length}`, type: "assistant", text: event.text }];
|
|
78
|
+
}
|
|
79
|
+
case "reasoning_delta": {
|
|
80
|
+
const last = lines[lines.length - 1];
|
|
81
|
+
if (last?.type === "thought") {
|
|
82
|
+
return [...lines.slice(0, -1), { ...last, text: last.text + event.text }];
|
|
83
|
+
}
|
|
84
|
+
return [...lines, { key: `th-${lines.length}`, type: "thought", text: event.text }];
|
|
85
|
+
}
|
|
86
|
+
case "tool_call_start": {
|
|
87
|
+
const label = toolLabel(event.toolName, event.input);
|
|
88
|
+
const last = lines[lines.length - 1];
|
|
89
|
+
if (last?.type === "tool" && last.status !== "fail" && last.label === label) {
|
|
90
|
+
return [
|
|
91
|
+
...lines.slice(0, -1),
|
|
92
|
+
{
|
|
93
|
+
...last,
|
|
94
|
+
key: event.callId,
|
|
95
|
+
callId: event.callId,
|
|
96
|
+
status: "running",
|
|
97
|
+
count: last.count + 1,
|
|
98
|
+
preview: previewInput(event.input),
|
|
99
|
+
},
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
return [
|
|
103
|
+
...lines,
|
|
104
|
+
{
|
|
105
|
+
key: event.callId,
|
|
106
|
+
type: "tool",
|
|
107
|
+
name: event.toolName,
|
|
108
|
+
callId: event.callId,
|
|
109
|
+
status: "running",
|
|
110
|
+
label,
|
|
111
|
+
count: 1,
|
|
112
|
+
preview: previewInput(event.input),
|
|
113
|
+
},
|
|
114
|
+
];
|
|
115
|
+
}
|
|
116
|
+
case "tool_call_end":
|
|
117
|
+
return lines.map((line) =>
|
|
118
|
+
line.type === "tool" && line.callId === event.callId
|
|
119
|
+
? { ...line, status: event.success ? "ok" : "fail", error: event.error }
|
|
120
|
+
: line,
|
|
121
|
+
);
|
|
122
|
+
case "session_meta":
|
|
123
|
+
return lines;
|
|
124
|
+
case "error":
|
|
125
|
+
return [...lines, { key: `e-${lines.length}`, type: "error", text: event.message }];
|
|
126
|
+
case "todos":
|
|
127
|
+
return [
|
|
128
|
+
...lines,
|
|
129
|
+
{
|
|
130
|
+
key: `todo-${lines.length}`,
|
|
131
|
+
type: "todos",
|
|
132
|
+
text: event.items.map((item) => `${item.status} ${item.content}`).join(" · "),
|
|
133
|
+
},
|
|
134
|
+
];
|
|
135
|
+
case "usage":
|
|
136
|
+
case "completion":
|
|
137
|
+
case "approval_request":
|
|
138
|
+
return lines;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function linesFromTurns(
|
|
143
|
+
messages: Array<{ role: "user" | "assistant"; content: string }>,
|
|
144
|
+
): StreamLine[] {
|
|
145
|
+
return linesFromTranscript(
|
|
146
|
+
messages.map((message) =>
|
|
147
|
+
message.role === "user"
|
|
148
|
+
? { kind: "user" as const, text: message.content }
|
|
149
|
+
: { kind: "assistant" as const, text: message.content },
|
|
150
|
+
),
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function linesFromTranscript(
|
|
155
|
+
messages: Array<
|
|
156
|
+
| { kind: "user"; text: string }
|
|
157
|
+
| { kind: "assistant"; text: string }
|
|
158
|
+
| { kind: "thought"; text: string }
|
|
159
|
+
| {
|
|
160
|
+
kind: "tool";
|
|
161
|
+
name: string;
|
|
162
|
+
callId: string;
|
|
163
|
+
status: ToolStatus;
|
|
164
|
+
preview: string;
|
|
165
|
+
error?: string;
|
|
166
|
+
}
|
|
167
|
+
>,
|
|
168
|
+
): StreamLine[] {
|
|
169
|
+
let userTurnIndex = 0;
|
|
170
|
+
return messages.map((message, index) => {
|
|
171
|
+
if (message.kind === "user") {
|
|
172
|
+
return {
|
|
173
|
+
key: `u-${index}`,
|
|
174
|
+
type: "user" as const,
|
|
175
|
+
text: message.text,
|
|
176
|
+
userTurnIndex: userTurnIndex++,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
if (message.kind === "assistant") {
|
|
180
|
+
return { key: `a-${index}`, type: "assistant" as const, text: message.text };
|
|
181
|
+
}
|
|
182
|
+
if (message.kind === "thought") {
|
|
183
|
+
return { key: `th-${index}`, type: "thought" as const, text: message.text };
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
key: message.callId || `t-${index}`,
|
|
187
|
+
type: "tool" as const,
|
|
188
|
+
name: message.name,
|
|
189
|
+
callId: message.callId,
|
|
190
|
+
status: message.status,
|
|
191
|
+
label: toolLabel(message.name, inputFromPreview(message.preview)),
|
|
192
|
+
count: 1,
|
|
193
|
+
preview: message.preview,
|
|
194
|
+
error: message.error,
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/* Self-hosted variable faces, WKWebView-safe.
|
|
2
|
+
One family per file. No unicode-range (latin-ext also ships U+0020;
|
|
3
|
+
WebKit then paints two spaces and drops the advance).
|
|
4
|
+
Discrete weights, not `400 700`, so it does not composite two masters.
|
|
5
|
+
`block` not `swap`: swap leaves system-ui and the webfont both visible. */
|
|
6
|
+
|
|
7
|
+
@font-face {
|
|
8
|
+
font-family: "Instrument Sans";
|
|
9
|
+
src: url("./fonts/instrument-sans-latin-wght-normal.ttf") format("truetype");
|
|
10
|
+
font-weight: 400;
|
|
11
|
+
font-style: normal;
|
|
12
|
+
font-display: block;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@font-face {
|
|
16
|
+
font-family: "Instrument Sans";
|
|
17
|
+
src: url("./fonts/instrument-sans-latin-wght-normal.ttf") format("truetype");
|
|
18
|
+
font-weight: 500;
|
|
19
|
+
font-style: normal;
|
|
20
|
+
font-display: block;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@font-face {
|
|
24
|
+
font-family: "Instrument Sans";
|
|
25
|
+
src: url("./fonts/instrument-sans-latin-wght-normal.ttf") format("truetype");
|
|
26
|
+
font-weight: 600;
|
|
27
|
+
font-style: normal;
|
|
28
|
+
font-display: block;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@font-face {
|
|
32
|
+
font-family: "Instrument Sans";
|
|
33
|
+
src: url("./fonts/instrument-sans-latin-wght-normal.ttf") format("truetype");
|
|
34
|
+
font-weight: 700;
|
|
35
|
+
font-style: normal;
|
|
36
|
+
font-display: block;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@font-face {
|
|
40
|
+
font-family: "Chivo Mono";
|
|
41
|
+
src: url("./fonts/chivo-mono-latin-wght-normal.ttf") format("truetype");
|
|
42
|
+
font-weight: 400;
|
|
43
|
+
font-style: normal;
|
|
44
|
+
font-display: block;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@font-face {
|
|
48
|
+
font-family: "Chivo Mono";
|
|
49
|
+
src: url("./fonts/chivo-mono-latin-wght-normal.ttf") format("truetype");
|
|
50
|
+
font-weight: 500;
|
|
51
|
+
font-style: normal;
|
|
52
|
+
font-display: block;
|
|
53
|
+
}
|