@softov/ahpc 0.2.0 → 0.4.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 +37 -6
- package/dist/src/ahp/fake.js +61 -14
- package/dist/src/ahp/live.d.ts +7 -0
- package/dist/src/ahp/live.js +156 -43
- package/dist/src/ahp/publish.js +13 -0
- package/dist/src/ahp/types.d.ts +20 -0
- package/dist/src/app.js +34 -7
- package/dist/src/blocks.d.ts +4 -74
- package/dist/src/blocks.js +10 -48
- package/dist/src/cli/main.d.ts +1 -1
- package/dist/src/cli/main.js +109 -6
- package/dist/src/connect.d.ts +2 -0
- package/dist/src/connect.js +1 -0
- package/dist/src/control.d.ts +6 -0
- package/dist/src/control.js +140 -10
- package/dist/src/flags.js +4 -1
- package/dist/src/links.d.ts +54 -0
- package/dist/src/links.js +120 -0
- package/dist/src/main.js +14 -2
- package/dist/src/mcp/http.d.ts +10 -0
- package/dist/src/mcp/http.js +110 -3
- package/dist/src/mcp/serve.d.ts +47 -9
- package/dist/src/mcp/serve.js +65 -14
- package/dist/src/mcp/stdio.d.ts +1 -0
- package/dist/src/mcp/stdio.js +7 -1
- package/dist/src/mcp/tools.d.ts +37 -2
- package/dist/src/mcp/tools.js +439 -2
- package/dist/src/resources.d.ts +13 -0
- package/dist/src/resources.js +46 -0
- package/dist/src/screens.js +95 -50
- package/dist/src/state.d.ts +42 -0
- package/dist/src/state.js +80 -1
- package/dist/src/tui.d.ts +3 -1
- package/dist/src/tui.js +29 -4
- package/dist/src/version.d.ts +2 -0
- package/dist/src/version.js +38 -0
- package/dist/src/view/creature.d.ts +0 -12
- package/dist/src/view/creature.js +0 -20
- package/dist/src/view/wire.d.ts +36 -0
- package/dist/src/view/wire.js +196 -0
- package/dist/src/wait.d.ts +11 -0
- package/dist/src/wait.js +15 -2
- package/dist/src/wire.d.ts +70 -0
- package/dist/src/wire.js +194 -0
- package/dist/src/wiretui.d.ts +22 -0
- package/dist/src/wiretui.js +69 -0
- package/package.json +6 -5
- package/dist/src/diff.d.ts +0 -44
- package/dist/src/diff.js +0 -111
- package/dist/src/view/bubble.d.ts +0 -75
- package/dist/src/view/bubble.js +0 -86
- package/dist/src/view/composer.d.ts +0 -64
- package/dist/src/view/composer.js +0 -192
- package/dist/src/view/controls.d.ts +0 -44
- package/dist/src/view/controls.js +0 -49
- package/dist/src/view/details.d.ts +0 -65
- package/dist/src/view/details.js +0 -65
- package/dist/src/view/filediff.d.ts +0 -29
- package/dist/src/view/filediff.js +0 -24
- package/dist/src/view/hitl.d.ts +0 -43
- package/dist/src/view/hitl.js +0 -171
- package/dist/src/view/icons.d.ts +0 -13
- package/dist/src/view/icons.js +0 -71
- package/dist/src/view/picker.d.ts +0 -42
- package/dist/src/view/picker.js +0 -71
- package/dist/src/view/sessionhead.d.ts +0 -41
- package/dist/src/view/sessionhead.js +0 -60
- package/dist/src/view/sessions.d.ts +0 -34
- package/dist/src/view/sessions.js +0 -61
- package/dist/src/view/toolcall.d.ts +0 -27
- package/dist/src/view/toolcall.js +0 -48
- package/dist/src/view/transcript.d.ts +0 -50
- package/dist/src/view/transcript.js +0 -60
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softov/ahpc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A terminal client for the Agent Host Protocol: sessions, a streaming transcript, and interactive prompts",
|
|
6
6
|
"keywords": [
|
|
@@ -54,12 +54,13 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@microsoft/agent-host-protocol": "^0.9.0",
|
|
57
|
-
"@textui/
|
|
58
|
-
"@textui/
|
|
59
|
-
"@textui/
|
|
57
|
+
"@textui/chat": "^0.6.1",
|
|
58
|
+
"@textui/core": "^0.6.1",
|
|
59
|
+
"@textui/terminal": "^0.6.1",
|
|
60
|
+
"@textui/widgets": "^0.6.1"
|
|
60
61
|
},
|
|
61
62
|
"devDependencies": {
|
|
62
|
-
"@textui/testing": "^0.
|
|
63
|
+
"@textui/testing": "^0.6.1",
|
|
63
64
|
"@types/node": "^22.10.2",
|
|
64
65
|
"ajv": "^8.17.1",
|
|
65
66
|
"ajv-formats": "^3.0.1",
|
package/dist/src/diff.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A line diff, small enough to read.
|
|
3
|
-
*
|
|
4
|
-
* The host sends two whole files and a count of what changed between them; it
|
|
5
|
-
* does not send the diff itself, so somebody has to work out which lines those
|
|
6
|
-
* were. This is that, and it is deliberately the textbook algorithm rather
|
|
7
|
-
* than anything clever: the longest common subsequence of the two line arrays,
|
|
8
|
-
* with everything not in it marked as removed on the left or added on the
|
|
9
|
-
* right.
|
|
10
|
-
*
|
|
11
|
-
* The cost is quadratic in the number of lines, which is why `diffLines` takes
|
|
12
|
-
* a ceiling. Two files of ten thousand lines each is a hundred million cells
|
|
13
|
-
* and a terminal that stops answering, and the honest answer at that size is
|
|
14
|
-
* to say the files are too big rather than to spend a minute proving it.
|
|
15
|
-
*/
|
|
16
|
-
export type DiffKind = 'same' | 'added' | 'removed';
|
|
17
|
-
export interface DiffRow {
|
|
18
|
-
kind: DiffKind;
|
|
19
|
-
/** 1-based, on the side this row exists on. Absent on the side it does not. */
|
|
20
|
-
before?: number;
|
|
21
|
-
after?: number;
|
|
22
|
-
text: string;
|
|
23
|
-
}
|
|
24
|
-
export interface DiffResult {
|
|
25
|
-
rows: DiffRow[];
|
|
26
|
-
added: number;
|
|
27
|
-
removed: number;
|
|
28
|
-
/** Set instead of a diff when the pair was over `limit`. */
|
|
29
|
-
tooLarge?: {
|
|
30
|
-
lines: number;
|
|
31
|
-
limit: number;
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
/** Lines of a file, with the trailing newline not counted as an empty last line. */
|
|
35
|
-
export declare function toLines(text: string): string[];
|
|
36
|
-
/**
|
|
37
|
-
* The two sides, lined up.
|
|
38
|
-
*
|
|
39
|
-
* A creation has no `before` and a deletion no `after`; both are passed as an
|
|
40
|
-
* empty string rather than as a special case, because "every line is an
|
|
41
|
-
* addition" is exactly the right diff for a new file and needs no branch of
|
|
42
|
-
* its own.
|
|
43
|
-
*/
|
|
44
|
-
export declare function diffLines(before: string, after: string, limit?: number): DiffResult;
|
package/dist/src/diff.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A line diff, small enough to read.
|
|
3
|
-
*
|
|
4
|
-
* The host sends two whole files and a count of what changed between them; it
|
|
5
|
-
* does not send the diff itself, so somebody has to work out which lines those
|
|
6
|
-
* were. This is that, and it is deliberately the textbook algorithm rather
|
|
7
|
-
* than anything clever: the longest common subsequence of the two line arrays,
|
|
8
|
-
* with everything not in it marked as removed on the left or added on the
|
|
9
|
-
* right.
|
|
10
|
-
*
|
|
11
|
-
* The cost is quadratic in the number of lines, which is why `diffLines` takes
|
|
12
|
-
* a ceiling. Two files of ten thousand lines each is a hundred million cells
|
|
13
|
-
* and a terminal that stops answering, and the honest answer at that size is
|
|
14
|
-
* to say the files are too big rather than to spend a minute proving it.
|
|
15
|
-
*/
|
|
16
|
-
/** Lines of a file, with the trailing newline not counted as an empty last line. */
|
|
17
|
-
export function toLines(text) {
|
|
18
|
-
if (text === '')
|
|
19
|
-
return [];
|
|
20
|
-
const lines = text.split('\n');
|
|
21
|
-
if (lines[lines.length - 1] === '')
|
|
22
|
-
lines.pop();
|
|
23
|
-
return lines;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* The two sides, lined up.
|
|
27
|
-
*
|
|
28
|
-
* A creation has no `before` and a deletion no `after`; both are passed as an
|
|
29
|
-
* empty string rather than as a special case, because "every line is an
|
|
30
|
-
* addition" is exactly the right diff for a new file and needs no branch of
|
|
31
|
-
* its own.
|
|
32
|
-
*/
|
|
33
|
-
export function diffLines(before, after, limit = 4000) {
|
|
34
|
-
const a = toLines(before);
|
|
35
|
-
const b = toLines(after);
|
|
36
|
-
if (a.length + b.length > limit) {
|
|
37
|
-
return { rows: [], added: 0, removed: 0, tooLarge: { lines: a.length + b.length, limit } };
|
|
38
|
-
}
|
|
39
|
-
// The common head and tail first. Two files that differ in one line share
|
|
40
|
-
// everything either side of it, and taking those off shrinks the table the
|
|
41
|
-
// quadratic part has to fill to the part that actually differs.
|
|
42
|
-
let head = 0;
|
|
43
|
-
while (head < a.length && head < b.length && a[head] === b[head])
|
|
44
|
-
head++;
|
|
45
|
-
let tail = 0;
|
|
46
|
-
while (tail < a.length - head
|
|
47
|
-
&& tail < b.length - head
|
|
48
|
-
&& a[a.length - 1 - tail] === b[b.length - 1 - tail])
|
|
49
|
-
tail++;
|
|
50
|
-
const midA = a.slice(head, a.length - tail);
|
|
51
|
-
const midB = b.slice(head, b.length - tail);
|
|
52
|
-
const table = lcs(midA, midB);
|
|
53
|
-
const rows = [];
|
|
54
|
-
let added = 0;
|
|
55
|
-
let removed = 0;
|
|
56
|
-
const push = (kind, text, ai, bi) => {
|
|
57
|
-
rows.push({
|
|
58
|
-
kind,
|
|
59
|
-
...(kind !== 'added' ? { before: ai + 1 } : {}),
|
|
60
|
-
...(kind !== 'removed' ? { after: bi + 1 } : {}),
|
|
61
|
-
text,
|
|
62
|
-
});
|
|
63
|
-
if (kind === 'added')
|
|
64
|
-
added++;
|
|
65
|
-
if (kind === 'removed')
|
|
66
|
-
removed++;
|
|
67
|
-
};
|
|
68
|
-
for (let i = 0; i < head; i++)
|
|
69
|
-
push('same', a[i], i, i);
|
|
70
|
-
// Walking the table forwards, so the rows come out in file order.
|
|
71
|
-
let i = 0;
|
|
72
|
-
let j = 0;
|
|
73
|
-
while (i < midA.length || j < midB.length) {
|
|
74
|
-
if (i < midA.length && j < midB.length && midA[i] === midB[j]) {
|
|
75
|
-
push('same', midA[i], head + i, head + j);
|
|
76
|
-
i++;
|
|
77
|
-
j++;
|
|
78
|
-
// A tie goes to the removal, so a replaced line reads `-old` then `+new`
|
|
79
|
-
// the way every other diff on the machine prints it. With `>=` here the
|
|
80
|
-
// pair comes out the other way round, which is not wrong so much as
|
|
81
|
-
// unreadable next to `git diff`.
|
|
82
|
-
}
|
|
83
|
-
else if (j < midB.length && (i === midA.length || (table[i]?.[j + 1] ?? 0) > (table[i + 1]?.[j] ?? 0))) {
|
|
84
|
-
push('added', midB[j], head + i, head + j);
|
|
85
|
-
j++;
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
push('removed', midA[i], head + i, head + j);
|
|
89
|
-
i++;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
for (let k = 0; k < tail; k++) {
|
|
93
|
-
push('same', a[a.length - tail + k], a.length - tail + k, b.length - tail + k);
|
|
94
|
-
}
|
|
95
|
-
return { rows, added, removed };
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* `table[i][j]` is the length of the longest common subsequence of `a[i..]`
|
|
99
|
-
* and `b[j..]`, filled from the end so the walk above can go forwards.
|
|
100
|
-
*/
|
|
101
|
-
function lcs(a, b) {
|
|
102
|
-
const table = Array.from({ length: a.length + 1 }, () => new Array(b.length + 1).fill(0));
|
|
103
|
-
for (let i = a.length - 1; i >= 0; i--) {
|
|
104
|
-
for (let j = b.length - 1; j >= 0; j--) {
|
|
105
|
-
table[i][j] = a[i] === b[j]
|
|
106
|
-
? (table[i + 1]?.[j + 1] ?? 0) + 1
|
|
107
|
-
: Math.max(table[i + 1]?.[j] ?? 0, table[i]?.[j + 1] ?? 0);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return table;
|
|
111
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type { BoxProps, RenderOutput, SemanticVariant } from '@textui/core';
|
|
2
|
-
/**
|
|
3
|
-
* One thing said, and the two ways it is still being said.
|
|
4
|
-
*
|
|
5
|
-
* A bubble in a terminal is not a rounded rectangle. It is a gutter that says
|
|
6
|
-
* who is speaking and a body that owns the rest of the width - because the
|
|
7
|
-
* width is 80 cells and half of it spent on alignment is half the conversation
|
|
8
|
-
* gone.
|
|
9
|
-
*/
|
|
10
|
-
export type Speaker = 'user' | 'agent' | 'system';
|
|
11
|
-
/**
|
|
12
|
-
* The rule down the left of everything one speaker said.
|
|
13
|
-
*
|
|
14
|
-
* A box that fills rather than a `text`: the text is one row tall and the
|
|
15
|
-
* paragraph beside it is nine, so a rule written as a character marks the
|
|
16
|
-
* first line of a wrapped answer and abandons the rest of it.
|
|
17
|
-
*/
|
|
18
|
-
export declare const Gutter: (props: BoxProps) => RenderOutput;
|
|
19
|
-
export interface ChatBubbleProps extends BoxProps {
|
|
20
|
-
speaker: Speaker;
|
|
21
|
-
/** The name, when the speaker is not enough: a model, a person, a host. */
|
|
22
|
-
author?: string;
|
|
23
|
-
/** Right of the author line: a time, a duration, a model. */
|
|
24
|
-
meta?: string;
|
|
25
|
-
tone?: SemanticVariant;
|
|
26
|
-
/** The transcript's cursor is on this block. */
|
|
27
|
-
active?: boolean;
|
|
28
|
-
children?: unknown;
|
|
29
|
-
}
|
|
30
|
-
export declare const ChatBubble: (props: ChatBubbleProps) => RenderOutput;
|
|
31
|
-
export interface StreamingTextProps extends BoxProps {
|
|
32
|
-
content: string;
|
|
33
|
-
/** Still arriving. Draws a caret and keeps it on the last word. */
|
|
34
|
-
streaming?: boolean;
|
|
35
|
-
quiet?: boolean;
|
|
36
|
-
maxLines?: number;
|
|
37
|
-
/**
|
|
38
|
-
* Draw it as markdown, or as the characters that arrived.
|
|
39
|
-
*
|
|
40
|
-
* Unstated it follows the application's own switch, which is what the key
|
|
41
|
-
* that toggles it moves - so a caller has to say something here only when
|
|
42
|
-
* it wants one or the other regardless.
|
|
43
|
-
*/
|
|
44
|
-
markdown?: boolean;
|
|
45
|
-
/** Text to pick out, for the find box. Coloured wherever it appears. */
|
|
46
|
-
match?: string;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Text that is still being said.
|
|
50
|
-
*
|
|
51
|
-
* The caret is part of the content rather than a node beside it, because a
|
|
52
|
-
* caret placed after the block sits under the last line instead of at the end
|
|
53
|
-
* of it - and the end of the sentence is the only place it means anything.
|
|
54
|
-
*
|
|
55
|
-
* It blinks on the theme's own ticker, so animation being off (a pipe, a test,
|
|
56
|
-
* a `--static` capture) leaves a steady caret rather than a missing one.
|
|
57
|
-
*/
|
|
58
|
-
export declare const StreamingText: (props: StreamingTextProps) => RenderOutput;
|
|
59
|
-
export interface ReasoningBlockProps extends BoxProps {
|
|
60
|
-
/** Text to pick out, for the find box. Handed to the text inside it. */
|
|
61
|
-
match?: string;
|
|
62
|
-
content: string;
|
|
63
|
-
expanded?: boolean;
|
|
64
|
-
streaming?: boolean;
|
|
65
|
-
/** Shown collapsed: "thought for 12s". */
|
|
66
|
-
summary?: string;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* What the agent was thinking, folded away.
|
|
70
|
-
*
|
|
71
|
-
* Reasoning is prose the host sends like any other, and it is not what the
|
|
72
|
-
* reader came for - so it is one row until it is asked for. Dropping it
|
|
73
|
-
* instead loses the only account of *why* a turn did what it did.
|
|
74
|
-
*/
|
|
75
|
-
export declare const ReasoningBlock: (props: ReasoningBlockProps) => RenderOutput;
|
package/dist/src/view/bubble.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "@textui/core/jsx-runtime";
|
|
2
|
-
import { defineComponent, useFrame, useStoreValue, useTheme } from '@textui/core';
|
|
3
|
-
import { Column, MarkdownView, Row } from '@textui/widgets';
|
|
4
|
-
import { MARKDOWN } from '../state.js';
|
|
5
|
-
/**
|
|
6
|
-
* The rule down the left of everything one speaker said.
|
|
7
|
-
*
|
|
8
|
-
* A box that fills rather than a `text`: the text is one row tall and the
|
|
9
|
-
* paragraph beside it is nine, so a rule written as a character marks the
|
|
10
|
-
* first line of a wrapped answer and abandons the rest of it.
|
|
11
|
-
*/
|
|
12
|
-
export const Gutter = defineComponent('ChatGutter', (props) => {
|
|
13
|
-
const theme = useTheme();
|
|
14
|
-
// `alignSelf` because `Row` centres its children: a one-cell box in a
|
|
15
|
-
// centred row is one cell tall, wherever the rule was meant to reach.
|
|
16
|
-
return _jsx("box", { width: 1, alignSelf: "stretch", fill: theme.borderChars().left, fg: "borderSubtle", ...props });
|
|
17
|
-
});
|
|
18
|
-
const SPEAKER = {
|
|
19
|
-
user: { fg: 'primary', label: 'you' },
|
|
20
|
-
agent: { fg: 'accent', label: 'agent' },
|
|
21
|
-
system: { fg: 'muted', label: 'system' },
|
|
22
|
-
};
|
|
23
|
-
export const ChatBubble = defineComponent('ChatBubble', (props) => {
|
|
24
|
-
const { speaker, author, meta, tone, active, children, ...rest } = props;
|
|
25
|
-
const theme = useTheme();
|
|
26
|
-
const look = SPEAKER[speaker];
|
|
27
|
-
const glyph = speaker === 'user' ? theme.glyphs.chevronRight
|
|
28
|
-
: speaker === 'agent' ? theme.glyphs.bulletFilled
|
|
29
|
-
: theme.glyphs.info;
|
|
30
|
-
// The gutter is one column of glyph and one of rule. It is what makes a
|
|
31
|
-
// wrapped paragraph read as one person talking rather than as the page
|
|
32
|
-
// starting again, and it survives losing colour - which a tinted
|
|
33
|
-
// background does not.
|
|
34
|
-
return (_jsxs(Column, { ...rest, ...(active ? { bg: 'selected' } : {}), children: [_jsxs(Row, { gap: 1, children: [_jsx("text", { content: glyph, fg: tone ?? look.fg }), _jsx("text", { content: author ?? look.label, bold: true, fg: tone ?? look.fg }), meta ? _jsx("text", { content: meta, fg: "subtle", flex: 1, truncate: "end" }) : _jsx("text", { content: "", flex: 1 })] }), _jsxs(Row, { gap: 1, flex: 1, children: [_jsx(Gutter, {}), _jsx(Column, { flex: 1, gap: 1, children: children })] })] }));
|
|
35
|
-
});
|
|
36
|
-
/**
|
|
37
|
-
* Text that is still being said.
|
|
38
|
-
*
|
|
39
|
-
* The caret is part of the content rather than a node beside it, because a
|
|
40
|
-
* caret placed after the block sits under the last line instead of at the end
|
|
41
|
-
* of it - and the end of the sentence is the only place it means anything.
|
|
42
|
-
*
|
|
43
|
-
* It blinks on the theme's own ticker, so animation being off (a pipe, a test,
|
|
44
|
-
* a `--static` capture) leaves a steady caret rather than a missing one.
|
|
45
|
-
*/
|
|
46
|
-
export const StreamingText = defineComponent('StreamingText', (props) => {
|
|
47
|
-
const { content, streaming, quiet, maxLines, markdown, match, ...rest } = props;
|
|
48
|
-
const theme = useTheme();
|
|
49
|
-
// Only while something is arriving. A ticker marks its component dirty
|
|
50
|
-
// whether or not the frame it produces differs, so an unconditional one
|
|
51
|
-
// here meant every settled paragraph in the transcript asked the
|
|
52
|
-
// application to redraw twice a second, for ever - a conversation that
|
|
53
|
-
// got heavier to sit in the longer it got.
|
|
54
|
-
const frame = useFrame(2, { enabled: streaming === true });
|
|
55
|
-
const caret = streaming && frame % 2 === 0 ? theme.glyphs.caret : '';
|
|
56
|
-
// Read unconditionally: `??` short-circuits, and a hook that is only
|
|
57
|
-
// reached when a prop is absent is a hook that changes position between
|
|
58
|
-
// renders. The prop still wins - it is just decided after the read.
|
|
59
|
-
const preference = useStoreValue(MARKDOWN, true) ?? true;
|
|
60
|
-
const rendered = markdown ?? preference;
|
|
61
|
-
const shown = streaming ? `${content}${caret}` : content;
|
|
62
|
-
// Raw is a `text`, not a `MarkdownView` that was told not to parse: the
|
|
63
|
-
// point of turning it off is to see the characters that arrived, and
|
|
64
|
-
// anything that lays the document out has already decided some of them
|
|
65
|
-
// were structure. `wrap` rather than truncate, because the lines being
|
|
66
|
-
// read are the long ones - a fenced block and a table are exactly what is
|
|
67
|
-
// wider than the pane.
|
|
68
|
-
if (!rendered) {
|
|
69
|
-
return (_jsx("text", { content: shown, wrap: "word", ...(quiet ? { fg: 'muted' } : {}), ...(match ? { match } : {}), ...rest }));
|
|
70
|
-
}
|
|
71
|
-
return (_jsx(MarkdownView, { content: shown, ...(quiet ? { quiet: true } : {}), ...(maxLines !== undefined ? { maxLines } : {}), ...(match ? { match } : {}), ...rest }));
|
|
72
|
-
});
|
|
73
|
-
/**
|
|
74
|
-
* What the agent was thinking, folded away.
|
|
75
|
-
*
|
|
76
|
-
* Reasoning is prose the host sends like any other, and it is not what the
|
|
77
|
-
* reader came for - so it is one row until it is asked for. Dropping it
|
|
78
|
-
* instead loses the only account of *why* a turn did what it did.
|
|
79
|
-
*/
|
|
80
|
-
export const ReasoningBlock = defineComponent('ReasoningBlock', (props) => {
|
|
81
|
-
const { content, expanded, streaming, summary, match, ...rest } = props;
|
|
82
|
-
const theme = useTheme();
|
|
83
|
-
const chevron = expanded ? theme.glyphs.chevronDown : theme.glyphs.chevronRight;
|
|
84
|
-
const words = content.trim().split(/\s+/).filter(Boolean).length;
|
|
85
|
-
return (_jsxs(Column, { ...rest, children: [_jsxs(Row, { gap: 1, children: [_jsx("text", { content: chevron, fg: "subtle" }), _jsx("text", { content: summary ?? (streaming ? 'thinking' : `thought, ${words} words`), fg: "subtle", italic: true })] }), expanded ? (_jsxs(Row, { gap: 1, children: [_jsx("text", { content: " " }), _jsx(StreamingText, { content: content, quiet: true, flex: 1, ...(streaming ? { streaming: true } : {}), ...(match ? { match } : {}) })] })) : null] }));
|
|
86
|
-
});
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { BoxProps, RenderOutput } from '@textui/core';
|
|
2
|
-
import type { Completion, SlashCommand } from '../ahp/types.js';
|
|
3
|
-
import type { ComposerOption } from './controls.js';
|
|
4
|
-
/**
|
|
5
|
-
* What you type, and one line saying what it will be sent as.
|
|
6
|
-
*
|
|
7
|
-
* The field itself is `TextArea` from the catalog - growing, scrolling and
|
|
8
|
-
* giving back the keys it does not want is not a chat problem. What is here is
|
|
9
|
-
* the rest of a composer: what enter means while a turn is running, the slash
|
|
10
|
-
* menu over what has already been typed, and the control row.
|
|
11
|
-
*
|
|
12
|
-
* The row used to be four ghost buttons naming their own keys - `send enter`,
|
|
13
|
-
* `newline alt+enter`, `stop ctrl+c`, `commands ctrl+p` - which spent the one
|
|
14
|
-
* line under the field on a keyboard legend. The keys belong in the footer,
|
|
15
|
-
* which already lists them and changes with where the focus is. The line under
|
|
16
|
-
* the field is worth more as *what is about to happen*: which harness, which
|
|
17
|
-
* model, what it may do without asking, where it runs.
|
|
18
|
-
*/
|
|
19
|
-
export interface ChatComposerProps extends BoxProps {
|
|
20
|
-
value: string;
|
|
21
|
-
onChange(value: string): void;
|
|
22
|
-
onSubmit(value: string): void;
|
|
23
|
-
onCancel?(): void;
|
|
24
|
-
onHistory?(direction: -1 | 1): void;
|
|
25
|
-
/** Left off the front of the field: out of the composer entirely. */
|
|
26
|
-
onLeave?(): void;
|
|
27
|
-
/** A turn is running: enter queues rather than sends, and stop is offered. */
|
|
28
|
-
running?: boolean;
|
|
29
|
-
queued?: number;
|
|
30
|
-
/** The control row. Each is a value, and each may open a picker. */
|
|
31
|
-
options?: ComposerOption[];
|
|
32
|
-
onOption?(option: ComposerOption, anchorId: string): void;
|
|
33
|
-
placeholder?: string;
|
|
34
|
-
/** Offered when the draft starts with a slash. */
|
|
35
|
-
commands?: SlashCommand[];
|
|
36
|
-
/**
|
|
37
|
-
* One of `commands` was chosen from the slash menu.
|
|
38
|
-
*
|
|
39
|
-
* The whole command rather than its id, because the two kinds go different
|
|
40
|
-
* places and only the command knows which it is. A `client` command is
|
|
41
|
-
* *ours*: it opens a screen, changes a setting or picks a theme, and none of
|
|
42
|
-
* that is a message - sending it down the session channel would put
|
|
43
|
-
* "/theme" in the transcript and ask the agent to make sense of it. A
|
|
44
|
-
* `session` command is a skill the host contributed, and the only way to
|
|
45
|
-
* invoke one is to send its name as the message.
|
|
46
|
-
*
|
|
47
|
-
* A slash the menu does not match is left alone and sent, which is how a
|
|
48
|
-
* command the host offers but did not list still reaches it.
|
|
49
|
-
*/
|
|
50
|
-
onCommand?(command: SlashCommand): void;
|
|
51
|
-
/**
|
|
52
|
-
* What the host offers to complete the word the caret is in.
|
|
53
|
-
*
|
|
54
|
-
* Fetched rather than filtered: a path is a path on the *host's*
|
|
55
|
-
* filesystem, so which of them match what has been typed is a question only
|
|
56
|
-
* it can answer, and the answer changes with every keystroke.
|
|
57
|
-
*/
|
|
58
|
-
paths?: Completion[];
|
|
59
|
-
/** One of `paths` was chosen. The range it replaces is on the completion. */
|
|
60
|
-
onPath?(path: Completion): void;
|
|
61
|
-
autoFocus?: boolean;
|
|
62
|
-
focusId?: string;
|
|
63
|
-
}
|
|
64
|
-
export declare const ChatComposer: (props: ChatComposerProps) => RenderOutput;
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "@textui/core/jsx-runtime";
|
|
2
|
-
import { defineComponent, useEffect, useMeasure, useSize, useState, useTheme } from '@textui/core';
|
|
3
|
-
import { Column, Divider, List, TextArea } from '@textui/widgets';
|
|
4
|
-
import { ComposerBar } from './controls.js';
|
|
5
|
-
import { useFloorTop } from './creature.js';
|
|
6
|
-
/**
|
|
7
|
-
* Rows the completion menu shows at once, at most.
|
|
8
|
-
*
|
|
9
|
-
* A cap on the box's height and not on the list: what does not fit is
|
|
10
|
-
* scrolled to. The menu sits above the composer and takes its room from it,
|
|
11
|
-
* so on a short terminal this is not the number that applies - see `fits`.
|
|
12
|
-
*/
|
|
13
|
-
const VISIBLE = 8;
|
|
14
|
-
/**
|
|
15
|
-
* Rows the composer itself takes: two border, two divider, the field and the
|
|
16
|
-
* bar under it. Eight menu rows on a terminal twelve high left four for all
|
|
17
|
-
* of that and drew an empty box - a menu on top of a field with no room to
|
|
18
|
-
* type in it.
|
|
19
|
-
*/
|
|
20
|
-
const COMPOSER_ROWS = 6;
|
|
21
|
-
/** The menu's own frame, which is height the list does not get. */
|
|
22
|
-
const MENU_BORDER = 2;
|
|
23
|
-
/**
|
|
24
|
-
* Rows the menu may have here, which is whatever the composer can spare.
|
|
25
|
-
*
|
|
26
|
-
* The floor is there because a terminal can always be made too short for
|
|
27
|
-
* both; below it the composer gives way, since a menu with nothing under it
|
|
28
|
-
* is the same dead end from the other side.
|
|
29
|
-
*/
|
|
30
|
-
const fits = (height) => Math.max(3, Math.min(VISIBLE, height - COMPOSER_ROWS - MENU_BORDER));
|
|
31
|
-
export const ChatComposer = defineComponent('ChatComposer', (props) => {
|
|
32
|
-
const { value, onChange, onSubmit, onCancel, onHistory, onLeave, running, queued = 0, options = [], onOption, placeholder, commands = [], onCommand, paths = [], onPath, autoFocus, focusId = 'chat.composer', ...rest } = props;
|
|
33
|
-
const theme = useTheme();
|
|
34
|
-
// A slash menu is a completion over what is already typed, not a mode.
|
|
35
|
-
const slash = value.startsWith('/') && !value.includes(' ') ? value.slice(1).toLowerCase() : null;
|
|
36
|
-
const found = slash === null ? [] : commands
|
|
37
|
-
.filter((command) => command.id.toLowerCase().includes(slash) || command.title.toLowerCase().includes(slash))
|
|
38
|
-
// What the host contributed first. A person typing a slash into a chat
|
|
39
|
-
// is usually reaching for a skill, and the client's own commands - which
|
|
40
|
-
// are also in the palette, on their own key - would otherwise fill the
|
|
41
|
-
// rows that are visible without scrolling.
|
|
42
|
-
.sort((a, b) => (a.kind === b.kind ? 0 : a.kind === 'session' ? -1 : 1));
|
|
43
|
-
const byId = new Map(found.map((command) => [command.id, command]));
|
|
44
|
-
/*
|
|
45
|
-
* One menu, and whichever list is live fills it.
|
|
46
|
-
*
|
|
47
|
-
* The two cannot both be: a slash menu is a draft that *starts* with a
|
|
48
|
-
* slash, and a path menu is a word the caret is in that starts with an
|
|
49
|
-
* at-sign. Two menus would be two boxes above one field.
|
|
50
|
-
*/
|
|
51
|
-
const offered = found.length > 0
|
|
52
|
-
? found.map((command) => ({
|
|
53
|
-
id: command.id,
|
|
54
|
-
label: `/${command.id}`,
|
|
55
|
-
...(command.description ? { description: command.description } : {}),
|
|
56
|
-
// Where it came from, when something did: two plugins can contribute
|
|
57
|
-
// a `/review`, and the title alone does not say which this is.
|
|
58
|
-
meta: command.from ?? command.title,
|
|
59
|
-
}))
|
|
60
|
-
: paths.map((path) => ({
|
|
61
|
-
id: path.insertText,
|
|
62
|
-
label: path.insertText,
|
|
63
|
-
...(path.description ? { description: path.description } : {}),
|
|
64
|
-
}));
|
|
65
|
-
const byInsert = new Map(paths.map((path) => [path.insertText, path]));
|
|
66
|
-
/*
|
|
67
|
-
* Escape closes the menu before it does anything else.
|
|
68
|
-
*
|
|
69
|
-
* The menu is drawn from the draft, so there is no state to close - which
|
|
70
|
-
* is why escape used to pass straight through it to the field and then to
|
|
71
|
-
* the screen, and typing `/` and pressing escape left for the session
|
|
72
|
-
* list. What is remembered is the draft it was dismissed at: the menu
|
|
73
|
-
* stays shut for that exact text and comes back the moment another
|
|
74
|
-
* character makes it a different question.
|
|
75
|
-
*
|
|
76
|
-
* And it is forgotten as soon as there is no menu to dismiss. Remembering
|
|
77
|
-
* the text alone was not enough: dismissing at `/`, deleting it and typing
|
|
78
|
-
* `/` again produced the same draft, so the menu stayed shut for a
|
|
79
|
-
* question that had been asked afresh. Clearing when nothing matches ties
|
|
80
|
-
* the dismissal to one continuous menu rather than to a string that can
|
|
81
|
-
* come back.
|
|
82
|
-
*/
|
|
83
|
-
const [dismissedAt, setDismissedAt] = useState(null);
|
|
84
|
-
const empty = offered.length === 0;
|
|
85
|
-
useEffect(() => {
|
|
86
|
-
if (empty && dismissedAt !== null)
|
|
87
|
-
setDismissedAt(null);
|
|
88
|
-
}, [empty]);
|
|
89
|
-
const matches = dismissedAt === value ? [] : offered;
|
|
90
|
-
// Which completion is under the cursor. Clamped rather than reset, so a
|
|
91
|
-
// list that shrinks as more is typed keeps a valid row instead of
|
|
92
|
-
// snapping back to the top on every keystroke.
|
|
93
|
-
const [highlight, setHighlight] = useState(0);
|
|
94
|
-
const index = Math.max(0, Math.min(highlight, matches.length - 1));
|
|
95
|
-
const chosen = matches[index];
|
|
96
|
-
/*
|
|
97
|
-
* What goes after the name of the command under the cursor.
|
|
98
|
-
*
|
|
99
|
-
* A row is the name, so a command that takes an argument has nowhere in
|
|
100
|
-
* the list to say so, and `/autocompact` reads as complete when it is
|
|
101
|
-
* not. It goes on the rule under the list, where it is one line for the
|
|
102
|
-
* whole menu and changes as the highlight moves rather than being
|
|
103
|
-
* repeated down every row.
|
|
104
|
-
*/
|
|
105
|
-
const usage = chosen === undefined ? undefined : byId.get(chosen.id)?.hint;
|
|
106
|
-
const hint = usage === undefined ? undefined : `/${chosen?.id ?? ''} ${usage}`;
|
|
107
|
-
/**
|
|
108
|
-
* Up and down, while the menu is open.
|
|
109
|
-
*
|
|
110
|
-
* They arrive as `onOverflow` - the field reports the key rather than
|
|
111
|
-
* handling it once there is no row above or below the caret, which for a
|
|
112
|
-
* `/word` draft is immediately. The same pair walks the history when there
|
|
113
|
-
* is no menu, and the menu is the nearer of the two things they could
|
|
114
|
-
* mean.
|
|
115
|
-
*/
|
|
116
|
-
const step = (direction) => {
|
|
117
|
-
setHighlight((matches.length + index + direction) % matches.length);
|
|
118
|
-
};
|
|
119
|
-
// Where this box starts, so the creature has somewhere to stand that is
|
|
120
|
-
// not on it. The slash menu grows this upward, so it is read every time
|
|
121
|
-
// rather than being a number somebody wrote down once.
|
|
122
|
-
useFloorTop('composer', useMeasure().y);
|
|
123
|
-
// How tall the menu may be here. Read unconditionally: it is a hook, and
|
|
124
|
-
// the menu is drawn from a branch.
|
|
125
|
-
const rows = fits(useSize().height);
|
|
126
|
-
return (_jsxs(Column, { ...rest, gap: 0, children: [matches.length > 0 ? (
|
|
127
|
-
// The theme's border, never a named one. A hardcoded `single` draws
|
|
128
|
-
// a box-drawing frame inside an ascii one on a terminal that cannot
|
|
129
|
-
// do either, and an airy theme gets a line it deliberately does not
|
|
130
|
-
// draw anywhere else.
|
|
131
|
-
_jsxs(Column, { border: theme.border, padding: [0, 1], children: [_jsx(List, { items: matches, focusable: false, selectedId: chosen?.id,
|
|
132
|
-
/*
|
|
133
|
-
* A window over all of them, not the first six.
|
|
134
|
-
*
|
|
135
|
-
* The list scrolls to keep the selected row in view, and the
|
|
136
|
-
* selection here is driven from outside - so walking past the
|
|
137
|
-
* sixth moves the window rather than stopping. Truncating the
|
|
138
|
-
* items instead made up and down cycle the six that survived,
|
|
139
|
-
* with no way to reach a seventh: a host that answers thirty
|
|
140
|
-
* paths for `@src/` offered six of them and looked like it had
|
|
141
|
-
* no more.
|
|
142
|
-
*/
|
|
143
|
-
visibleRows: hint === undefined ? rows : rows - 1, marker: true,
|
|
144
|
-
// Not focusable, so this is the click: a completion clicked is a
|
|
145
|
-
// completion chosen, and there is nowhere for a merely
|
|
146
|
-
// highlighted row to lead.
|
|
147
|
-
onSelect: (id) => {
|
|
148
|
-
const command = byId.get(id);
|
|
149
|
-
if (command) {
|
|
150
|
-
onCommand?.(command);
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
const path = byInsert.get(id);
|
|
154
|
-
if (path)
|
|
155
|
-
onPath?.(path);
|
|
156
|
-
}, emptyMessage: "no command" }), hint === undefined ? null : _jsx(Divider, { label: hint })] })) : null, _jsxs(Column, { border: theme.border, children: [_jsx(Divider, { dim: true }), _jsx(TextArea, { value: value, onChange: onChange,
|
|
157
|
-
// A slash the menu matched runs here; anything else is a message,
|
|
158
|
-
// which is what lets a command the agent offers through.
|
|
159
|
-
onSubmit: (next) => {
|
|
160
|
-
const command = chosen ? byId.get(chosen.id) : undefined;
|
|
161
|
-
if (command && onCommand) {
|
|
162
|
-
onCommand(command);
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
// A highlighted path completes rather than sends: enter on a
|
|
166
|
-
// menu row means "that one", and a draft half-way through a
|
|
167
|
-
// path is not a message anybody meant to send.
|
|
168
|
-
const path = chosen ? byInsert.get(chosen.id) : undefined;
|
|
169
|
-
if (path && onPath) {
|
|
170
|
-
onPath(path);
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
onSubmit(next);
|
|
174
|
-
}, onCancel: () => {
|
|
175
|
-
if (matches.length > 0) {
|
|
176
|
-
setDismissedAt(value);
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
onCancel?.();
|
|
180
|
-
}, onOverflow: (direction) => {
|
|
181
|
-
if (matches.length > 0) {
|
|
182
|
-
step(direction);
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
onHistory?.(direction);
|
|
186
|
-
}, ...(onLeave ? { onEdge: (edge) => { if (edge === 'start')
|
|
187
|
-
onLeave(); } } : {}), placeholder: placeholder
|
|
188
|
-
?? (running ? 'The agent is working. Type to queue a message.' : 'Ask the agent anything…'), focusId: focusId,
|
|
189
|
-
// The caret is the one thing on this screen saying where typing
|
|
190
|
-
// goes, and this field is the point of the screen.
|
|
191
|
-
caretTone: "accent", ...(autoFocus ? { autoFocus: true } : {}) }), _jsx(Divider, { dim: true }), _jsx(ComposerBar, { options: options, onOpen: (option, anchorId) => onOption?.(option, anchorId), onSend: () => onSubmit(value), ...(running ? { running: true } : {}), queued: queued, sendDisabled: value.trim() === '' })] })] }));
|
|
192
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { BoxProps, RenderOutput } from '@textui/core';
|
|
2
|
-
/**
|
|
3
|
-
* The composer's control row: what this message will be sent as.
|
|
4
|
-
*
|
|
5
|
-
* One line under the field, and everything on it is a *current value* rather
|
|
6
|
-
* than a label - which harness, which model, how much it may do before it
|
|
7
|
-
* asks, where it works. A person can read what will happen without opening
|
|
8
|
-
* anything, and change any of it without leaving the composer.
|
|
9
|
-
*
|
|
10
|
-
* Each chip is one command's argument, asked through the palette (see
|
|
11
|
-
* `picker.ts`). That is the whole design: nothing here knows what a model or a
|
|
12
|
-
* permission mode is, so a new chip is a new command and no change to this
|
|
13
|
-
* file.
|
|
14
|
-
*/
|
|
15
|
-
export interface ComposerOption {
|
|
16
|
-
id: string;
|
|
17
|
-
/** The value, as a person reads it. Never the id the host stores. */
|
|
18
|
-
label: string;
|
|
19
|
-
/**
|
|
20
|
-
* The question, as opposed to the answer in `label`.
|
|
21
|
-
*
|
|
22
|
-
* The chip has no room for it - "Ask each time" is the whole row and the
|
|
23
|
-
* mark in front says which question it belongs to - but anything listing
|
|
24
|
-
* these somewhere with more space needs the pair, and the host's own wording
|
|
25
|
-
* for both is on the schema rather than in this file.
|
|
26
|
-
*/
|
|
27
|
-
title?: string;
|
|
28
|
-
icon?: string;
|
|
29
|
-
/** The command whose argument this chip asks about. Absent: shown, not asked. */
|
|
30
|
-
commandId?: string;
|
|
31
|
-
}
|
|
32
|
-
export interface ComposerBarProps extends BoxProps {
|
|
33
|
-
options: ComposerOption[];
|
|
34
|
-
onOpen(option: ComposerOption, anchorId: string): void;
|
|
35
|
-
onSend(): void;
|
|
36
|
-
/** A turn is running, so this message joins the queue instead. */
|
|
37
|
-
running?: boolean;
|
|
38
|
-
queued?: number;
|
|
39
|
-
sendDisabled?: boolean;
|
|
40
|
-
}
|
|
41
|
-
/** The focus id of one chip. The picker anchors to it, so it has to be knowable. */
|
|
42
|
-
export declare const chipId: (id: string) => string;
|
|
43
|
-
export declare const SEND_ID = "chat.send";
|
|
44
|
-
export declare const ComposerBar: (props: ComposerBarProps) => RenderOutput;
|