@0gfoundation/0g-agentdna 0.2.3 → 0.5.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/GUIDE.md +190 -40
- package/OPERATORS.md +164 -0
- package/OPERATORS.zh.md +141 -0
- package/PROVIDERS.md +6 -0
- package/PROVIDERS.zh.md +3 -1
- package/README.md +84 -11
- package/dist/AgentClient.d.ts +374 -26
- package/dist/AgentClient.d.ts.map +1 -1
- package/dist/AgentClient.js +323 -40
- package/dist/AgentClient.js.map +1 -1
- package/dist/AgenticID.d.ts +170 -80
- package/dist/AgenticID.d.ts.map +1 -1
- package/dist/AgenticID.js +300 -42
- package/dist/AgenticID.js.map +1 -1
- package/dist/AttestorClient.d.ts +115 -31
- package/dist/AttestorClient.d.ts.map +1 -1
- package/dist/AttestorClient.js +276 -56
- package/dist/AttestorClient.js.map +1 -1
- package/dist/Credentials.d.ts +574 -0
- package/dist/Credentials.d.ts.map +1 -0
- package/dist/Credentials.js +838 -0
- package/dist/Credentials.js.map +1 -0
- package/dist/Operators.d.ts +60 -0
- package/dist/Operators.d.ts.map +1 -0
- package/dist/Operators.js +38 -0
- package/dist/Operators.js.map +1 -0
- package/dist/Providers.d.ts +13 -0
- package/dist/Providers.d.ts.map +1 -1
- package/dist/Providers.js +20 -1
- package/dist/Providers.js.map +1 -1
- package/dist/Releases.d.ts +51 -0
- package/dist/Releases.d.ts.map +1 -0
- package/dist/Releases.js +72 -0
- package/dist/Releases.js.map +1 -0
- package/dist/ReputationClient.d.ts +47 -3
- package/dist/ReputationClient.d.ts.map +1 -1
- package/dist/ReputationClient.js +204 -78
- package/dist/ReputationClient.js.map +1 -1
- package/dist/ServeProof.d.ts +70 -23
- package/dist/ServeProof.d.ts.map +1 -1
- package/dist/ServeProof.js +94 -35
- package/dist/ServeProof.js.map +1 -1
- package/dist/ServeSession.d.ts +17 -2
- package/dist/ServeSession.d.ts.map +1 -1
- package/dist/ServeSession.js +77 -9
- package/dist/ServeSession.js.map +1 -1
- package/dist/Settings.d.ts +25 -1
- package/dist/Settings.d.ts.map +1 -1
- package/dist/Settings.js +53 -1
- package/dist/Settings.js.map +1 -1
- package/dist/TrustRegistry.d.ts +28 -0
- package/dist/TrustRegistry.d.ts.map +1 -0
- package/dist/TrustRegistry.js +67 -0
- package/dist/TrustRegistry.js.map +1 -0
- package/dist/abi.d.ts +346 -34
- package/dist/abi.d.ts.map +1 -1
- package/dist/abi.js +150 -30
- package/dist/abi.js.map +1 -1
- package/dist/cli/attach.d.ts +79 -0
- package/dist/cli/attach.d.ts.map +1 -0
- package/dist/cli/attach.js +253 -0
- package/dist/cli/attach.js.map +1 -0
- package/dist/cli/commands/cells.d.ts +45 -0
- package/dist/cli/commands/cells.d.ts.map +1 -1
- package/dist/cli/commands/cells.js +77 -0
- package/dist/cli/commands/cells.js.map +1 -1
- package/dist/cli/commands/cred.d.ts +12 -0
- package/dist/cli/commands/cred.d.ts.map +1 -0
- package/dist/cli/commands/cred.js +43 -0
- package/dist/cli/commands/cred.js.map +1 -0
- package/dist/cli/commands/doctor.d.ts.map +1 -1
- package/dist/cli/commands/doctor.js +44 -35
- package/dist/cli/commands/doctor.js.map +1 -1
- package/dist/cli/commands/interactive.d.ts +597 -21
- package/dist/cli/commands/interactive.d.ts.map +1 -1
- package/dist/cli/commands/interactive.js +5082 -1323
- package/dist/cli/commands/interactive.js.map +1 -1
- package/dist/cli/commands/list.d.ts +5 -5
- package/dist/cli/commands/list.d.ts.map +1 -1
- package/dist/cli/commands/list.js +21 -26
- package/dist/cli/commands/list.js.map +1 -1
- package/dist/cli/commands/providers.d.ts +4 -0
- package/dist/cli/commands/providers.d.ts.map +1 -1
- package/dist/cli/commands/providers.js +19 -5
- package/dist/cli/commands/providers.js.map +1 -1
- package/dist/cli/commands/releases.d.ts +13 -0
- package/dist/cli/commands/releases.d.ts.map +1 -0
- package/dist/cli/commands/releases.js +65 -0
- package/dist/cli/commands/releases.js.map +1 -0
- package/dist/cli/commands/settings.d.ts +5 -0
- package/dist/cli/commands/settings.d.ts.map +1 -1
- package/dist/cli/commands/settings.js +70 -24
- package/dist/cli/commands/settings.js.map +1 -1
- package/dist/cli/commands/status.d.ts +2 -1
- package/dist/cli/commands/status.d.ts.map +1 -1
- package/dist/cli/commands/status.js +22 -19
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/cli/config.d.ts +48 -1
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +114 -5
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/credentials.d.ts +179 -0
- package/dist/cli/credentials.d.ts.map +1 -0
- package/dist/cli/credentials.js +1443 -0
- package/dist/cli/credentials.js.map +1 -0
- package/dist/cli/download.d.ts +21 -0
- package/dist/cli/download.d.ts.map +1 -0
- package/dist/cli/download.js +89 -0
- package/dist/cli/download.js.map +1 -0
- package/dist/cli/env.d.ts +6 -0
- package/dist/cli/env.d.ts.map +1 -1
- package/dist/cli/env.js +18 -6
- package/dist/cli/env.js.map +1 -1
- package/dist/cli/envelope.d.ts +4 -2
- package/dist/cli/envelope.d.ts.map +1 -1
- package/dist/cli/envelope.js +10 -6
- package/dist/cli/envelope.js.map +1 -1
- package/dist/cli/errors.d.ts +45 -1
- package/dist/cli/errors.d.ts.map +1 -1
- package/dist/cli/errors.js +77 -0
- package/dist/cli/errors.js.map +1 -1
- package/dist/cli/inference.d.ts.map +1 -1
- package/dist/cli/inference.js +7 -0
- package/dist/cli/inference.js.map +1 -1
- package/dist/cli/inkView.d.ts +341 -0
- package/dist/cli/inkView.d.ts.map +1 -0
- package/dist/cli/inkView.js +1019 -0
- package/dist/cli/inkView.js.map +1 -0
- package/dist/cli/legacy/modelKey.d.ts +24 -0
- package/dist/cli/legacy/modelKey.d.ts.map +1 -0
- package/dist/cli/legacy/modelKey.js +32 -0
- package/dist/cli/legacy/modelKey.js.map +1 -0
- package/dist/cli/livePrompt.d.ts +212 -0
- package/dist/cli/livePrompt.d.ts.map +1 -0
- package/dist/cli/livePrompt.js +576 -0
- package/dist/cli/livePrompt.js.map +1 -0
- package/dist/cli/main.js +206 -72
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/modelkey.d.ts +64 -0
- package/dist/cli/modelkey.d.ts.map +1 -0
- package/dist/cli/modelkey.js +113 -0
- package/dist/cli/modelkey.js.map +1 -0
- package/dist/cli/outboxSync.d.ts +51 -0
- package/dist/cli/outboxSync.d.ts.map +1 -0
- package/dist/cli/outboxSync.js +210 -0
- package/dist/cli/outboxSync.js.map +1 -0
- package/dist/cli/plain.d.ts +46 -0
- package/dist/cli/plain.d.ts.map +1 -0
- package/dist/cli/plain.js +260 -0
- package/dist/cli/plain.js.map +1 -0
- package/dist/cli/proofs.d.ts +5 -0
- package/dist/cli/proofs.d.ts.map +1 -1
- package/dist/cli/proofs.js +20 -0
- package/dist/cli/proofs.js.map +1 -1
- package/dist/cli/ref.d.ts.map +1 -1
- package/dist/cli/ref.js +3 -2
- package/dist/cli/ref.js.map +1 -1
- package/dist/cli/releaseNotice.d.ts +64 -0
- package/dist/cli/releaseNotice.d.ts.map +1 -0
- package/dist/cli/releaseNotice.js +194 -0
- package/dist/cli/releaseNotice.js.map +1 -0
- package/dist/cli/sdk.d.ts +18 -0
- package/dist/cli/sdk.d.ts.map +1 -1
- package/dist/cli/sdk.js +99 -1
- package/dist/cli/sdk.js.map +1 -1
- package/dist/cli/settings.d.ts +90 -9
- package/dist/cli/settings.d.ts.map +1 -1
- package/dist/cli/settings.js +273 -21
- package/dist/cli/settings.js.map +1 -1
- package/dist/cli/textfit.d.ts +28 -0
- package/dist/cli/textfit.d.ts.map +1 -0
- package/dist/cli/textfit.js +111 -0
- package/dist/cli/textfit.js.map +1 -0
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/context.d.ts +26 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -0
- package/dist/context.js.map +1 -1
- package/dist/index.d.ts +19 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +35 -2
- package/dist/index.js.map +1 -1
- package/dist/legacy/modelKey.d.ts +67 -0
- package/dist/legacy/modelKey.d.ts.map +1 -0
- package/dist/legacy/modelKey.js +80 -0
- package/dist/legacy/modelKey.js.map +1 -0
- package/dist/legacy/serveProofV1.d.ts +56 -0
- package/dist/legacy/serveProofV1.d.ts.map +1 -0
- package/dist/legacy/serveProofV1.js +91 -0
- package/dist/legacy/serveProofV1.js.map +1 -0
- package/dist/provider-catalog.json +3 -2
- package/dist/secretEnv.d.ts +18 -3
- package/dist/secretEnv.d.ts.map +1 -1
- package/dist/secretEnv.js +16 -2
- package/dist/secretEnv.js.map +1 -1
- package/dist/types.d.ts +63 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/viemErrors.d.ts +30 -0
- package/dist/viemErrors.d.ts.map +1 -0
- package/dist/viemErrors.js +36 -0
- package/dist/viemErrors.js.map +1 -0
- package/package.json +5 -1
- package/src/AgentClient.ts +622 -68
- package/src/AgenticID.ts +345 -56
- package/src/AttestorClient.ts +330 -83
- package/src/Credentials.ts +1027 -0
- package/src/Operators.ts +71 -0
- package/src/Providers.ts +20 -0
- package/src/Releases.ts +95 -0
- package/src/ReputationClient.ts +231 -79
- package/src/ServeProof.ts +123 -39
- package/src/ServeSession.ts +91 -9
- package/src/Settings.ts +61 -1
- package/src/TrustRegistry.ts +75 -0
- package/src/abi.ts +153 -30
- package/src/cli/attach.ts +257 -0
- package/src/cli/commands/cells.ts +104 -0
- package/src/cli/commands/cred.ts +44 -0
- package/src/cli/commands/doctor.ts +45 -37
- package/src/cli/commands/interactive.ts +4120 -664
- package/src/cli/commands/list.ts +21 -30
- package/src/cli/commands/providers.ts +17 -4
- package/src/cli/commands/releases.ts +60 -0
- package/src/cli/commands/settings.ts +75 -28
- package/src/cli/commands/status.ts +24 -21
- package/src/cli/config.ts +119 -4
- package/src/cli/credentials.ts +1379 -0
- package/src/cli/download.ts +80 -0
- package/src/cli/env.ts +22 -7
- package/src/cli/envelope.ts +10 -6
- package/src/cli/errors.ts +92 -0
- package/src/cli/inference.ts +8 -1
- package/src/cli/inkView.ts +969 -0
- package/src/cli/legacy/modelKey.ts +35 -0
- package/src/cli/livePrompt.ts +615 -0
- package/src/cli/main.ts +206 -76
- package/src/cli/modelkey.ts +124 -0
- package/src/cli/outboxSync.ts +231 -0
- package/src/cli/plain.ts +260 -0
- package/src/cli/proofs.ts +27 -0
- package/src/cli/ref.ts +5 -4
- package/src/cli/releaseNotice.ts +200 -0
- package/src/cli/sdk.ts +87 -7
- package/src/cli/settings.ts +275 -25
- package/src/cli/textfit.ts +95 -0
- package/src/constants.ts +1 -1
- package/src/context.ts +28 -0
- package/src/index.ts +50 -7
- package/src/legacy/modelKey.ts +80 -0
- package/src/legacy/serveProofV1.ts +124 -0
- package/src/provider-catalog.json +3 -2
- package/src/secretEnv.ts +18 -3
- package/src/types.ts +60 -1
- package/src/viemErrors.ts +39 -0
|
@@ -0,0 +1,969 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The agent session on a terminal, drawn with Ink and laid out like Claude
|
|
3
|
+
* Code's input area. From the bottom up:
|
|
4
|
+
*
|
|
5
|
+
* agent 625 · Enter steers · Tab queues · ↑ takes back · Esc stops (footer)
|
|
6
|
+
* ────────────────────────────────────────────────────────────────
|
|
7
|
+
* ❯ what the owner is typing█ (input)
|
|
8
|
+
* ────────────────────────────────────────────────────────────────
|
|
9
|
+
* ⠹ running a command… (14s · Esc to stop) 2 notices · 1 new file
|
|
10
|
+
* ❯ a message sent during the turn queued (highlighted, waiting)
|
|
11
|
+
* the reply's line being written (the transcript's tail)
|
|
12
|
+
*
|
|
13
|
+
* and above all of that the transcript, which scrolls: the owner's messages
|
|
14
|
+
* as `❯ text`, replies, command output, notices, one line per run of the
|
|
15
|
+
* agent's tool calls (`ran 3 commands`).
|
|
16
|
+
*
|
|
17
|
+
* Only the region below the transcript is Ink's: it is redrawn in place.
|
|
18
|
+
* Transcript text is written through Ink's `useStdout().write` (Ink's
|
|
19
|
+
* equivalent of `<Static>` for strings): Ink clears its region, the text is
|
|
20
|
+
* written as it is (an OSC 8 link in it stays a link; Ink's own text layout
|
|
21
|
+
* would cut it up) and the region is drawn again under it. Every row of the
|
|
22
|
+
* region is cut to the terminal's width here, so its height is known and
|
|
23
|
+
* kept below the screen's (Ink clears the whole terminal, scrollback too,
|
|
24
|
+
* when its output is taller than the screen). Frames are at least
|
|
25
|
+
* {@link FRAME_MS} apart: Ink renders a change at once only when its last
|
|
26
|
+
* render is more than 32 ms old, and writing transcript text redraws Ink's
|
|
27
|
+
* last frame, which must be the current one.
|
|
28
|
+
*
|
|
29
|
+
* The keys are the shell's (the session's keypress events, readline's own
|
|
30
|
+
* handler set aside meanwhile): {@link InkEditor} edits the line the way
|
|
31
|
+
* readline does and stands in for readline under the shell's line queue
|
|
32
|
+
* (interactive.ts lineQueue), which keeps every rule about steering,
|
|
33
|
+
* queueing, pastes and questions it already has.
|
|
34
|
+
*/
|
|
35
|
+
import { EventEmitter } from 'node:events';
|
|
36
|
+
import { PassThrough } from 'node:stream';
|
|
37
|
+
import { pathToFileURL } from 'node:url';
|
|
38
|
+
import { cleanCell, cleanStream } from './commands/cells';
|
|
39
|
+
import { charCols, completeAt, fitRow, splitRows, wrapProse, wrapText, type TurnView } from './livePrompt';
|
|
40
|
+
|
|
41
|
+
/** The fewest milliseconds between two frames (Ink throttles at 32). */
|
|
42
|
+
export const FRAME_MS = 40;
|
|
43
|
+
/** The prompt of the owner's message, in the box and in the transcript. */
|
|
44
|
+
export const INK_PROMPT = '❯ ';
|
|
45
|
+
/** What a message sent during a turn waits for: the agent to read it (Enter), the next turn (Tab, or a command). */
|
|
46
|
+
export const WAITING_AGENT = 'waiting for the agent';
|
|
47
|
+
export const WAITING_TURN = 'next turn';
|
|
48
|
+
/** The lines of a long message of the owner's that the transcript keeps. */
|
|
49
|
+
const OWNER_LINES = 8;
|
|
50
|
+
/** The fewest terminal rows and columns the view is drawn on (the shell's prompt serves smaller ones). */
|
|
51
|
+
export const MIN_ROWS = 12;
|
|
52
|
+
export const MIN_COLS = 30;
|
|
53
|
+
|
|
54
|
+
const SPIN = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧'];
|
|
55
|
+
|
|
56
|
+
// ── loading Ink ──────────────────────────────────────────────────────────────
|
|
57
|
+
|
|
58
|
+
type El = unknown;
|
|
59
|
+
type Props = Record<string, unknown> | null;
|
|
60
|
+
/** The parts of React and Ink this view uses. */
|
|
61
|
+
export interface InkLib {
|
|
62
|
+
React: { createElement(type: unknown, props?: Props, ...children: unknown[]): El };
|
|
63
|
+
ink: {
|
|
64
|
+
render(tree: El, options: Record<string, unknown>): InkInstance;
|
|
65
|
+
Box: unknown;
|
|
66
|
+
Text: unknown;
|
|
67
|
+
useStdout(): { write(data: string): void };
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
interface InkInstance { rerender(tree: El): void; unmount(): void; clear(): void }
|
|
71
|
+
|
|
72
|
+
let loading: Promise<InkLib | null> | undefined;
|
|
73
|
+
let loadError: string | undefined;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Ink and React, or null when they cannot be loaded (then the shell keeps
|
|
77
|
+
* its readline prompt). Ink is an ES module and this package is CommonJS:
|
|
78
|
+
* it is imported with a real dynamic `import()` (TypeScript would turn one
|
|
79
|
+
* written here into `require`, which cannot load Ink's top-level await).
|
|
80
|
+
*/
|
|
81
|
+
export function loadInk(): Promise<InkLib | null> {
|
|
82
|
+
loading ??= (async () => {
|
|
83
|
+
try {
|
|
84
|
+
const importEsm = new Function('url', 'return import(url)') as (url: string) => Promise<unknown>;
|
|
85
|
+
const ink = (await importEsm(pathToFileURL(require.resolve('ink')).href)) as InkLib['ink'];
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
87
|
+
const React = require('react') as InkLib['React'];
|
|
88
|
+
if (typeof ink.render !== 'function' || typeof React.createElement !== 'function') throw new Error('unexpected module shape');
|
|
89
|
+
return { React, ink };
|
|
90
|
+
} catch (e) {
|
|
91
|
+
loadError = cleanCell((e as Error).message ?? String(e)).slice(0, 160);
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
})();
|
|
95
|
+
return loading;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Why {@link loadInk} gave null. */
|
|
99
|
+
export function inkLoadError(): string | undefined { return loadError; }
|
|
100
|
+
|
|
101
|
+
// ── the line being edited ────────────────────────────────────────────────────
|
|
102
|
+
|
|
103
|
+
export type Key = { name?: string; ctrl?: boolean; meta?: boolean; shift?: boolean; sequence?: string };
|
|
104
|
+
|
|
105
|
+
/** Readline's history size. */
|
|
106
|
+
const HISTORY = 30;
|
|
107
|
+
/** Readline's crlfDelay: an LF this soon after a CR is the same Enter. */
|
|
108
|
+
const CRLF_MS = 100;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The line being edited, with readline's keys (Emacs bindings, history with
|
|
112
|
+
* prefix search) and the parts of a readline interface the shell's line
|
|
113
|
+
* queue reads and writes: `line`, `cursor`, `history`, the prompt, and the
|
|
114
|
+
* `line`, `close` and `keypress` events. A `line` event is emitted on Enter
|
|
115
|
+
* (also between a paste's start and end, where the queue collects them),
|
|
116
|
+
* after the line went into the history; `close` on Ctrl-D at an empty line.
|
|
117
|
+
*/
|
|
118
|
+
export class InkEditor extends EventEmitter {
|
|
119
|
+
readonly terminal = true;
|
|
120
|
+
line = '';
|
|
121
|
+
cursor = 0;
|
|
122
|
+
prevRows = 0;
|
|
123
|
+
history: string[] = [];
|
|
124
|
+
/** Lines entered meanwhile stay out of the history (a secret is typed). */
|
|
125
|
+
noHistory = false;
|
|
126
|
+
/** Between a bracketed paste's start and end. */
|
|
127
|
+
pasting = false;
|
|
128
|
+
private shown = '';
|
|
129
|
+
private hist = -1;
|
|
130
|
+
private saved = '';
|
|
131
|
+
private search = '';
|
|
132
|
+
private returnAt = 0;
|
|
133
|
+
|
|
134
|
+
/** Called when the prompt changes (a question came up): the view redraws. */
|
|
135
|
+
changed: () => void = () => undefined;
|
|
136
|
+
setPrompt(q: string): void { this.shown = q; this.changed(); }
|
|
137
|
+
getPrompt(): string { return this.shown; }
|
|
138
|
+
/** As readline: the cursor goes to the line's start unless kept. */
|
|
139
|
+
prompt(preserveCursor?: boolean): void { if (!preserveCursor) this.cursor = 0; this.changed(); }
|
|
140
|
+
|
|
141
|
+
/** Put text at the cursor. */
|
|
142
|
+
insert(s: string): void {
|
|
143
|
+
this.hist = -1;
|
|
144
|
+
this.line = this.line.slice(0, this.cursor) + s + this.line.slice(this.cursor);
|
|
145
|
+
this.cursor += s.length;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Replace `n` characters before the cursor with `s`. */
|
|
149
|
+
replaceBefore(n: number, s: string): void {
|
|
150
|
+
this.hist = -1;
|
|
151
|
+
const at = Math.max(0, this.cursor - n);
|
|
152
|
+
this.line = this.line.slice(0, at) + s + this.line.slice(this.cursor);
|
|
153
|
+
this.cursor = at + s.length;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** One key, as readline handles it on a terminal (Esc, Tab outside a paste and Ctrl-C are the caller's). */
|
|
157
|
+
handle(s: string | undefined, key: Key): void {
|
|
158
|
+
const name = key.name;
|
|
159
|
+
if (name === 'paste-start') { this.pasting = true; return; }
|
|
160
|
+
if (name === 'paste-end') { this.pasting = false; return; }
|
|
161
|
+
if (key.ctrl && !key.meta) {
|
|
162
|
+
switch (name) {
|
|
163
|
+
case 'a': this.cursor = 0; return;
|
|
164
|
+
case 'e': this.cursor = this.line.length; return;
|
|
165
|
+
case 'b': this.move(-1); return;
|
|
166
|
+
case 'f': this.move(1); return;
|
|
167
|
+
case 'h': this.backspace(); return;
|
|
168
|
+
case 'd': if (this.line === '') this.emit('close'); else this.del(); return;
|
|
169
|
+
case 'u': this.hist = -1; this.line = this.line.slice(this.cursor); this.cursor = 0; return;
|
|
170
|
+
case 'k': this.hist = -1; this.line = this.line.slice(0, this.cursor); return;
|
|
171
|
+
case 'w': this.deleteWordLeft(); return;
|
|
172
|
+
case 'p': this.histPrev(); return;
|
|
173
|
+
case 'n': this.histNext(); return;
|
|
174
|
+
case 'left': this.cursor -= this.wordLeft(); return;
|
|
175
|
+
case 'right': this.cursor += this.wordRight(); return;
|
|
176
|
+
default: return;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (key.meta) {
|
|
180
|
+
switch (name) {
|
|
181
|
+
case 'b': case 'left': this.cursor -= this.wordLeft(); return;
|
|
182
|
+
case 'f': case 'right': this.cursor += this.wordRight(); return;
|
|
183
|
+
case 'd': this.hist = -1; this.line = this.line.slice(0, this.cursor) + this.line.slice(this.cursor + this.wordRight()); return;
|
|
184
|
+
case 'backspace': this.deleteWordLeft(); return;
|
|
185
|
+
default: return; // Option/Alt+Enter: the line queue's
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
switch (name) {
|
|
189
|
+
case 'return': this.returnAt = Date.now(); this.enter(); return;
|
|
190
|
+
case 'enter':
|
|
191
|
+
if (this.returnAt === 0 || Date.now() - this.returnAt > CRLF_MS) this.enter();
|
|
192
|
+
this.returnAt = 0;
|
|
193
|
+
return;
|
|
194
|
+
case 'backspace': this.backspace(); return;
|
|
195
|
+
case 'delete': this.del(); return;
|
|
196
|
+
case 'left': this.move(-1); return;
|
|
197
|
+
case 'right': this.move(1); return;
|
|
198
|
+
case 'home': this.cursor = 0; return;
|
|
199
|
+
case 'end': this.cursor = this.line.length; return;
|
|
200
|
+
case 'up': this.histPrev(); return;
|
|
201
|
+
case 'down': this.histNext(); return;
|
|
202
|
+
case 'tab': this.insert('\t'); return; // inside a paste
|
|
203
|
+
case 'escape': return;
|
|
204
|
+
default:
|
|
205
|
+
// eslint-disable-next-line no-control-regex
|
|
206
|
+
if (s && !/[\u0000-\u001f\u007f]/.test(s)) this.insert(s);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
private enter(): void {
|
|
211
|
+
const l = this.line;
|
|
212
|
+
if (!this.noHistory && l.trim() && this.history[0] !== l) {
|
|
213
|
+
this.history.unshift(l);
|
|
214
|
+
if (this.history.length > HISTORY) this.history.pop();
|
|
215
|
+
}
|
|
216
|
+
this.hist = -1;
|
|
217
|
+
this.line = '';
|
|
218
|
+
this.cursor = 0;
|
|
219
|
+
this.emit('line', l);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** UTF-16 units of the character before (-1) or at (1) the cursor. */
|
|
223
|
+
private charLen(dir: -1 | 1): number {
|
|
224
|
+
const at = dir < 0 ? this.cursor - 1 : this.cursor;
|
|
225
|
+
if (at < 0 || at >= this.line.length) return 0;
|
|
226
|
+
const c = this.line.charCodeAt(at);
|
|
227
|
+
if (dir < 0 && c >= 0xdc00 && c <= 0xdfff && at > 0) return 2;
|
|
228
|
+
if (dir > 0 && c >= 0xd800 && c <= 0xdbff && at + 1 < this.line.length) return 2;
|
|
229
|
+
return 1;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
private move(dir: -1 | 1): void { this.cursor += dir * this.charLen(dir); }
|
|
233
|
+
|
|
234
|
+
private backspace(): void {
|
|
235
|
+
const n = this.charLen(-1);
|
|
236
|
+
if (n) this.replaceBefore(n, '');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
private del(): void {
|
|
240
|
+
const n = this.charLen(1);
|
|
241
|
+
if (!n) return;
|
|
242
|
+
this.hist = -1;
|
|
243
|
+
this.line = this.line.slice(0, this.cursor) + this.line.slice(this.cursor + n);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Readline's word boundaries (a run of word characters or of other
|
|
247
|
+
// non-space characters, with the spaces next to it), with letters and
|
|
248
|
+
// digits of every script as word characters, not only ASCII ones.
|
|
249
|
+
private wordLeft(): number {
|
|
250
|
+
const before = [...this.line.slice(0, this.cursor)].reverse().join('');
|
|
251
|
+
return (/^\s*(?:[^\p{L}\p{N}_\s]+|[\p{L}\p{N}_]+)?/u.exec(before)?.[0] ?? '').length;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
private wordRight(): number {
|
|
255
|
+
return (/^\s*(?:[^\p{L}\p{N}_\s]+|[\p{L}\p{N}_]+)\s*/u.exec(this.line.slice(this.cursor))?.[0] ?? '').length;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
private deleteWordLeft(): void {
|
|
259
|
+
const n = this.wordLeft();
|
|
260
|
+
if (n) this.replaceBefore(n, '');
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
private setLine(l: string): void {
|
|
264
|
+
this.line = l;
|
|
265
|
+
this.cursor = l.length;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// ↑/↓: older and newer entries starting with what was typed before ↑.
|
|
269
|
+
private histPrev(): void {
|
|
270
|
+
if (this.hist === -1) { this.saved = this.line; this.search = this.line; }
|
|
271
|
+
for (let i = this.hist + 1; i < this.history.length; i++) {
|
|
272
|
+
const h = this.history[i];
|
|
273
|
+
if (h.startsWith(this.search) && h !== this.line) { this.hist = i; this.setLine(h); return; }
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
private histNext(): void {
|
|
278
|
+
if (this.hist === -1) return;
|
|
279
|
+
for (let i = this.hist - 1; i >= 0; i--) {
|
|
280
|
+
const h = this.history[i];
|
|
281
|
+
if (h.startsWith(this.search) && h !== this.line) { this.hist = i; this.setLine(h); return; }
|
|
282
|
+
}
|
|
283
|
+
this.hist = -1;
|
|
284
|
+
this.setLine(this.saved);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// ── the screen ───────────────────────────────────────────────────────────────
|
|
289
|
+
|
|
290
|
+
/** What the shell's line queue answers for the view (interactive.ts Ask). */
|
|
291
|
+
export interface InkAsk {
|
|
292
|
+
unwind?(): boolean;
|
|
293
|
+
clearBox?(): boolean;
|
|
294
|
+
held?: { count(): number } | null;
|
|
295
|
+
queued?(): Array<{ text: string }>;
|
|
296
|
+
drafting?(): string[];
|
|
297
|
+
recall?(): boolean;
|
|
298
|
+
queueEdit?(): boolean;
|
|
299
|
+
waiting?(): { kind: string; q: string } | null;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** How the line queue reports an entry it gave a question: the question's kind, its text, the entry. */
|
|
303
|
+
export type Echo = (kind: string, q: string, e: { text: string }) => void;
|
|
304
|
+
|
|
305
|
+
export interface InkScreenOptions<A extends InkAsk> {
|
|
306
|
+
lib: InkLib;
|
|
307
|
+
stdout: NodeJS.WritableStream & { columns?: number; rows?: number; on(ev: 'resize', f: () => void): unknown; off(ev: 'resize', f: () => void): unknown };
|
|
308
|
+
stderr?: NodeJS.WritableStream;
|
|
309
|
+
/** The shell's line queue over the editor; `echo` writes what it gives a question to the transcript. */
|
|
310
|
+
makeAsk(editor: InkEditor, echo: Echo): A;
|
|
311
|
+
/** Tab completion of the text before the cursor (interactive.ts completeLine). */
|
|
312
|
+
complete(before: string): [string[], string];
|
|
313
|
+
/** Ctrl-C and Esc: the shell's own handling. */
|
|
314
|
+
onInterrupt(): void;
|
|
315
|
+
onEscape(): void;
|
|
316
|
+
/** One run of tool calls in plain words ('' when the run had none). */
|
|
317
|
+
summarize(labels: readonly string[]): string;
|
|
318
|
+
/** How the owner's message reads in the transcript (a dropped file's path as its name). */
|
|
319
|
+
ownerText?(text: string): string;
|
|
320
|
+
/** Styles (colours, dim) on; the cursor is drawn inverted regardless. */
|
|
321
|
+
colors?: boolean;
|
|
322
|
+
patchConsole?: boolean;
|
|
323
|
+
frameMs?: number;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** What the footer and the status row say about the session. */
|
|
327
|
+
export interface InkContext {
|
|
328
|
+
/** e.g. `agent 625 [notes]`. */
|
|
329
|
+
agent(): string;
|
|
330
|
+
/** e.g. `2 notices · 1 new file`, '' for none. */
|
|
331
|
+
counts(): string;
|
|
332
|
+
/** The agent when it is not running, with the way out (`stopped — /start`); '' while it runs. */
|
|
333
|
+
state?(): string;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const CSI = /\u001b\[[0-?]*[ -/]*[@-~]|\u009b[0-?]*[ -/]*[@-~]/g;
|
|
337
|
+
|
|
338
|
+
/** The width of a row as this file measures it (erring wide). */
|
|
339
|
+
function width(text: string): number {
|
|
340
|
+
let w = 0;
|
|
341
|
+
for (const ch of text) w += charCols(ch.codePointAt(0)!);
|
|
342
|
+
return w;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* A line in rows of at most `cols` columns, broken between words (a row ends
|
|
347
|
+
* after a space, which is not shown; mid-word only for a word longer than a
|
|
348
|
+
* row). `end`: where the next row starts in the line.
|
|
349
|
+
*/
|
|
350
|
+
export function wrapRows(line: string, cols: number): Array<{ text: string; end: number }> {
|
|
351
|
+
const rows: Array<{ text: string; end: number }> = [];
|
|
352
|
+
let at = 0;
|
|
353
|
+
while (at < line.length) {
|
|
354
|
+
const rest = line.slice(at);
|
|
355
|
+
const split = splitRows(rest, cols);
|
|
356
|
+
if (split.length === 1) { rows.push({ text: split[0].text, end: line.length }); break; }
|
|
357
|
+
const cut = split[0].end;
|
|
358
|
+
const sp = rest[cut] === ' ' ? cut : rest.lastIndexOf(' ', cut - 1);
|
|
359
|
+
if (sp > 0) {
|
|
360
|
+
rows.push({ text: rest.slice(0, sp).replace(/\t/g, ' ').trimEnd(), end: at + sp + 1 });
|
|
361
|
+
at += sp + 1;
|
|
362
|
+
} else {
|
|
363
|
+
rows.push({ text: split[0].text, end: at + cut });
|
|
364
|
+
at += cut;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return rows.length ? rows : [{ text: '', end: 0 }];
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function oneLine(text: string): string {
|
|
371
|
+
const lines = text.split('\n');
|
|
372
|
+
return lines.length > 1 ? `${lines[0]} (+${lines.length - 1} line${lines.length === 2 ? '' : 's'})` : lines[0];
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* The Ink session view: the transcript's writer, the region below it, and
|
|
377
|
+
* the keys. One per session; {@link close} hands the terminal back.
|
|
378
|
+
*/
|
|
379
|
+
export class InkScreen<A extends InkAsk = InkAsk> {
|
|
380
|
+
readonly editor = new InkEditor();
|
|
381
|
+
readonly ask: A;
|
|
382
|
+
context: InkContext = { agent: () => '', counts: () => '' };
|
|
383
|
+
/** Transcript text to write with the next frame: whole lines. */
|
|
384
|
+
private pending = '';
|
|
385
|
+
/** The transcript's unfinished line (a reply being written): in the region. */
|
|
386
|
+
private tail = '';
|
|
387
|
+
private masked = false;
|
|
388
|
+
private waitStatus: string | null = null;
|
|
389
|
+
private completions: string[] | null = null;
|
|
390
|
+
private turnView: InkTurn | null = null;
|
|
391
|
+
private inst: InkInstance | null = null;
|
|
392
|
+
private writeOut: ((s: string) => void) | null = null;
|
|
393
|
+
private timer: ReturnType<typeof setTimeout> | null = null;
|
|
394
|
+
private lastFrame = 0;
|
|
395
|
+
private closing = false;
|
|
396
|
+
private hidden = false;
|
|
397
|
+
/** Closed: what is written from now on goes to the terminal as it is. */
|
|
398
|
+
private done = false;
|
|
399
|
+
private settled: Array<() => void> = [];
|
|
400
|
+
private readonly frameMs: number;
|
|
401
|
+
private readonly colors: boolean;
|
|
402
|
+
private readonly h: InkLib['React']['createElement'];
|
|
403
|
+
private readonly Grab: () => null;
|
|
404
|
+
private readonly onResize = (): void => this.schedule();
|
|
405
|
+
|
|
406
|
+
constructor(private readonly o: InkScreenOptions<A>) {
|
|
407
|
+
this.frameMs = Math.max(FRAME_MS, o.frameMs ?? FRAME_MS);
|
|
408
|
+
this.colors = o.colors ?? true;
|
|
409
|
+
this.h = o.lib.React.createElement.bind(o.lib.React);
|
|
410
|
+
const ink = o.lib.ink;
|
|
411
|
+
// The writer of transcript text, from Ink's stdout context.
|
|
412
|
+
this.Grab = (): null => { this.writeOut = ink.useStdout().write; return null; };
|
|
413
|
+
this.ask = o.makeAsk(this.editor, (kind, q, e) => this.echo(kind, q, e.text));
|
|
414
|
+
this.editor.changed = () => this.schedule();
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/** Draw the region for the first time. */
|
|
418
|
+
mount(): void {
|
|
419
|
+
const { ink } = this.o.lib;
|
|
420
|
+
this.inst = ink.render(this.tree(), {
|
|
421
|
+
stdout: this.o.stdout,
|
|
422
|
+
stderr: this.o.stderr ?? this.o.stdout,
|
|
423
|
+
// Ink never reads the keyboard here: the shell's keypress events come in through key().
|
|
424
|
+
stdin: Object.assign(new PassThrough(), { isTTY: false }),
|
|
425
|
+
exitOnCtrlC: false,
|
|
426
|
+
patchConsole: this.o.patchConsole ?? true,
|
|
427
|
+
});
|
|
428
|
+
this.lastFrame = Date.now();
|
|
429
|
+
this.o.stdout.on('resize', this.onResize);
|
|
430
|
+
this.schedule();
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// ── what the shell writes ──
|
|
434
|
+
|
|
435
|
+
/** Text for the transcript, cleaned by the caller (interactive.ts `out`). */
|
|
436
|
+
write(s: string): void {
|
|
437
|
+
if (!s) return;
|
|
438
|
+
const all = this.tail + s;
|
|
439
|
+
const nl = all.lastIndexOf('\n');
|
|
440
|
+
if (nl < 0) {
|
|
441
|
+
this.tail = all;
|
|
442
|
+
} else {
|
|
443
|
+
// Finished lines stay in the scrollback: broken between words.
|
|
444
|
+
this.pending += wrapText(all.slice(0, nl + 1), this.wrapCols());
|
|
445
|
+
this.tail = all.slice(nl + 1);
|
|
446
|
+
}
|
|
447
|
+
this.schedule();
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/** The width text for the transcript is wrapped to: the terminal's, less one. */
|
|
451
|
+
private wrapCols(): number {
|
|
452
|
+
return Math.max(20, (this.o.stdout.columns || 80) - 1);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* The shell's own text with escape sequences in it (interactive.ts
|
|
457
|
+
* `term`): an OSC 8 link stays as it is in whole lines; cursor and erase
|
|
458
|
+
* sequences, which would move the region from under Ink, go; a write of
|
|
459
|
+
* nothing but sequences (a terminal reset) is left out.
|
|
460
|
+
*/
|
|
461
|
+
raw(s: string): void {
|
|
462
|
+
const text = s.replace(CSI, '').replace(/\r/g, '');
|
|
463
|
+
if (!cleanStream(text)) return;
|
|
464
|
+
if (/\u001b\]/.test(text) && !this.tail && text.endsWith('\n')) {
|
|
465
|
+
this.pending += text;
|
|
466
|
+
this.schedule();
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
this.write(cleanStream(text));
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/** A block for the transcript now, after the line being written (printAbovePrompt). */
|
|
473
|
+
print(text: string): void {
|
|
474
|
+
this.breakTail();
|
|
475
|
+
let t = text.replace(CSI, '').replace(/\r/g, '').replace(/^\n+/, '');
|
|
476
|
+
if (!t) return;
|
|
477
|
+
// Broken between words, unless it carries a link (the shell's own sequence).
|
|
478
|
+
if (!/\u001b/.test(t)) t = wrapText(t, this.wrapCols());
|
|
479
|
+
this.pending += t.endsWith('\n') ? t : `${t}\n`;
|
|
480
|
+
this.schedule();
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/** A whole line above the line being written (a turn's note). */
|
|
484
|
+
note(text: string): void {
|
|
485
|
+
this.pending += `${/\u001b/.test(text) ? text : wrapText(text, this.wrapCols())}\n`;
|
|
486
|
+
this.schedule();
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/** Lines put between a reply's text (the owner's message read, a line
|
|
490
|
+
* after it): its next text is marked as the agent's again. */
|
|
491
|
+
breaks = 0;
|
|
492
|
+
|
|
493
|
+
/** A whole line after the line being written, which ends there. */
|
|
494
|
+
after(text: string): void {
|
|
495
|
+
this.breakTail();
|
|
496
|
+
this.breaks++;
|
|
497
|
+
this.note(text);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/** The owner's message in the transcript: `❯ text`, highlighted. */
|
|
501
|
+
owner(text: string): void {
|
|
502
|
+
this.breakTail();
|
|
503
|
+
this.breaks++;
|
|
504
|
+
let shown = text;
|
|
505
|
+
try { shown = this.o.ownerText?.(text) ?? text; } catch { /* as typed */ }
|
|
506
|
+
let lines = cleanStream(shown).split('\n');
|
|
507
|
+
// A long one (a big paste): its first lines and how many more.
|
|
508
|
+
if (lines.length > OWNER_LINES + 2) lines = [...lines.slice(0, OWNER_LINES), `… (+${lines.length - OWNER_LINES} more lines)`];
|
|
509
|
+
// Each line broken between words, its further rows under its text.
|
|
510
|
+
const rows = lines.flatMap((l) => wrapProse(l, Math.max(18, this.wrapCols() - 2)));
|
|
511
|
+
const [on, off] = this.colors ? ['\u001b[100m', '\u001b[49m'] : ['', ''];
|
|
512
|
+
this.pending += `${rows.map((l, i) => `${on}${i ? ' ' : INK_PROMPT}${l} ${off}`).join('\n')}\n`;
|
|
513
|
+
this.schedule();
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/** A dim line (a run of tool calls) after what is written so far. */
|
|
517
|
+
dim(text: string): void {
|
|
518
|
+
this.breakTail();
|
|
519
|
+
const [on, off] = this.colors ? ['\u001b[2m', '\u001b[22m'] : ['', ''];
|
|
520
|
+
this.pending += `${on}${fitRow(cleanCell(text), Math.max(20, (this.o.stdout.columns || 80) - 1))}${off}\n`;
|
|
521
|
+
this.schedule();
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/** The line being written ends here. */
|
|
525
|
+
breakTail(): void {
|
|
526
|
+
if (!this.tail) return;
|
|
527
|
+
this.pending += `${wrapText(this.tail, this.wrapCols())}\n`;
|
|
528
|
+
this.tail = '';
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/** A question cancelled with Esc or Ctrl-C (`typed`: what its line held): it stays in the transcript as it was. */
|
|
532
|
+
cancelled(q: string, typed = ''): void {
|
|
533
|
+
this.questionLine(q, this.masked ? '' : typed);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/** The status row while no turn runs (a wait for the agent to start); null hides it. */
|
|
537
|
+
status(text: string | null): void {
|
|
538
|
+
const t = text === null ? null : cleanCell(text);
|
|
539
|
+
if (t === this.waitStatus) return;
|
|
540
|
+
this.waitStatus = t;
|
|
541
|
+
this.schedule();
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/** A chat turn's view. `steers`: Enter puts a message into the turn. */
|
|
545
|
+
turn(o: { steered?: () => readonly string[]; steers?: boolean; next?: () => readonly string[] } = {}): InkTurn {
|
|
546
|
+
this.turnView?.end();
|
|
547
|
+
const t = new InkTurn(this, o.steered ?? (() => []), !!o.steers, o.next ?? (() => []));
|
|
548
|
+
this.turnView = t;
|
|
549
|
+
this.completions = null;
|
|
550
|
+
this.schedule();
|
|
551
|
+
return t;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/** @internal */
|
|
555
|
+
endTurn(t: InkTurn): void {
|
|
556
|
+
if (this.turnView === t) this.turnView = null;
|
|
557
|
+
// Tab's candidates were for what was typed during the turn.
|
|
558
|
+
this.completions = null;
|
|
559
|
+
this.schedule();
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/** @internal */
|
|
563
|
+
summarize(labels: readonly string[]): string {
|
|
564
|
+
try { return this.o.summarize(labels); } catch { return ''; }
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/** Ask a secret: what is typed shows as `*` and stays out of the history. */
|
|
568
|
+
async secret<T>(run: () => Promise<T>): Promise<T> {
|
|
569
|
+
this.masked = true;
|
|
570
|
+
this.editor.noHistory = true;
|
|
571
|
+
this.schedule();
|
|
572
|
+
try {
|
|
573
|
+
return await run();
|
|
574
|
+
} finally {
|
|
575
|
+
this.masked = false;
|
|
576
|
+
this.editor.noHistory = false;
|
|
577
|
+
this.schedule();
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/** Something the region shows changed. */
|
|
582
|
+
refresh(): void { this.schedule(); }
|
|
583
|
+
|
|
584
|
+
private echo(kind: string, q: string, text: string): void {
|
|
585
|
+
// A bare Enter at the message prompt (a refresh) leaves no line behind.
|
|
586
|
+
if (kind === 'message') { if (text.trim()) this.owner(text); return; }
|
|
587
|
+
this.questionLine(q, this.masked ? '*'.repeat([...text].length) : text);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
private questionLine(q: string, text: string): void {
|
|
591
|
+
this.breakTail();
|
|
592
|
+
this.pending += `${cleanStream(q.replace(/^\n+/, ''))}${cleanStream(text)}\n`;
|
|
593
|
+
this.schedule();
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// ── keys ──
|
|
597
|
+
|
|
598
|
+
/** One key of the session (the shell routes every keypress here while the view is up). */
|
|
599
|
+
key(s: string | undefined, key: Key = {}): void {
|
|
600
|
+
if (this.closing) return;
|
|
601
|
+
const e = this.editor;
|
|
602
|
+
const plain = !key.ctrl && !key.meta && !key.shift;
|
|
603
|
+
if (key.name !== 'tab') this.completions = null;
|
|
604
|
+
if (key.ctrl && key.name === 'c') {
|
|
605
|
+
e.emit('keypress', s, key);
|
|
606
|
+
this.o.onInterrupt();
|
|
607
|
+
this.schedule();
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
if (key.name === 'tab' && !e.pasting && !key.ctrl && !key.meta) {
|
|
611
|
+
// During a turn Tab queues what is typed for the next turn, unless it
|
|
612
|
+
// is a command, which it completes as at the prompt.
|
|
613
|
+
const command = e.line.trimStart().startsWith('/') && !this.ask.drafting?.().length;
|
|
614
|
+
if (this.turnView && !command) this.ask.queueEdit?.();
|
|
615
|
+
else this.complete();
|
|
616
|
+
} else if (key.name === 'backspace' && plain && !e.pasting && e.cursor === 0 && this.ask.unwind?.()) {
|
|
617
|
+
// The line before comes back, joined.
|
|
618
|
+
} else if (key.ctrl && !key.meta && key.name === 'u' && !e.pasting && this.ask.drafting?.().length && this.ask.clearBox?.()) {
|
|
619
|
+
// Ctrl-U on a message of several lines: all of it goes, not only this line.
|
|
620
|
+
} else if (key.name === 'up' && plain && !e.pasting && !this.ask.waiting?.() && e.line === ''
|
|
621
|
+
&& !this.ask.drafting?.().length && (this.ask.queued?.().length || this.ask.held?.count())) {
|
|
622
|
+
// ↑ on an empty line while the shell is busy: the newest queued entry, back to edit.
|
|
623
|
+
this.ask.recall?.();
|
|
624
|
+
} else {
|
|
625
|
+
e.handle(s, key);
|
|
626
|
+
}
|
|
627
|
+
e.emit('keypress', s, key);
|
|
628
|
+
if (key.name === 'escape') this.o.onEscape();
|
|
629
|
+
this.schedule();
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// As readline: the candidates' common start is filled in; when it adds
|
|
633
|
+
// nothing, the candidates are listed under the box.
|
|
634
|
+
private complete(): void {
|
|
635
|
+
const e = this.editor;
|
|
636
|
+
const r = completeAt(e.line, e.cursor, (before) => this.o.complete(before));
|
|
637
|
+
if (r.line !== e.line) e.replaceBefore(e.cursor, r.line.slice(0, r.cursor));
|
|
638
|
+
if (r.list) this.completions = r.list;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
// ── frames ──
|
|
642
|
+
|
|
643
|
+
/** @internal Redraw at the next frame. */
|
|
644
|
+
schedule(): void {
|
|
645
|
+
if (this.done) {
|
|
646
|
+
const t = this.pending + this.tail;
|
|
647
|
+
this.pending = '';
|
|
648
|
+
this.tail = '';
|
|
649
|
+
if (t) this.o.stdout.write(t);
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
if (this.timer || !this.inst || this.hidden) return;
|
|
653
|
+
const wait = Math.max(0, this.lastFrame + this.frameMs - Date.now());
|
|
654
|
+
this.timer = setTimeout(() => this.frame(), wait);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
/** Resolves once nothing is due: what was pending is on the screen, no
|
|
658
|
+
* frame waits, and a frame's time has passed (Ink's own 32 ms window), so
|
|
659
|
+
* the screen is the last frame (tests). */
|
|
660
|
+
async settle(): Promise<void> {
|
|
661
|
+
for (let i = 0; i < 25; i++) {
|
|
662
|
+
if (this.timer) await new Promise<void>((r) => this.settled.push(r));
|
|
663
|
+
await new Promise((r) => setTimeout(r, this.frameMs));
|
|
664
|
+
if (!this.timer) return;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
private frame(): void {
|
|
669
|
+
if (this.timer) clearTimeout(this.timer);
|
|
670
|
+
this.timer = null;
|
|
671
|
+
if (!this.inst) return;
|
|
672
|
+
this.lastFrame = Date.now();
|
|
673
|
+
const { tree, commit } = this.layout();
|
|
674
|
+
const text = this.pending + commit;
|
|
675
|
+
this.pending = '';
|
|
676
|
+
try {
|
|
677
|
+
this.inst.rerender(tree);
|
|
678
|
+
if (text) (this.writeOut ?? ((t: string) => this.o.stdout.write(t)))(text);
|
|
679
|
+
} catch {
|
|
680
|
+
// Ink failed to draw: the text still reaches the terminal.
|
|
681
|
+
if (text) this.o.stdout.write(text);
|
|
682
|
+
}
|
|
683
|
+
for (const r of this.settled.splice(0)) r();
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
private tree(rows: El[] = []): El {
|
|
687
|
+
return this.h(this.o.lib.ink.Box, { flexDirection: 'column' }, this.h(this.Grab), ...rows);
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
private text(props: Props, ...children: unknown[]): El {
|
|
691
|
+
const p: Record<string, unknown> = { ...(props ?? {}) };
|
|
692
|
+
if (!this.colors) for (const k of ['color', 'backgroundColor', 'dimColor']) delete p[k];
|
|
693
|
+
return this.h(this.o.lib.ink.Text, p, ...children);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
/** The region's rows, bottom part first measured, and the tail rows that no longer fit (to the transcript). */
|
|
697
|
+
private layout(): { tree: El; commit: string } {
|
|
698
|
+
if (this.hidden) {
|
|
699
|
+
const commit = this.tail ? `${this.tail}\n` : '';
|
|
700
|
+
this.tail = '';
|
|
701
|
+
return { tree: this.tree(), commit };
|
|
702
|
+
}
|
|
703
|
+
const cols = Math.max(20, (this.o.stdout.columns || 80) - 1);
|
|
704
|
+
const height = Math.max(MIN_ROWS, this.o.stdout.rows || 24);
|
|
705
|
+
const turn = this.turnView;
|
|
706
|
+
const w = this.ask.waiting?.() ?? null;
|
|
707
|
+
|
|
708
|
+
// What was sent during the turn and waits: inserted into it (for the
|
|
709
|
+
// agent to read at its next step), or for the next turn.
|
|
710
|
+
const waiting: Array<{ text: string; how: string }> = [
|
|
711
|
+
...(turn ? turn.steered().map((text) => ({ text, how: WAITING_AGENT })) : []),
|
|
712
|
+
...(this.ask.queued?.() ?? []).map((q) => ({ text: q.text, how: WAITING_TURN })),
|
|
713
|
+
// Taken by the agent as a new message: it waits for its own turn.
|
|
714
|
+
...(turn ? turn.next().map((text) => ({ text, how: WAITING_TURN })) : []),
|
|
715
|
+
];
|
|
716
|
+
const shownWaiting = waiting.length > 4 ? [...waiting.slice(0, 3), { text: '', how: `… and ${waiting.length - 3} more` }] : waiting;
|
|
717
|
+
const named = (t: string): string => { try { return this.o.ownerText?.(t) ?? t; } catch { return t; } };
|
|
718
|
+
let waitRows = shownWaiting.map(({ text, how }) => {
|
|
719
|
+
if (!text) return this.text({ dimColor: true }, ` ${how}`);
|
|
720
|
+
const main = fitRow(`${INK_PROMPT}${cleanCell(oneLine(named(text)))} `, Math.max(8, cols - how.length - 2));
|
|
721
|
+
return this.text(null, this.text({ backgroundColor: 'gray' }, main), this.text({ dimColor: true }, ` ${how}`));
|
|
722
|
+
});
|
|
723
|
+
|
|
724
|
+
// The status row: what the agent does (or what is awaited), and what waits for the owner.
|
|
725
|
+
const counts = this.context.counts();
|
|
726
|
+
const left = turn ? turn.statusLine() : this.waitStatus;
|
|
727
|
+
let statusRow: El | null = null;
|
|
728
|
+
if (left || counts) {
|
|
729
|
+
const room = Math.max(4, cols - (counts ? width(counts) + 2 : 0));
|
|
730
|
+
statusRow = this.h(this.o.lib.ink.Box, { width: cols, justifyContent: 'space-between' },
|
|
731
|
+
this.text(null, left ? fitRow(left, room) : ''),
|
|
732
|
+
this.text({ color: 'yellow' }, counts ? fitRow(counts, cols - 1) : ''));
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
// The input: the message's earlier lines, then the line with the cursor.
|
|
736
|
+
const draft = this.ask.drafting?.() ?? [];
|
|
737
|
+
const asking = w && w.kind !== 'message';
|
|
738
|
+
const first = asking ? cleanCell(w!.q.replace(/^\n+/, '')).trimStart() : INK_PROMPT;
|
|
739
|
+
let draftShown = draft.length > 4 ? [draft[0], `(${draft.length - 3} more lines)`, ...draft.slice(-2)] : draft;
|
|
740
|
+
const lineRows = this.lineRows(draft.length ? ' ' : first, cols, Math.max(1, height - 14));
|
|
741
|
+
|
|
742
|
+
const back = !w && waiting.some((x) => x.how === WAITING_TURN) ? ' · ↑ edits queued' : '';
|
|
743
|
+
// Esc first: on a narrow screen what is cut is the end.
|
|
744
|
+
const hint = turn
|
|
745
|
+
? `Esc stops · ${turn.steers ? 'Enter steers · Tab queues' : 'Enter queues'}${back}`
|
|
746
|
+
: asking ? 'Esc cancels' : w ? 'Tab completes · /help' : back.slice(3);
|
|
747
|
+
// While a wait is on the status row (a start, a reset), it says the phase.
|
|
748
|
+
const state = this.waitStatus ? '' : this.context.state?.() ?? '';
|
|
749
|
+
const footer = [this.context.agent(), state, hint].filter(Boolean).join(' · ');
|
|
750
|
+
let footerRow: El | null = footer ? this.text({ dimColor: true }, fitRow(footer, cols)) : null;
|
|
751
|
+
let compRows: El[] = this.completions ? this.candidateRows(this.completions, cols).map((r) => this.text({ dimColor: true }, r)) : [];
|
|
752
|
+
const rule = this.text({ dimColor: true }, '─'.repeat(cols));
|
|
753
|
+
const count = (): number => waitRows.length + (statusRow ? 1 : 0) + 2 + draftShown.length + lineRows.length + (footerRow ? 1 : 0) + compRows.length;
|
|
754
|
+
// A short screen: the least needed goes first, so the region stays below the screen's height.
|
|
755
|
+
const budget = height - 2;
|
|
756
|
+
if (count() > budget) compRows = compRows.slice(0, 1);
|
|
757
|
+
if (count() > budget) compRows = [];
|
|
758
|
+
if (count() > budget) waitRows = waitRows.slice(-1);
|
|
759
|
+
if (count() > budget) draftShown = draftShown.length ? [`(${draft.length} earlier lines)`] : [];
|
|
760
|
+
if (count() > budget) footerRow = null;
|
|
761
|
+
if (count() > budget) statusRow = null;
|
|
762
|
+
const inputRows: El[] = [
|
|
763
|
+
...draftShown.map((d, i) => this.text(null, fitRow(`${i === 0 ? first : ' '}${cleanCell(d)}`, cols))),
|
|
764
|
+
...lineRows,
|
|
765
|
+
];
|
|
766
|
+
const below: El[] = [
|
|
767
|
+
...waitRows,
|
|
768
|
+
...(statusRow ? [statusRow] : []),
|
|
769
|
+
rule,
|
|
770
|
+
...inputRows,
|
|
771
|
+
rule,
|
|
772
|
+
...(footerRow ? [footerRow] : []),
|
|
773
|
+
...compRows,
|
|
774
|
+
];
|
|
775
|
+
|
|
776
|
+
// The tail in what is left of the screen, wrapped between words; past
|
|
777
|
+
// that, its first rows go to the transcript as they are shown.
|
|
778
|
+
let commit = '';
|
|
779
|
+
let tailRows = this.tail ? wrapRows(this.tail, cols) : [];
|
|
780
|
+
const room = Math.max(0, height - 1 - below.length);
|
|
781
|
+
if (tailRows.length > room) {
|
|
782
|
+
const head = tailRows.slice(0, tailRows.length - room);
|
|
783
|
+
commit = head.map((r) => `${r.text}\n`).join('');
|
|
784
|
+
this.tail = this.tail.slice(head[head.length - 1].end);
|
|
785
|
+
tailRows = tailRows.slice(head.length);
|
|
786
|
+
}
|
|
787
|
+
return { tree: this.tree([...tailRows.map((r) => this.text(null, r.text)), ...below]), commit };
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
/** Tab's candidates in columns, at most three rows (the last one says how many more). */
|
|
791
|
+
private candidateRows(list: readonly string[], cols: number): string[] {
|
|
792
|
+
const items = list.map((c) => cleanCell(c) || ' ');
|
|
793
|
+
const colW = Math.min(cols, Math.max(...items.map(width)) + 2);
|
|
794
|
+
const per = Math.max(1, Math.floor(cols / colW));
|
|
795
|
+
const rows: string[] = [];
|
|
796
|
+
for (let i = 0; i < items.length && rows.length < 3; i += per) {
|
|
797
|
+
rows.push(fitRow(items.slice(i, i + per).map((c) => c + ' '.repeat(Math.max(0, colW - width(c)))).join('').trimEnd(), cols));
|
|
798
|
+
}
|
|
799
|
+
const shown = Math.min(items.length, per * 3);
|
|
800
|
+
if (shown < items.length) rows[2] = fitRow(`${rows[2].slice(0, Math.max(0, cols - 14))}… +${items.length - shown} more`, cols);
|
|
801
|
+
return rows;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
/** The line being edited after `prefix`, in rows, the cursor inverted; at most `max` rows, around the cursor. */
|
|
805
|
+
private lineRows(prefix: string, cols: number, max: number): El[] {
|
|
806
|
+
const e = this.editor;
|
|
807
|
+
// The owner's own text, one display unit per UTF-16 unit, so the cursor's offset holds.
|
|
808
|
+
// eslint-disable-next-line no-control-regex
|
|
809
|
+
const safe = (t: string): string => t.replace(/[\u0000-\u001f\u007f-\u009f]/g, ' ').replace(/\p{Cf}/gu, (m) => ' '.repeat(m.length));
|
|
810
|
+
const pre = cleanCell(prefix);
|
|
811
|
+
const disp = pre + (this.masked ? '*'.repeat([...e.line].length) : safe(e.line));
|
|
812
|
+
const at = pre.length + (this.masked ? [...e.line.slice(0, e.cursor)].length : e.cursor);
|
|
813
|
+
const rows = splitRows(disp, cols).map((r, i, all) => ({ start: i ? all[i - 1].end : 0, end: r.end }));
|
|
814
|
+
const last = rows[rows.length - 1];
|
|
815
|
+
if (at >= disp.length && width(disp.slice(last.start)) + 1 > cols) rows.push({ start: disp.length, end: disp.length });
|
|
816
|
+
let cur = rows.findIndex((r) => at >= r.start && at < r.end);
|
|
817
|
+
if (cur < 0) cur = rows.length - 1;
|
|
818
|
+
const from = Math.max(0, Math.min(cur - max + 1, rows.length - max));
|
|
819
|
+
return rows.slice(from, from + max).map((r, i) => {
|
|
820
|
+
if (from + i !== cur) return this.text(null, disp.slice(r.start, r.end));
|
|
821
|
+
const ch = at < disp.length ? String.fromCodePoint(disp.codePointAt(at)!) : ' ';
|
|
822
|
+
return this.text(null, disp.slice(r.start, at), this.h(this.o.lib.ink.Text, { inverse: true }, ch), disp.slice(at + ch.length, r.end));
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
// ── leaving ──
|
|
827
|
+
|
|
828
|
+
/** Take the region off the screen now, without waiting for a frame (the process is ending). */
|
|
829
|
+
closeNow(): void {
|
|
830
|
+
if (this.done || !this.inst) return;
|
|
831
|
+
this.closing = true;
|
|
832
|
+
this.hidden = true;
|
|
833
|
+
if (this.timer) clearTimeout(this.timer);
|
|
834
|
+
this.timer = null;
|
|
835
|
+
this.o.stdout.off('resize', this.onResize);
|
|
836
|
+
try {
|
|
837
|
+
this.inst.clear();
|
|
838
|
+
if (this.pending || this.tail) this.o.stdout.write(this.pending + (this.tail ? `${this.tail}\n` : ''));
|
|
839
|
+
this.pending = '';
|
|
840
|
+
this.tail = '';
|
|
841
|
+
this.inst.unmount();
|
|
842
|
+
} catch { /* the process is ending */ }
|
|
843
|
+
this.inst = null;
|
|
844
|
+
this.done = true;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
/** Take the region off the screen and give the terminal back; what is pending is written first. */
|
|
848
|
+
async close(): Promise<void> {
|
|
849
|
+
if (this.closing) return;
|
|
850
|
+
this.closing = true;
|
|
851
|
+
this.turnView?.end();
|
|
852
|
+
this.o.stdout.off('resize', this.onResize);
|
|
853
|
+
if (!this.inst) { this.done = true; this.schedule(); return; }
|
|
854
|
+
// No other frame from here: the last one hides the region and writes
|
|
855
|
+
// what is pending, drawn at once (more than Ink's 32 ms after the one
|
|
856
|
+
// before), so unmounting has nothing left to draw.
|
|
857
|
+
this.hidden = true;
|
|
858
|
+
if (this.timer) clearTimeout(this.timer);
|
|
859
|
+
this.timer = null;
|
|
860
|
+
const wait = this.lastFrame + this.frameMs - Date.now();
|
|
861
|
+
if (wait > 0) await new Promise((r) => setTimeout(r, wait));
|
|
862
|
+
this.frame();
|
|
863
|
+
try {
|
|
864
|
+
this.inst.clear();
|
|
865
|
+
this.inst.unmount();
|
|
866
|
+
} catch { /* the terminal is the shell's again either way */ }
|
|
867
|
+
this.inst = null;
|
|
868
|
+
this.done = true;
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* A chat turn under the Ink view: the reply goes to the transcript (its
|
|
874
|
+
* unfinished line drawn just above the region), the status row says what
|
|
875
|
+
* the agent does, and each run of tool calls becomes one dim line when the
|
|
876
|
+
* reply goes on or the turn ends.
|
|
877
|
+
*/
|
|
878
|
+
export class InkTurn implements TurnView {
|
|
879
|
+
readonly live = true;
|
|
880
|
+
/** Added to the status line's time (interactive.ts paintStatus). */
|
|
881
|
+
readonly stopHint = ' · Esc to stop';
|
|
882
|
+
private statusText: string | null = null;
|
|
883
|
+
private labels: string[] = [];
|
|
884
|
+
/** A run's line was just written: the reply's next text starts it own line. */
|
|
885
|
+
private gap = false;
|
|
886
|
+
private ended = false;
|
|
887
|
+
private spin = 0;
|
|
888
|
+
private readonly t0 = Date.now();
|
|
889
|
+
private readonly tick: ReturnType<typeof setInterval>;
|
|
890
|
+
|
|
891
|
+
constructor(private readonly screen: InkScreen, readonly steered: () => readonly string[], readonly steers: boolean, readonly next: () => readonly string[] = () => []) {
|
|
892
|
+
this.tick = setInterval(() => { this.spin++; screen.refresh(); }, 1000);
|
|
893
|
+
this.tick.unref?.();
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
write(s: string): void {
|
|
897
|
+
if (this.ended) return;
|
|
898
|
+
let t = cleanStream(s);
|
|
899
|
+
if (!t) return;
|
|
900
|
+
this.closeRun();
|
|
901
|
+
if (this.gap) {
|
|
902
|
+
t = t.replace(/^\n+/, '');
|
|
903
|
+
if (!t) return;
|
|
904
|
+
this.gap = false;
|
|
905
|
+
}
|
|
906
|
+
this.screen.write(t);
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
note(text: string): void {
|
|
910
|
+
if (this.ended) { this.screen.write(cleanStream(text)); return; }
|
|
911
|
+
const t = cleanStream(text).replace(/^\n+/, '').replace(/\n+$/, '');
|
|
912
|
+
if (t) this.screen.note(t);
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
/** A line after what the reply has written so far: its line ends there. */
|
|
916
|
+
after(text: string): void {
|
|
917
|
+
if (this.ended) { this.screen.write(cleanStream(text)); return; }
|
|
918
|
+
this.closeRun();
|
|
919
|
+
const t = cleanStream(text).replace(/^\n+/, '').replace(/\n+$/, '');
|
|
920
|
+
if (t) this.screen.after(t);
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
/** Lines that came between the reply's text (TurnView.breaks). */
|
|
924
|
+
get breaks(): number { return this.screen.breaks; }
|
|
925
|
+
|
|
926
|
+
status(text: string | null): void {
|
|
927
|
+
const t = text === null ? null : cleanCell(text);
|
|
928
|
+
if (t === this.statusText) return;
|
|
929
|
+
this.statusText = t;
|
|
930
|
+
this.screen.refresh();
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
/** An activity label as the stream reports it ("tool/call bash", "thinking"). */
|
|
934
|
+
activity(label: string): void {
|
|
935
|
+
if (!this.ended) this.labels.push(label);
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
refresh(): void { this.screen.refresh(); }
|
|
939
|
+
|
|
940
|
+
end(): void {
|
|
941
|
+
if (this.ended) return;
|
|
942
|
+
this.closeRun();
|
|
943
|
+
this.ended = true;
|
|
944
|
+
clearInterval(this.tick);
|
|
945
|
+
this.screen.endTurn(this);
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
/** The status row's text: the turn's own status, or how long it has been replying. */
|
|
949
|
+
statusLine(): string {
|
|
950
|
+
if (this.statusText) return this.statusText;
|
|
951
|
+
return `${SPIN[this.spin % SPIN.length]} replying… (${Math.floor((Date.now() - this.t0) / 1000)}s${this.stopHint})`;
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
private closeRun(): void {
|
|
955
|
+
if (!this.labels.length) return;
|
|
956
|
+
const sum = this.screen.summarize(this.labels);
|
|
957
|
+
this.labels = [];
|
|
958
|
+
if (!sum) return;
|
|
959
|
+
this.screen.dim(`· ${sum}`);
|
|
960
|
+
this.gap = true;
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
/** Mount the view (throws when Ink cannot draw). */
|
|
965
|
+
export function openInkScreen<A extends InkAsk>(o: InkScreenOptions<A>): InkScreen<A> {
|
|
966
|
+
const screen = new InkScreen(o);
|
|
967
|
+
screen.mount();
|
|
968
|
+
return screen;
|
|
969
|
+
}
|