@x-tech-laboratories/x-app 0.116.0 → 0.118.0
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 +19 -6
- package/dist/agent/claude_stream.d.ts +22 -0
- package/dist/agent/claude_stream.js +85 -0
- package/dist/agent/git.d.ts +37 -0
- package/dist/agent/git.js +121 -0
- package/dist/agent/github.d.ts +81 -0
- package/dist/agent/github.js +185 -0
- package/dist/agent/programs.d.ts +17 -0
- package/dist/agent/programs.js +62 -0
- package/dist/agent/worktree_files.d.ts +20 -0
- package/dist/agent/worktree_files.js +69 -0
- package/dist/agent_transcript.d.ts +83 -0
- package/dist/agent_transcript.js +267 -0
- package/dist/app_android_key.d.ts +3 -0
- package/dist/app_android_key.js +34 -11
- package/dist/connection_protocol.d.ts +1 -0
- package/dist/connection_protocol.js +11 -0
- package/dist/diff_rows.d.ts +78 -0
- package/dist/diff_rows.js +158 -0
- package/dist/frontmatter.d.ts +10 -0
- package/dist/frontmatter.js +57 -0
- package/dist/frontmatter_folder.d.ts +24 -0
- package/dist/frontmatter_folder.js +54 -0
- package/dist/server/config.d.ts +2 -0
- package/dist/server/config.js +15 -1
- package/dist/server/github_webhook.d.ts +30 -0
- package/dist/server/github_webhook.js +146 -0
- package/dist/test_helpers.d.ts +7 -0
- package/dist/test_helpers.js +44 -0
- package/dist/web/react/accounts.js +2 -1
- package/dist/web/react/controls.d.ts +3 -2
- package/dist/web/react/controls.js +6 -4
- package/dist/web/react/copy_button.d.ts +11 -0
- package/dist/web/react/copy_button.js +44 -0
- package/dist/web/react/dialog.js +2 -2
- package/dist/web/react/diff.d.ts +26 -0
- package/dist/web/react/diff.js +79 -0
- package/dist/web/react/file_tree.d.ts +26 -0
- package/dist/web/react/file_tree.js +46 -0
- package/dist/web/react/local_mcp_settings.js +2 -1
- package/dist/web/react/transcript.d.ts +24 -0
- package/dist/web/react/transcript.js +100 -0
- package/package.json +5 -3
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// One file's change drawn from `diff_rows`: side by side with the old lines on the left and the new on the right, or
|
|
3
|
+
// in one column, each line numbered, removed and added lines tinted and the words that changed within them tinted again
|
|
4
|
+
// through Halon's diff classes, and long unchanged stretches folded behind a "show more" row; a file's text read-only
|
|
5
|
+
// with numbered lines; a small diff of one edit's before and after; and the added and removed line counts.
|
|
6
|
+
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
7
|
+
import { Fragment, useState } from "react";
|
|
8
|
+
import { edit_lines, fold_rows, split_rows, unified_rows } from "../../diff_rows.js";
|
|
9
|
+
import { cx } from "../dom.js";
|
|
10
|
+
// ── Words ────────────────────────────────────────────────────────────────────
|
|
11
|
+
// Each status's label, its one-letter mark and its badge tone.
|
|
12
|
+
export const diff_status_words = {
|
|
13
|
+
added: ["Added", "A", "good"],
|
|
14
|
+
removed: ["Deleted", "D", "bad"],
|
|
15
|
+
renamed: ["Renamed", "R", "info"],
|
|
16
|
+
changed: ["Modified", "M", "warn"],
|
|
17
|
+
};
|
|
18
|
+
// ── Pieces ───────────────────────────────────────────────────────────────────
|
|
19
|
+
// A change's added and removed line counts, such as "+3 −1".
|
|
20
|
+
export function DiffCounts({ additions, deletions }) {
|
|
21
|
+
return (_jsxs("span", { className: "diff-counts", "aria-label": `${additions} added, ${deletions} removed`, children: [_jsxs("span", { className: "diff-count-added", children: ["+", additions] }), " ", _jsxs("span", { className: "diff-count-removed", children: ["\u2212", deletions] })] }));
|
|
22
|
+
}
|
|
23
|
+
// A line's text with its changed words marked, inside a removed or added line.
|
|
24
|
+
function Words({ parts, side }) {
|
|
25
|
+
return (_jsx("code", { children: parts.map((part, index) => part.changed && side ? (_jsx("mark", { className: "diff-word", children: part.text }, index)) : (_jsx(Fragment, { children: part.text }, index))) }));
|
|
26
|
+
}
|
|
27
|
+
function FoldRow({ fold, columns, on_open }) {
|
|
28
|
+
return (_jsx("tr", { className: "diff-fold", children: _jsx("td", { colSpan: columns, children: _jsxs("button", { type: "button", className: "link", onClick: () => on_open(fold.start), children: ["Show ", fold.count, " more unchanged lines"] }) }) }));
|
|
29
|
+
}
|
|
30
|
+
function HunkRow({ header, columns }) {
|
|
31
|
+
return (_jsx("tr", { className: "diff-hunk", children: _jsx("td", { colSpan: columns, children: _jsx("code", { children: header }) }) }));
|
|
32
|
+
}
|
|
33
|
+
function SideCells({ cell, side }) {
|
|
34
|
+
if (!cell) {
|
|
35
|
+
return (_jsxs(_Fragment, { children: [_jsx("td", { className: "diff-number diff-empty" }), _jsx("td", { className: "diff-text diff-empty" })] }));
|
|
36
|
+
}
|
|
37
|
+
const tint = side && `diff-${side}`;
|
|
38
|
+
return (_jsxs(_Fragment, { children: [_jsx("td", { className: cx("diff-number", tint), children: cell.number }), _jsx("td", { className: cx("diff-text", tint), "aria-label": side ?? undefined, children: _jsx(Words, { parts: cell.parts, side: side }) })] }));
|
|
39
|
+
}
|
|
40
|
+
export function FileDiff({ file, layout, no_lines_text = "No lines to show: a binary file, a bare rename or a change of mode." }) {
|
|
41
|
+
const [opened, set_opened] = useState(new Set());
|
|
42
|
+
const open = (start) => set_opened((current) => new Set([...current, start]));
|
|
43
|
+
if (file.hunks.length === 0)
|
|
44
|
+
return _jsx("p", { className: "diff-note", children: no_lines_text });
|
|
45
|
+
if (layout === "unified") {
|
|
46
|
+
const rows = fold_rows(unified_rows(file), opened);
|
|
47
|
+
return (_jsx("div", { className: "diff-scroll", children: _jsx("table", { className: "diff-lines diff-unified", "aria-label": `Changes to ${file.path}`, children: _jsx("tbody", { children: rows.map((row, index) => {
|
|
48
|
+
if (row.kind === "fold")
|
|
49
|
+
return _jsx(FoldRow, { fold: row, columns: 4, on_open: open }, `fold-${row.start}`);
|
|
50
|
+
if (row.kind === "hunk")
|
|
51
|
+
return _jsx(HunkRow, { header: row.header, columns: 4 }, index);
|
|
52
|
+
const side = row.kind === "same" ? null : row.kind;
|
|
53
|
+
return (_jsxs("tr", { className: side ? `diff-${side}` : undefined, children: [_jsx("td", { className: "diff-number", children: row.old_number ?? "" }), _jsx("td", { className: "diff-number", children: row.new_number ?? "" }), _jsx("td", { className: "diff-mark", "aria-label": side ?? undefined, children: side === "added" ? "+" : side === "removed" ? "−" : " " }), _jsx("td", { className: "diff-text", children: _jsx(Words, { parts: row.parts, side: side }) })] }, index));
|
|
54
|
+
}) }) }) }));
|
|
55
|
+
}
|
|
56
|
+
const rows = fold_rows(split_rows(file), opened);
|
|
57
|
+
return (_jsx("div", { className: "diff-scroll", children: _jsxs("table", { className: "diff-lines diff-split", "aria-label": `Changes to ${file.path}, old on the left and new on the right`, children: [_jsxs("colgroup", { children: [_jsx("col", { className: "diff-number-column" }), _jsx("col", {}), _jsx("col", { className: "diff-number-column" }), _jsx("col", {})] }), _jsx("tbody", { children: rows.map((row, index) => {
|
|
58
|
+
if (row.kind === "fold")
|
|
59
|
+
return _jsx(FoldRow, { fold: row, columns: 4, on_open: open }, `fold-${row.start}`);
|
|
60
|
+
if (row.kind === "hunk")
|
|
61
|
+
return _jsx(HunkRow, { header: row.header, columns: 4 }, index);
|
|
62
|
+
const changed = row.kind === "change";
|
|
63
|
+
return (_jsxs("tr", { children: [_jsx(SideCells, { cell: row.left, side: changed ? "removed" : null }), _jsx(SideCells, { cell: row.right, side: changed ? "added" : null })] }, index));
|
|
64
|
+
}) })] }) }));
|
|
65
|
+
}
|
|
66
|
+
// ── Plain file ───────────────────────────────────────────────────────────────
|
|
67
|
+
// A file's text read-only, each line numbered, with no diff columns.
|
|
68
|
+
export function FileContent({ path, text }) {
|
|
69
|
+
const lines = text.replace(/\n$/, "").split("\n");
|
|
70
|
+
return (_jsx("div", { className: "diff-scroll", children: _jsx("table", { className: "diff-lines diff-plain", "aria-label": `Contents of ${path}`, children: _jsx("tbody", { children: lines.map((line, index) => (_jsxs("tr", { children: [_jsx("td", { className: "diff-number", children: index + 1 }), _jsx("td", { className: "diff-text", children: _jsx("code", { children: line }) })] }, index))) }) }) }));
|
|
71
|
+
}
|
|
72
|
+
// ── One edit ─────────────────────────────────────────────────────────────────
|
|
73
|
+
const edit_marks = { added: "+", removed: "−", context: " " };
|
|
74
|
+
// The lines one edit takes out and puts in, unchanged lines kept for context, and a long change cut short.
|
|
75
|
+
export function EditDiff({ path = "", before, after, limit = 120 }) {
|
|
76
|
+
const lines = edit_lines(before, after);
|
|
77
|
+
const kept = lines.slice(0, limit);
|
|
78
|
+
return (_jsxs("div", { className: "edit-diff", children: [path && _jsx("code", { className: "diff-path", children: path }), _jsx("div", { className: "diff-scroll", children: _jsx("table", { className: "diff-lines", "aria-label": path ? `Change to ${path}` : "Change", children: _jsx("tbody", { children: kept.map((line, index) => (_jsxs("tr", { className: line.kind === "context" ? undefined : `diff-${line.kind}`, children: [_jsx("td", { className: "diff-mark", "aria-label": line.kind === "context" ? undefined : line.kind, children: edit_marks[line.kind] }), _jsx("td", { className: "diff-text", children: _jsx("code", { children: line.text }) })] }, index))) }) }) }), lines.length > kept.length && _jsxs("p", { className: "diff-note", children: [lines.length - kept.length, " more lines left out."] })] }));
|
|
79
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { DiffFileStatus } from "../../diff_rows.ts";
|
|
3
|
+
import { type TreeItem } from "./tree.tsx";
|
|
4
|
+
export interface TreeFile {
|
|
5
|
+
path: string;
|
|
6
|
+
status?: DiffFileStatus;
|
|
7
|
+
additions?: number;
|
|
8
|
+
deletions?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface FileTreeRow<File extends TreeFile = TreeFile> extends TreeItem {
|
|
11
|
+
name: string;
|
|
12
|
+
file: File | null;
|
|
13
|
+
}
|
|
14
|
+
export declare function file_tree_rows<File extends TreeFile>(files: File[]): FileTreeRow<File>[];
|
|
15
|
+
export declare function file_tree_folders(files: Pick<TreeFile, "path">[]): string[];
|
|
16
|
+
interface FileTreeProps<File extends TreeFile> {
|
|
17
|
+
files: File[];
|
|
18
|
+
selected: string | null;
|
|
19
|
+
on_select: (path: string) => void;
|
|
20
|
+
extra?: (file: File) => ReactNode;
|
|
21
|
+
folded?: (folder: string) => boolean;
|
|
22
|
+
label?: string;
|
|
23
|
+
filter_label?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare function FileTree<File extends TreeFile>({ files, selected, on_select, extra, folded, label, filter_label }: FileTreeProps<File>): import("react").JSX.Element;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// Files as a folder tree on `Tree`: folders first and folding, each changed file with a letter for how it changed and
|
|
3
|
+
// its added and removed lines, walked with the arrow keys and picked with Enter or a click, narrowed by a filter box
|
|
4
|
+
// that keeps the folders of the files it matches.
|
|
5
|
+
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import { Badge } from "./badges.js";
|
|
8
|
+
import { SearchBox } from "./controls.js";
|
|
9
|
+
import { DiffCounts, diff_status_words } from "./diff.js";
|
|
10
|
+
import { Tree } from "./tree.js";
|
|
11
|
+
const folder_id = (path) => `folder:${path}`;
|
|
12
|
+
const folder_of = (path) => (path.includes("/") ? path.slice(0, path.lastIndexOf("/")) : "");
|
|
13
|
+
const name_of = (path) => path.slice(path.lastIndexOf("/") + 1);
|
|
14
|
+
// The files and the folders that hold them as tree rows, folders before files and each by name.
|
|
15
|
+
export function file_tree_rows(files) {
|
|
16
|
+
const rows = new Map();
|
|
17
|
+
const add_folder = (path) => {
|
|
18
|
+
if (!path)
|
|
19
|
+
return null;
|
|
20
|
+
const id = folder_id(path);
|
|
21
|
+
if (!rows.has(id))
|
|
22
|
+
rows.set(id, { id, parent_id: add_folder(folder_of(path)), position: 0, name: name_of(path), file: null });
|
|
23
|
+
return id;
|
|
24
|
+
};
|
|
25
|
+
for (const file of files)
|
|
26
|
+
rows.set(`file:${file.path}`, { id: `file:${file.path}`, parent_id: add_folder(folder_of(file.path)), position: 0, name: name_of(file.path), file });
|
|
27
|
+
const sorted = [...rows.values()].sort((first, second) => Number(first.file !== null) - Number(second.file !== null) || first.name.localeCompare(second.name));
|
|
28
|
+
return sorted.map((row, index) => ({ ...row, position: index }));
|
|
29
|
+
}
|
|
30
|
+
// The folders the files sit in, by path.
|
|
31
|
+
export function file_tree_folders(files) {
|
|
32
|
+
const folders = new Set();
|
|
33
|
+
for (const file of files) {
|
|
34
|
+
const parts = file.path.split("/").slice(0, -1);
|
|
35
|
+
parts.forEach((_, index) => folders.add(parts.slice(0, index + 1).join("/")));
|
|
36
|
+
}
|
|
37
|
+
return [...folders];
|
|
38
|
+
}
|
|
39
|
+
export function FileTree({ files, selected, on_select, extra, folded, label = "Changed files", filter_label = "Filter files" }) {
|
|
40
|
+
const [filter, set_filter] = useState("");
|
|
41
|
+
const [collapsed, set_collapsed] = useState(() => new Set(folded ? file_tree_folders(files).filter(folded).map(folder_id) : []));
|
|
42
|
+
const needle = filter.trim().toLowerCase();
|
|
43
|
+
const shown = needle ? files.filter((file) => file.path.toLowerCase().includes(needle)) : files;
|
|
44
|
+
const toggle = (id) => set_collapsed((current) => (current.has(id) ? new Set([...current].filter((each) => each !== id)) : new Set([...current, id])));
|
|
45
|
+
return (_jsxs("div", { className: "file-tree", children: [_jsx(SearchBox, { label: filter_label, value: filter, on_input: set_filter }), shown.length === 0 ? (_jsx("p", { className: "diff-note", children: files.length ? "No file matches." : "No files." })) : (_jsx(Tree, { items: file_tree_rows(shown), label: label, collapsed: collapsed, on_collapsed_change: set_collapsed, selected_id: selected ? `file:${selected}` : null, on_select: (row) => (row.file ? on_select(row.file.path) : toggle(row.id)), name_of: (row) => row.name, render_item: (row) => (row.file ? _jsx("span", { className: "tree-name", children: row.name }) : _jsxs("span", { children: [row.name, "/"] })), render_extra: (row) => row.file?.status && (_jsxs(_Fragment, { children: [extra?.(row.file), _jsx(DiffCounts, { additions: row.file.additions ?? 0, deletions: row.file.deletions ?? 0 }), _jsx(Badge, { tone: diff_status_words[row.file.status][2], title: diff_status_words[row.file.status][0], children: diff_status_words[row.file.status][1] })] })) }))] }));
|
|
46
|
+
}
|
|
@@ -6,6 +6,7 @@ import { local_mcp_add_command, local_mcp_client_config } from "../../local_mcp_
|
|
|
6
6
|
import { describe_error } from "../errors.js";
|
|
7
7
|
import { ButtonGroup, NumberField, Switch } from "./controls.js";
|
|
8
8
|
import { SettingRow } from "./layout.js";
|
|
9
|
+
import { CopyButton } from "./copy_button.js";
|
|
9
10
|
import { toast } from "./toasts.js";
|
|
10
11
|
function status_text(status) {
|
|
11
12
|
if (status.state === "running")
|
|
@@ -40,5 +41,5 @@ export function LocalMcpSettings({ device, name, data_name = "read and change th
|
|
|
40
41
|
const command = local_mcp_add_command(name, status);
|
|
41
42
|
const config = local_mcp_client_config(name, status);
|
|
42
43
|
const config_text = config === null ? "" : JSON.stringify(config, null, 2);
|
|
43
|
-
return (_jsxs(_Fragment, { children: [_jsx(SettingRow, { label: "MCP server", hint: `Lets AI assistants on this computer ${data_name}. Only programs on this computer can reach it${settings.require_token ? ", and only with its token" : ""}.`, as_label: true, children: _jsx(Switch, { label: "MCP server", checked: settings.enabled, on_change: (enabled) => void change({ ...settings, enabled }) }) }), settings.enabled && (_jsxs(_Fragment, { children: [_jsx(SettingRow, { label: "Port", hint: "Change it if another program already uses this one.", children: _jsx(NumberField, { label: "Port", bare: true, min: 1, max: 65535, value: settings.port, on_change: (port) => port !== null && void change({ ...settings, port: Math.round(port) }) }) }), _jsx(SettingRow, { label: "Require a token", hint: "Callers must send the server's token, so other programs on this computer cannot use it. Turn it off and on again for a new token.", as_label: true, children: _jsx(Switch, { label: "Require a token", checked: settings.require_token === true, on_change: (require_token) => void change({ ...settings, require_token }) }) }), _jsx(SettingRow, { label: "Status", hint: status_text(status), children: null }), command !== null && (_jsx(SettingRow, { label: "Add to Claude Code", hint: _jsx("code", { children: command }), children: null })), config !== null && (_jsx(SettingRow, { label: "Client config", hint: _jsxs(_Fragment, { children: [status.token ? "For .mcp.json or a managed MCP config, under mcpServers. It holds the token, so keep it private." : "For .mcp.json or a managed MCP config, under mcpServers.", config_shown && _jsx("pre", { className: "output", children: config_text })] }), children: _jsxs(ButtonGroup, { label: "Client config", children: [_jsx("button", { onClick: () => set_config_shown(!config_shown), children: config_shown ? "Hide" : "Show" }), _jsx(
|
|
44
|
+
return (_jsxs(_Fragment, { children: [_jsx(SettingRow, { label: "MCP server", hint: `Lets AI assistants on this computer ${data_name}. Only programs on this computer can reach it${settings.require_token ? ", and only with its token" : ""}.`, as_label: true, children: _jsx(Switch, { label: "MCP server", checked: settings.enabled, on_change: (enabled) => void change({ ...settings, enabled }) }) }), settings.enabled && (_jsxs(_Fragment, { children: [_jsx(SettingRow, { label: "Port", hint: "Change it if another program already uses this one.", children: _jsx(NumberField, { label: "Port", bare: true, min: 1, max: 65535, value: settings.port, on_change: (port) => port !== null && void change({ ...settings, port: Math.round(port) }) }) }), _jsx(SettingRow, { label: "Require a token", hint: "Callers must send the server's token, so other programs on this computer cannot use it. Turn it off and on again for a new token.", as_label: true, children: _jsx(Switch, { label: "Require a token", checked: settings.require_token === true, on_change: (require_token) => void change({ ...settings, require_token }) }) }), _jsx(SettingRow, { label: "Status", hint: status_text(status), children: null }), command !== null && (_jsx(SettingRow, { label: "Add to Claude Code", hint: _jsx("code", { children: command }), children: null })), config !== null && (_jsx(SettingRow, { label: "Client config", hint: _jsxs(_Fragment, { children: [status.token ? "For .mcp.json or a managed MCP config, under mcpServers. It holds the token, so keep it private." : "For .mcp.json or a managed MCP config, under mcpServers.", config_shown && _jsx("pre", { className: "output", children: config_text })] }), children: _jsxs(ButtonGroup, { label: "Client config", children: [_jsx("button", { onClick: () => set_config_shown(!config_shown), children: config_shown ? "Hide" : "Show" }), _jsx(CopyButton, { text: config_text })] }) }))] }))] }));
|
|
44
45
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type PermissionDecision, type TranscriptEntry, type UserRole } from "../../agent_transcript.ts";
|
|
2
|
+
export type AnswerPermission = (id: string, decision: PermissionDecision, message: string) => void;
|
|
3
|
+
interface PermissionWords {
|
|
4
|
+
decisions: Record<PermissionDecision, string>;
|
|
5
|
+
allow_for_session: (rule: string) => string;
|
|
6
|
+
}
|
|
7
|
+
interface TranscriptViewProps {
|
|
8
|
+
entries: TranscriptEntry[];
|
|
9
|
+
live: boolean;
|
|
10
|
+
dropped?: number;
|
|
11
|
+
empty_text?: string;
|
|
12
|
+
user_labels?: Partial<Record<UserRole, string>>;
|
|
13
|
+
on_permission?: AnswerPermission;
|
|
14
|
+
allow_for_session?: boolean;
|
|
15
|
+
permission_words?: Partial<PermissionWords>;
|
|
16
|
+
}
|
|
17
|
+
export declare function TranscriptView({ entries, live, dropped, empty_text, user_labels, on_permission, allow_for_session, permission_words }: TranscriptViewProps): import("react").JSX.Element;
|
|
18
|
+
interface TranscriptMessageBoxProps {
|
|
19
|
+
on_send: (text: string) => Promise<boolean> | boolean;
|
|
20
|
+
placeholder?: string;
|
|
21
|
+
label?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function TranscriptMessageBox({ on_send, placeholder, label }: TranscriptMessageBoxProps): import("react").JSX.Element;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// An agent session's transcript from `agent_transcript` as steps: thinking folded to one line, its text as Markdown,
|
|
3
|
+
// each tool call as a row naming the tool and what it works on that opens to its whole input and result, an edit as a
|
|
4
|
+
// small diff, the user's own messages in place, marked while the agent has not read them yet, and each tool call
|
|
5
|
+
// waiting for approval with Allow, Allow for the session and Deny. It follows the newest step until the reader scrolls
|
|
6
|
+
// up, with a button back to the latest. `TranscriptMessageBox` writes to the agent while its session is open.
|
|
7
|
+
// ── Imports ──────────────────────────────────────────────────────────────────
|
|
8
|
+
import { useState } from "react";
|
|
9
|
+
import { edit_of, permission_rule, rule_words, tool_summary } from "../../agent_transcript.js";
|
|
10
|
+
import { cx } from "../dom.js";
|
|
11
|
+
import { Badge } from "./badges.js";
|
|
12
|
+
import { EditDiff } from "./diff.js";
|
|
13
|
+
import { use_follow_tail } from "./following.js";
|
|
14
|
+
import { Markdown } from "./markdown.js";
|
|
15
|
+
// ── Steps ────────────────────────────────────────────────────────────────────
|
|
16
|
+
const default_user_labels = { input: "Input", message: "You" };
|
|
17
|
+
function last_line(text) {
|
|
18
|
+
return text.trim().split("\n").at(-1)?.trim() ?? "";
|
|
19
|
+
}
|
|
20
|
+
function Thinking({ entry }) {
|
|
21
|
+
return (_jsxs("details", { className: "transcript-step transcript-thinking", children: [_jsxs("summary", { children: [_jsx("span", { className: cx("status-dot", "tone-info", entry.streaming && "busy"), "aria-hidden": "true" }), " ", _jsx("span", { className: "muted", children: entry.streaming ? "Thinking…" : "Thought" }), " ", _jsx("span", { className: "transcript-line muted small", children: last_line(entry.text) })] }), _jsx("p", { className: "transcript-text muted", children: entry.text || "The model kept its thinking to itself." })] }));
|
|
22
|
+
}
|
|
23
|
+
function ToolInput({ name, input, input_text }) {
|
|
24
|
+
if (input_text !== undefined)
|
|
25
|
+
return _jsx("pre", { className: "transcript-code", children: input_text });
|
|
26
|
+
const edits = edit_of(name, input);
|
|
27
|
+
if (edits)
|
|
28
|
+
return _jsx(_Fragment, { children: edits.map((edit, index) => _jsx(EditDiff, { ...edit }, index)) });
|
|
29
|
+
if (typeof input.command === "string")
|
|
30
|
+
return _jsx("pre", { className: "transcript-code", children: input.command });
|
|
31
|
+
return _jsx("pre", { className: "transcript-code", children: JSON.stringify(input, null, 2) });
|
|
32
|
+
}
|
|
33
|
+
const default_permission_words = {
|
|
34
|
+
decisions: { allowed: "Allowed", allowed_for_session: "Allowed for this session", denied: "Denied" },
|
|
35
|
+
allow_for_session: (rule) => `Allow ${rule} for This Session`,
|
|
36
|
+
};
|
|
37
|
+
function Permission({ entry, on_answer, allow_for_session, words }) {
|
|
38
|
+
const [reason, set_reason] = useState("");
|
|
39
|
+
const waiting = !entry.decision;
|
|
40
|
+
const tone = waiting ? "warn" : entry.decision === "denied" ? "bad" : "good";
|
|
41
|
+
return (_jsxs("div", { className: cx("transcript-step transcript-permission", `tone-edge-${tone}`), role: waiting ? "group" : undefined, "aria-label": waiting ? `${entry.tool} waits for approval` : undefined, children: [_jsxs("div", { className: "transcript-head", children: [_jsx(Badge, { tone: tone, children: waiting ? "Waiting for approval" : words.decisions[entry.decision] }), _jsx("strong", { children: entry.tool }), !waiting && _jsx("code", { className: "transcript-line", children: tool_summary(entry.input) })] }), entry.reason && _jsx("p", { className: "small muted", children: entry.reason }), waiting && _jsx(ToolInput, { name: entry.tool, input: entry.input }), entry.message && _jsxs("p", { className: "small", children: ["Reason given: ", entry.message] }), waiting && on_answer && (_jsxs("div", { className: "transcript-answer", children: [_jsx("input", { type: "text", "aria-label": `Why ${entry.tool} is refused`, placeholder: "Why not, for the agent (optional)", value: reason, onChange: (event) => set_reason(event.currentTarget.value) }), _jsxs("span", { className: "transcript-head", children: [_jsx("button", { type: "button", className: "accent solid", onClick: () => on_answer(entry.id, "allowed", ""), children: "Allow" }), allow_for_session && (_jsx("button", { type: "button", onClick: () => on_answer(entry.id, "allowed_for_session", ""), children: words.allow_for_session(rule_words(permission_rule(entry.tool, entry.input))) })), _jsx("button", { type: "button", className: "danger", onClick: () => on_answer(entry.id, "denied", reason), children: "Deny" })] })] }))] }));
|
|
42
|
+
}
|
|
43
|
+
function Tool({ entry, live }) {
|
|
44
|
+
const running = entry.result === undefined && live;
|
|
45
|
+
return (_jsxs("details", { className: cx("transcript-step transcript-tool", entry.is_error && "failed tone-edge-bad"), children: [_jsxs("summary", { children: [_jsx(Badge, { tone: entry.is_error ? "bad" : "none", children: entry.name }), running && _jsx("span", { className: "status-dot tone-info busy", role: "status", "aria-label": "Running" }), _jsx("code", { className: "transcript-line", children: tool_summary(entry.input) || (entry.input_text ? "…" : "") }), entry.is_error && _jsx("span", { className: "tone-bad small", children: "failed" })] }), _jsx(ToolInput, { name: entry.name, input: entry.input, input_text: entry.input_text }), entry.result !== undefined && _jsx("pre", { className: cx("transcript-code", entry.is_error && "failed"), children: entry.result || "No output." })] }));
|
|
46
|
+
}
|
|
47
|
+
function UserMessage({ entry, labels }) {
|
|
48
|
+
const label = labels[entry.role] ?? entry.role;
|
|
49
|
+
if (entry.role === "input") {
|
|
50
|
+
return (_jsxs("details", { className: "transcript-step", children: [_jsx("summary", { className: "muted", children: label }), _jsx(Markdown, { text: entry.text })] }));
|
|
51
|
+
}
|
|
52
|
+
return (_jsxs("div", { className: "transcript-step transcript-user", children: [_jsxs("div", { className: "small muted", children: [label, " ", entry.pending && _jsx(Badge, { tone: "warn", children: "Not read yet" })] }), _jsx("p", { className: "transcript-text", children: entry.text })] }));
|
|
53
|
+
}
|
|
54
|
+
function Step({ entry, live, labels, on_permission, allow_for_session, words }) {
|
|
55
|
+
if (entry.kind === "thinking")
|
|
56
|
+
return _jsx(Thinking, { entry: entry });
|
|
57
|
+
if (entry.kind === "text")
|
|
58
|
+
return _jsx(Markdown, { text: entry.text, class_name: "transcript-step" });
|
|
59
|
+
if (entry.kind === "tool")
|
|
60
|
+
return _jsx(Tool, { entry: entry, live: live });
|
|
61
|
+
if (entry.kind === "user")
|
|
62
|
+
return _jsx(UserMessage, { entry: entry, labels: labels });
|
|
63
|
+
if (entry.kind === "permission")
|
|
64
|
+
return _jsx(Permission, { entry: entry, on_answer: live ? on_permission : undefined, allow_for_session: allow_for_session, words: words });
|
|
65
|
+
return _jsx("p", { className: cx("transcript-step transcript-notice small", `tone-${entry.tone}`), children: entry.text });
|
|
66
|
+
}
|
|
67
|
+
export function TranscriptView({ entries, live, dropped = 0, empty_text = "Nothing yet.", user_labels, on_permission, allow_for_session = true, permission_words }) {
|
|
68
|
+
const last = entries.at(-1);
|
|
69
|
+
const size = `${entries.length} ${last && "text" in last ? last.text.length : 0} ${last?.kind === "tool" ? `${last.input_text?.length ?? 0} ${last.result?.length ?? 0}` : ""}`;
|
|
70
|
+
const follow = use_follow_tail(size, live);
|
|
71
|
+
const labels = { ...default_user_labels, ...user_labels };
|
|
72
|
+
const words = { ...default_permission_words, ...permission_words };
|
|
73
|
+
return (_jsxs("div", { className: "transcript-frame", children: [_jsxs("div", { ref: follow.ref, className: "transcript", role: "log", "aria-label": "Transcript", "aria-live": live ? "polite" : "off", onScroll: follow.on_scroll, children: [dropped > 0 && _jsxs("p", { className: "muted small", children: [dropped, " earlier steps were left out to keep the transcript within its size."] }), entries.length === 0 ? _jsx("p", { className: "muted", children: empty_text }) : entries.map((entry, index) => _jsx(Step, { entry: entry, live: live, labels: labels, on_permission: on_permission, allow_for_session: allow_for_session, words: words }, index))] }), live && !follow.following && (_jsx("button", { type: "button", className: "transcript-jump", onClick: follow.jump, children: "Jump to Latest" }))] }));
|
|
74
|
+
}
|
|
75
|
+
// A box to write to the agent, sent by its button or Ctrl+Enter.
|
|
76
|
+
export function TranscriptMessageBox({ on_send, placeholder = "Steer the agent; it reads this after its current step", label = "Message to the agent" }) {
|
|
77
|
+
const [text, set_text] = useState("");
|
|
78
|
+
const [sending, set_sending] = useState(false);
|
|
79
|
+
async function send() {
|
|
80
|
+
if (!text.trim() || sending)
|
|
81
|
+
return;
|
|
82
|
+
set_sending(true);
|
|
83
|
+
try {
|
|
84
|
+
if (await on_send(text))
|
|
85
|
+
set_text("");
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
set_sending(false);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return (_jsxs("form", { className: "transcript-message", onSubmit: (event) => {
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
void send();
|
|
94
|
+
}, children: [_jsx("textarea", { "aria-label": label, rows: 2, placeholder: placeholder, value: text, onChange: (event) => set_text(event.currentTarget.value), onKeyDown: (event) => {
|
|
95
|
+
if (event.key === "Enter" && (event.ctrlKey || event.metaKey)) {
|
|
96
|
+
event.preventDefault();
|
|
97
|
+
void send();
|
|
98
|
+
}
|
|
99
|
+
} }), _jsx("button", { type: "submit", className: "accent solid", disabled: !text.trim() || sending, children: "Send" })] }));
|
|
100
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x-tech-laboratories/x-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.118.0",
|
|
4
4
|
"description": "Code the X-apps share: agents and their long runs, passwords and sign-in, the Fastify server pieces, durations, and the web page's helpers and widgets",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"repository": {
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@fastify/formbody": "^9.0.1",
|
|
49
49
|
"@fastify/rate-limit": "^11.2.2",
|
|
50
50
|
"@fastify/session": "^11.1.6",
|
|
51
|
-
"@fastify/static": "^
|
|
51
|
+
"@fastify/static": "^11.0.0",
|
|
52
52
|
"@fastify/websocket": "^11.3.5",
|
|
53
53
|
"@mdx-js/rollup": "^3.1.1",
|
|
54
54
|
"@modelcontextprotocol/client": "^2.4.0",
|
|
@@ -192,7 +192,7 @@
|
|
|
192
192
|
"@fastify/formbody": "^9.0.1",
|
|
193
193
|
"@fastify/rate-limit": "^11.2.2",
|
|
194
194
|
"@fastify/session": "^11.1.6",
|
|
195
|
-
"@fastify/static": "^
|
|
195
|
+
"@fastify/static": "^11.0.0",
|
|
196
196
|
"@fastify/websocket": "^11.3.5",
|
|
197
197
|
"@mdx-js/rollup": "^3.1.1",
|
|
198
198
|
"@modelcontextprotocol/client": "^2.4.0",
|
|
@@ -246,6 +246,7 @@
|
|
|
246
246
|
"@tiptap/starter-kit": "^3.33.0",
|
|
247
247
|
"bonjour-service": "^1.4.4",
|
|
248
248
|
"dayjs": "^1.11.23",
|
|
249
|
+
"diff": "^9.0.0",
|
|
249
250
|
"dompurify": "^3.4.17",
|
|
250
251
|
"drizzle-orm": "1.0.0-rc.6",
|
|
251
252
|
"emojibase": "^18.0.0",
|
|
@@ -257,6 +258,7 @@
|
|
|
257
258
|
"hookable": "^6.1.2",
|
|
258
259
|
"lucide-react": "^1.67.0",
|
|
259
260
|
"marked": "^18.1.3",
|
|
261
|
+
"parse-diff": "^0.12.0",
|
|
260
262
|
"parse-duration": "^2.1.11",
|
|
261
263
|
"pretty-bytes": "^7.2.0",
|
|
262
264
|
"react-error-boundary": "^6.1.6",
|