@orkestrel/terminal 0.0.14 → 0.0.15
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 +10 -11
- package/dist/src/core/index.cjs +115 -80
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +265 -150
- package/dist/src/core/index.d.ts +265 -150
- package/dist/src/core/index.js +115 -80
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +102 -78
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +122 -92
- package/dist/src/server/index.d.ts +122 -92
- package/dist/src/server/index.js +102 -78
- package/dist/src/server/index.js.map +1 -1
- package/package.json +18 -19
package/dist/src/core/index.d.ts
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
|
-
import { CheckboxField } from '@orkestrel/form';
|
|
2
|
-
import { ConfirmField } from '@orkestrel/form';
|
|
3
|
-
import { DriverInterface } from '@orkestrel/database';
|
|
4
|
-
import { EditorField } from '@orkestrel/form';
|
|
5
|
-
import { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
6
|
-
import { EmitterHooks } from '@orkestrel/emitter';
|
|
7
|
-
import { EmitterInterface } from '@orkestrel/emitter';
|
|
8
|
-
import { FieldChoice } from '@orkestrel/form';
|
|
9
|
-
import { FieldError } from '@orkestrel/form';
|
|
10
|
-
import { FormInterface } from '@orkestrel/form';
|
|
11
|
-
import { FormSchema } from '@orkestrel/form';
|
|
12
|
-
import { FormValues } from '@orkestrel/form';
|
|
13
|
-
import { Guard } from '@orkestrel/contract';
|
|
14
|
-
import { JSONRecord } from '@orkestrel/contract';
|
|
15
|
-
import { PasswordField } from '@orkestrel/form';
|
|
16
|
-
import { Result } from '@orkestrel/contract';
|
|
17
|
-
import { SelectField } from '@orkestrel/form';
|
|
18
|
-
import { Style } from '@orkestrel/console';
|
|
19
|
-
import { StylerInterface } from '@orkestrel/console';
|
|
20
|
-
import { TableInterface } from '@orkestrel/database';
|
|
21
|
-
import { TextField } from '@orkestrel/form';
|
|
22
|
-
|
|
23
|
-
/** Names the `Accept` header value that opens the broker's SSE stream
|
|
1
|
+
import type { CheckboxField } from '@orkestrel/form';
|
|
2
|
+
import type { ConfirmField } from '@orkestrel/form';
|
|
3
|
+
import type { DriverInterface } from '@orkestrel/database';
|
|
4
|
+
import type { EditorField } from '@orkestrel/form';
|
|
5
|
+
import type { EmitterErrorHandler } from '@orkestrel/emitter';
|
|
6
|
+
import type { EmitterHooks } from '@orkestrel/emitter';
|
|
7
|
+
import type { EmitterInterface } from '@orkestrel/emitter';
|
|
8
|
+
import type { FieldChoice } from '@orkestrel/form';
|
|
9
|
+
import type { FieldError } from '@orkestrel/form';
|
|
10
|
+
import type { FormInterface } from '@orkestrel/form';
|
|
11
|
+
import type { FormSchema } from '@orkestrel/form';
|
|
12
|
+
import type { FormValues } from '@orkestrel/form';
|
|
13
|
+
import type { Guard } from '@orkestrel/contract';
|
|
14
|
+
import type { JSONRecord } from '@orkestrel/contract';
|
|
15
|
+
import type { PasswordField } from '@orkestrel/form';
|
|
16
|
+
import type { Result } from '@orkestrel/contract';
|
|
17
|
+
import type { SelectField } from '@orkestrel/form';
|
|
18
|
+
import type { Style } from '@orkestrel/console';
|
|
19
|
+
import type { StylerInterface } from '@orkestrel/console';
|
|
20
|
+
import type { TableInterface } from '@orkestrel/database';
|
|
21
|
+
import type { TextField } from '@orkestrel/form';
|
|
22
|
+
|
|
23
|
+
/** Names the `Accept` header value that opens the broker's SSE stream — `text/event-stream`. */
|
|
24
24
|
export declare const ACCEPT_EVENT_STREAM = "text/event-stream";
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
* Explains why {@link PromptInterface.answer} refused
|
|
27
|
+
* Explains why {@link PromptInterface.answer} refused — `unknown` for an id no form is parked
|
|
28
|
+
* under, `rejected` for values the authoritative form itself refused, carrying the `FieldError`
|
|
29
|
+
* list it reported. Names its axis with `reason`.
|
|
28
30
|
*
|
|
29
31
|
* @remarks
|
|
30
32
|
* - `unknown` — no form is parked under that id, or the one that was has already settled.
|
|
@@ -81,10 +83,10 @@ export declare interface ConfirmState {
|
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
/**
|
|
84
|
-
* Holds the control
|
|
85
|
-
* consults for the one-byte keys and the two-byte CRLF
|
|
86
|
-
* canonical `name` and whether it is a `ctrl` combination. The
|
|
87
|
-
* frozen.
|
|
86
|
+
* Holds the control byte (or CRLF pair) to key descriptor table
|
|
87
|
+
* {@link import('./helpers.js').parseKey} consults for the one-byte keys and the two-byte CRLF
|
|
88
|
+
* Enter chunk. Each entry carries the canonical `name` and whether it is a `ctrl` combination. The
|
|
89
|
+
* source of truth for that decode; frozen.
|
|
88
90
|
*
|
|
89
91
|
* @remarks
|
|
90
92
|
* `return` / `newline` / `return + newline` all map to `return` (one canonical Enter name) — a
|
|
@@ -99,7 +101,8 @@ export declare const CONTROL_NAMES: Readonly<Record<string, {
|
|
|
99
101
|
}>>;
|
|
100
102
|
|
|
101
103
|
/**
|
|
102
|
-
* Builds the initial checkbox-field
|
|
104
|
+
* Builds the initial checkbox-field reducer state — the offered choices, with every value in the
|
|
105
|
+
* field's `default` list pre-checked.
|
|
103
106
|
*
|
|
104
107
|
* @param field - The checkbox field to render
|
|
105
108
|
* @param styler - The styler used to render the view
|
|
@@ -109,7 +112,8 @@ export declare const CONTROL_NAMES: Readonly<Record<string, {
|
|
|
109
112
|
export declare function createCheckboxState(field: CheckboxField, styler?: StylerInterface, theme?: PromptThemeOptions): CheckboxState;
|
|
110
113
|
|
|
111
114
|
/**
|
|
112
|
-
* Builds the initial confirm-field
|
|
115
|
+
* Builds the initial confirm-field reducer state — the sanitized label and the declared default
|
|
116
|
+
* answer.
|
|
113
117
|
*
|
|
114
118
|
* @param field - The confirm field to render
|
|
115
119
|
* @param styler - The styler used to render the view
|
|
@@ -121,7 +125,8 @@ export declare function createConfirmState(field: ConfirmField, styler?: StylerI
|
|
|
121
125
|
/**
|
|
122
126
|
* Creates a {@link TerminalStoreInterface} backed by one table of the `databases` layer — the
|
|
123
127
|
* driver-pluggable twin of {@link createMemoryTerminalStore}, storing each endpoint's config
|
|
124
|
-
* snapshot as one opaque JSON column.
|
|
128
|
+
* snapshot as one opaque JSON column. The default driver is an in-memory `@orkestrel/database`
|
|
129
|
+
* driver.
|
|
125
130
|
*
|
|
126
131
|
* @param driver - The {@link DriverInterface} backing the table (default an in-memory driver)
|
|
127
132
|
* @returns A {@link TerminalStoreInterface}
|
|
@@ -136,7 +141,8 @@ export declare function createConfirmState(field: ConfirmField, styler?: StylerI
|
|
|
136
141
|
export declare function createDatabaseTerminalStore(driver?: DriverInterface): TerminalStoreInterface;
|
|
137
142
|
|
|
138
143
|
/**
|
|
139
|
-
* Builds the initial editor-field
|
|
144
|
+
* Builds the initial editor-field reducer state — the committed lines empty, and the declared
|
|
145
|
+
* default held for a finish with nothing typed.
|
|
140
146
|
*
|
|
141
147
|
* @param field - The editor field to render
|
|
142
148
|
* @param styler - The styler used to render the view
|
|
@@ -146,7 +152,8 @@ export declare function createDatabaseTerminalStore(driver?: DriverInterface): T
|
|
|
146
152
|
export declare function createEditorState(field: EditorField, styler?: StylerInterface, theme?: PromptThemeOptions): EditorState;
|
|
147
153
|
|
|
148
154
|
/**
|
|
149
|
-
* Builds the initial text-field
|
|
155
|
+
* Builds the initial text-field reducer state — the sanitized label, the declared default, the
|
|
156
|
+
* styler, and the resolved theme.
|
|
150
157
|
*
|
|
151
158
|
* @param field - The text field to render
|
|
152
159
|
* @param styler - The styler used to render the view
|
|
@@ -171,7 +178,8 @@ export declare function createInputState(field: TextField, styler?: StylerInterf
|
|
|
171
178
|
export declare function createMemoryTerminalStore(): TerminalStoreInterface;
|
|
172
179
|
|
|
173
180
|
/**
|
|
174
|
-
* Builds the initial password-field
|
|
181
|
+
* Builds the initial password-field reducer state — the text-field state, plus the mask glyph each
|
|
182
|
+
* typed character renders as.
|
|
175
183
|
*
|
|
176
184
|
* @param field - The password field to render
|
|
177
185
|
* @param styler - The styler used to render the view
|
|
@@ -206,9 +214,10 @@ export declare function createPasswordState(field: PasswordField, styler?: Style
|
|
|
206
214
|
export declare function createPrompt(options?: PromptOptions): PromptInterface;
|
|
207
215
|
|
|
208
216
|
/**
|
|
209
|
-
* Creates the SSE prompt {@link PromptClientInterface}
|
|
210
|
-
* endpoint, dispatches each received form to a local
|
|
211
|
-
* and POSTs the answer back. Universal — `fetch`
|
|
217
|
+
* Creates the SSE prompt {@link PromptClientInterface} bridge — it connects to a remote broker's
|
|
218
|
+
* SSE endpoint, dispatches each received form to a local
|
|
219
|
+
* {@link import('./types.js').TerminalInterface}, and POSTs the answer back. Universal — `fetch`
|
|
220
|
+
* and SSE are web standards.
|
|
212
221
|
*
|
|
213
222
|
* @param options - See {@link PromptClientOptions} (`url` + `terminal` required)
|
|
214
223
|
* @returns A {@link PromptClientInterface}
|
|
@@ -253,7 +262,8 @@ export declare function createPromptClient(options: PromptClientOptions): Prompt
|
|
|
253
262
|
export declare function createPromptTheme(options?: PromptThemeOptions): PromptTheme;
|
|
254
263
|
|
|
255
264
|
/**
|
|
256
|
-
* Builds the initial select-field
|
|
265
|
+
* Builds the initial select-field reducer state — the offered choices, with the focus pre-placed on
|
|
266
|
+
* the declared default.
|
|
257
267
|
*
|
|
258
268
|
* @param field - The select field to render
|
|
259
269
|
* @param styler - The styler used to render the view
|
|
@@ -263,9 +273,9 @@ export declare function createPromptTheme(options?: PromptThemeOptions): PromptT
|
|
|
263
273
|
export declare function createSelectState(field: SelectField, styler?: StylerInterface, theme?: PromptThemeOptions): SelectState;
|
|
264
274
|
|
|
265
275
|
/**
|
|
266
|
-
* Creates the multi-endpoint {@link TerminalManager} — a named registry of
|
|
267
|
-
*
|
|
268
|
-
*
|
|
276
|
+
* Creates the multi-endpoint {@link TerminalManager} — a named registry of {@link PromptInterface}
|
|
277
|
+
* brokers so several parties can `ask` forms of each other by name, with a transitive cycle check
|
|
278
|
+
* that refuses `DEADLOCK` across every in-flight ask.
|
|
269
279
|
*
|
|
270
280
|
* @param options - See {@link TerminalManagerOptions}
|
|
271
281
|
* @returns A {@link TerminalManager}
|
|
@@ -296,10 +306,11 @@ export declare const CTRL_E: string;
|
|
|
296
306
|
export declare const CTRL_U: string;
|
|
297
307
|
|
|
298
308
|
/**
|
|
299
|
-
* Implements a {@link TerminalStoreInterface} backed by one table of the `databases` layer — an
|
|
300
|
-
* durable
|
|
301
|
-
* `delete`) over a {@link TableInterface}, the driver-pluggable twin of the plain-`Map`
|
|
302
|
-
* {@link import('./MemoryTerminalStore.js').MemoryTerminalStore}.
|
|
309
|
+
* Implements a {@link TerminalStoreInterface} backed by one table of the `databases` layer — an
|
|
310
|
+
* endpoint's durable config state is a row, so persistence reduces to keyed point-access (`get` /
|
|
311
|
+
* `set` / `delete`) over a {@link TableInterface}, the driver-pluggable twin of the plain-`Map`
|
|
312
|
+
* {@link import('./MemoryTerminalStore.js').MemoryTerminalStore}. A stored `snapshot` is narrowed
|
|
313
|
+
* with {@link import('../validators.js').isTerminalSnapshot} on read.
|
|
303
314
|
*
|
|
304
315
|
* @remarks
|
|
305
316
|
* The store is driver-agnostic: it holds a single {@link TableInterface} whose backend (memory,
|
|
@@ -392,7 +403,7 @@ export declare const DEFAULT_MASK = "*";
|
|
|
392
403
|
*/
|
|
393
404
|
export declare const DEFAULT_PROMPT_THEME: PromptTheme;
|
|
394
405
|
|
|
395
|
-
/** Holds how long (ms) the {@link import('./types.js').PromptInterface} broker parks an unanswered
|
|
406
|
+
/** Holds how long (ms) the {@link import('./types.js').PromptInterface} broker parks an unanswered form before it expires — 5 minutes. */
|
|
396
407
|
export declare const DEFAULT_PROMPT_TIMEOUT_MS = 300000;
|
|
397
408
|
|
|
398
409
|
/** Holds how long (ms) the {@link import('./types.js').PromptClientInterface} waits before each reconnect attempt — 2 seconds. */
|
|
@@ -415,9 +426,10 @@ export declare function defaultTimer(callback: () => void, ms: number): TimerCan
|
|
|
415
426
|
export declare const DELETE: string;
|
|
416
427
|
|
|
417
428
|
/**
|
|
418
|
-
* Applies a single line-editing {@link KeyEvent} to a text buffer — the editing shared by input
|
|
419
|
-
* password
|
|
420
|
-
* `space` appends a space; ctrl-u clears the line
|
|
429
|
+
* Applies a single line-editing {@link KeyEvent} to a text buffer — the editing shared by input,
|
|
430
|
+
* password, and editor. A printable key appends its character; `backspace` drops the last
|
|
431
|
+
* character; `space` appends a space; ctrl-u clears the line; a key that edits nothing returns
|
|
432
|
+
* `undefined`.
|
|
421
433
|
*
|
|
422
434
|
* @param value - The buffer the field holds so far
|
|
423
435
|
* @param key - The decoded keypress to apply
|
|
@@ -474,7 +486,10 @@ export declare interface FetchInit {
|
|
|
474
486
|
*/
|
|
475
487
|
export declare function globalFetch(input: string, init?: FetchInit): Promise<Response>;
|
|
476
488
|
|
|
477
|
-
/**
|
|
489
|
+
/**
|
|
490
|
+
* Names the auth-token request header the {@link import('./types.js').PromptClientInterface} sends
|
|
491
|
+
* when a `token` is configured — `x-orkestrel-token`.
|
|
492
|
+
*/
|
|
478
493
|
export declare const HEADER_TOKEN = "x-orkestrel-token";
|
|
479
494
|
|
|
480
495
|
/**
|
|
@@ -509,8 +524,10 @@ export declare interface InputState {
|
|
|
509
524
|
export declare function isAbortError(error: unknown): boolean;
|
|
510
525
|
|
|
511
526
|
/**
|
|
512
|
-
* Checks whether `url` is an
|
|
513
|
-
* loopback address. Pure string parsing (no `URL` global), so it stays total on malformed input
|
|
527
|
+
* Checks whether `url` is an insecure remote endpoint — a plain `http://` URL whose host is not a
|
|
528
|
+
* loopback address. Pure string parsing (no `URL` global), so it stays total on malformed input;
|
|
529
|
+
* the {@link import('./PromptClient.js').PromptClient} warns once when a `token` would cross such
|
|
530
|
+
* an endpoint in cleartext.
|
|
514
531
|
*
|
|
515
532
|
* @remarks
|
|
516
533
|
* A loopback host (`localhost`, `127.0.0.1`, `[::1]`) over `http://` is exempt (local
|
|
@@ -530,7 +547,8 @@ export declare function isAbortError(error: unknown): boolean;
|
|
|
530
547
|
export declare function isInsecureRemote(url: string): boolean;
|
|
531
548
|
|
|
532
549
|
/**
|
|
533
|
-
* Narrows an unknown wire value to a {@link PendingForm} envelope
|
|
550
|
+
* Narrows an unknown wire value to a {@link PendingForm} envelope — the envelope alone, because the
|
|
551
|
+
* form package's `parseForm` owns the schema payload.
|
|
534
552
|
*
|
|
535
553
|
* @remarks
|
|
536
554
|
* This guard checks the transport record and proves only that `schema` is a record. The Form
|
|
@@ -550,8 +568,8 @@ export declare function isPendingForm(value: unknown): value is PendingForm;
|
|
|
550
568
|
export declare const isPendingFormStatus: Guard<PendingFormStatus>;
|
|
551
569
|
|
|
552
570
|
/**
|
|
553
|
-
* Checks whether a single character is
|
|
554
|
-
*
|
|
571
|
+
* Checks whether a single character is printable — the fallback test {@link parseKey} applies after
|
|
572
|
+
* the control bytes and the escape sequences, so the C0 controls and DEL are excluded.
|
|
555
573
|
*
|
|
556
574
|
* @param character - The single character to test
|
|
557
575
|
* @returns True if the character is at or above space and is not DEL; false otherwise
|
|
@@ -559,7 +577,7 @@ export declare const isPendingFormStatus: Guard<PendingFormStatus>;
|
|
|
559
577
|
export declare function isPrintable(character: string): boolean;
|
|
560
578
|
|
|
561
579
|
/**
|
|
562
|
-
* Narrows an unknown caught value to a {@link TerminalError}
|
|
580
|
+
* Narrows an unknown caught value to a {@link TerminalError}, so a caller can branch on its `code`.
|
|
563
581
|
*
|
|
564
582
|
* @param value - The value to test (typically a `catch` binding or a rejected prompt call)
|
|
565
583
|
* @returns True if `value` is a {@link TerminalError}; false otherwise
|
|
@@ -578,8 +596,8 @@ export declare function isPrintable(character: string): boolean;
|
|
|
578
596
|
export declare function isTerminalError(value: unknown): value is TerminalError;
|
|
579
597
|
|
|
580
598
|
/**
|
|
581
|
-
* Narrows an unknown value to a {@link TerminalSnapshot} —
|
|
582
|
-
* untrusted persisted row.
|
|
599
|
+
* Narrows an unknown value to a {@link TerminalSnapshot} — a non-empty `id` and an optional numeric
|
|
600
|
+
* `timeout`, the read boundary a store applies to an untrusted persisted row.
|
|
583
601
|
*
|
|
584
602
|
* @param value - The candidate snapshot read back from storage
|
|
585
603
|
* @returns True if the value carries a non-empty `id` and an optional numeric `timeout`; false otherwise
|
|
@@ -587,7 +605,8 @@ export declare function isTerminalError(value: unknown): value is TerminalError;
|
|
|
587
605
|
export declare const isTerminalSnapshot: Guard<TerminalSnapshot>;
|
|
588
606
|
|
|
589
607
|
/**
|
|
590
|
-
* Narrows an unknown value to a transport-neutral {@link WireEvent}
|
|
608
|
+
* Narrows an unknown value to a transport-neutral {@link WireEvent} — the guard a consumer's own
|
|
609
|
+
* transport applies to an inbound frame.
|
|
591
610
|
*
|
|
592
611
|
* @param value - The candidate wire event
|
|
593
612
|
* @returns True if the value carries an event name, serialized data, and an optional id; false otherwise
|
|
@@ -629,9 +648,10 @@ export declare interface KeyEvent {
|
|
|
629
648
|
|
|
630
649
|
/**
|
|
631
650
|
* Implements the in-memory {@link TerminalStoreInterface} — a process-lifetime `Map` of
|
|
632
|
-
* {@link TerminalSnapshot}
|
|
633
|
-
* {@link import('../factories.js').createMemoryTerminalStore} builds
|
|
634
|
-
* {@link import('./DatabaseTerminalStore.js').DatabaseTerminalStore}.
|
|
651
|
+
* {@link TerminalSnapshot} records keyed by endpoint id, the default store
|
|
652
|
+
* {@link import('../factories.js').createMemoryTerminalStore} builds and the exact twin of
|
|
653
|
+
* {@link import('./DatabaseTerminalStore.js').DatabaseTerminalStore}. It carries no idle expiry and
|
|
654
|
+
* no eviction.
|
|
635
655
|
*
|
|
636
656
|
* @remarks
|
|
637
657
|
* A plain `Map<string, TerminalSnapshot>` — the snapshot is already pure, self-contained CONFIG-only
|
|
@@ -692,13 +712,14 @@ export declare const NEWLINE: string;
|
|
|
692
712
|
* broker exposes, and the cancel for its expiry timer.
|
|
693
713
|
*
|
|
694
714
|
* @remarks
|
|
695
|
-
* `form` is the
|
|
715
|
+
* `form` is the authoritative form the caller parked, not a copy: an answer fills and submits this
|
|
696
716
|
* one, so a `custom` rule that never crossed the wire still decides. Expiry destroys it, which
|
|
697
717
|
* abandons it and settles the caller's promise through the form's own lifecycle. `pending` is the
|
|
698
718
|
* wire record, whose `status` tracks the ticket.
|
|
699
719
|
*/
|
|
700
720
|
export declare interface ParkedForm {
|
|
701
721
|
readonly form: FormInterface;
|
|
722
|
+
/** Lists every parked record (`pending()`), or looks one up by id (`pending(id)`). */
|
|
702
723
|
readonly pending: PendingForm;
|
|
703
724
|
readonly cancel: TimerCancelFunction;
|
|
704
725
|
}
|
|
@@ -708,7 +729,7 @@ export declare interface ParkedForm {
|
|
|
708
729
|
* say.
|
|
709
730
|
*
|
|
710
731
|
* @remarks
|
|
711
|
-
* `from` and `to` are the attribution edge, set
|
|
732
|
+
* `from` and `to` are the attribution edge, set only by a {@link TerminalManagerInterface}: which
|
|
712
733
|
* endpoint asked, which endpoint must answer. A direct broker caller passes no request at all.
|
|
713
734
|
*/
|
|
714
735
|
export declare interface ParkRequest {
|
|
@@ -718,16 +739,16 @@ export declare interface ParkRequest {
|
|
|
718
739
|
|
|
719
740
|
/**
|
|
720
741
|
* Decodes one keypress's bytes into a {@link KeyEvent} — total, never throws. A `Uint8Array` is
|
|
721
|
-
* read as UTF-8; the resulting string is matched against the known control bytes and the CRLF
|
|
722
|
-
*
|
|
723
|
-
*
|
|
742
|
+
* read as UTF-8; the resulting string is matched against the known control bytes and the CRLF pair
|
|
743
|
+
* ({@link CONTROL_NAMES}) and escape sequences ({@link SEQUENCE_NAMES}), falling back to a single
|
|
744
|
+
* printable character. An unrecognized sequence carries no `name`, with the raw `sequence`
|
|
724
745
|
* preserved.
|
|
725
746
|
*
|
|
726
747
|
* @remarks
|
|
727
748
|
* - **Single control byte.** A one-character control input (`return` / `backspace` / `tab` /
|
|
728
749
|
* `escape` / `space`, or a Ctrl combo `c` / `d` / `u` / `a` / `e`), or the two-byte `\r\n`
|
|
729
750
|
* CRLF pair, is looked up in {@link CONTROL_NAMES}, carrying its `ctrl` flag.
|
|
730
|
-
* - **Escape sequence.** A multi-byte ESC sequence (`up` / `down` / `left` / `right` in
|
|
751
|
+
* - **Escape sequence.** A multi-byte ESC sequence (`up` / `down` / `left` / `right` in both the
|
|
731
752
|
* `ESC[A` and `ESCOA` forms, plus `home` / `end` / `delete`) is looked up in
|
|
732
753
|
* {@link SEQUENCE_NAMES} and flagged `meta`.
|
|
733
754
|
* - **Printable character.** A single printable character becomes `name` = that character, with
|
|
@@ -769,8 +790,8 @@ export declare interface PasswordState {
|
|
|
769
790
|
}
|
|
770
791
|
|
|
771
792
|
/**
|
|
772
|
-
* Represents one form
|
|
773
|
-
* answer. The value a `pending` listener receives and the broker serializes over SSE to a
|
|
793
|
+
* Represents one form parked by the broker — an id-keyed, wire-safe record of a live form awaiting
|
|
794
|
+
* a remote answer. The value a `pending` listener receives and the broker serializes over SSE to a
|
|
774
795
|
* {@link PromptClientInterface}.
|
|
775
796
|
*
|
|
776
797
|
* @remarks
|
|
@@ -795,9 +816,9 @@ export declare interface PendingForm {
|
|
|
795
816
|
}
|
|
796
817
|
|
|
797
818
|
/**
|
|
798
|
-
* Names the lifecycle status of a parked {@link PendingForm} — where the
|
|
799
|
-
* where the form stands. A ticket is `pending` until somebody answers it; the form it carries
|
|
800
|
-
* its own status, and
|
|
819
|
+
* Names the lifecycle status of a parked {@link PendingForm} — where the ticket stands, which is
|
|
820
|
+
* not where the form stands. A ticket is `pending` until somebody answers it; the form it carries
|
|
821
|
+
* has its own status, and each is a separate fact about a separate entity.
|
|
801
822
|
*
|
|
802
823
|
* @remarks
|
|
803
824
|
* - `pending` — parked, awaiting {@link PromptInterface.answer}.
|
|
@@ -807,8 +828,9 @@ export declare interface PendingForm {
|
|
|
807
828
|
export declare type PendingFormStatus = 'pending' | 'answered' | 'expired';
|
|
808
829
|
|
|
809
830
|
/**
|
|
810
|
-
* Implements the headless form broker. It parks live forms, exposes their serialized schemas,
|
|
811
|
-
* remote answers to the authoritative form
|
|
831
|
+
* Implements the headless form broker. It parks live forms, exposes their serialized schemas,
|
|
832
|
+
* applies remote answers to the authoritative form, and abandons a parked form on timeout, release,
|
|
833
|
+
* or teardown.
|
|
812
834
|
*
|
|
813
835
|
* @remarks
|
|
814
836
|
* A parked record carries one call to `serializeForm`. A failed fill or submit leaves the record
|
|
@@ -841,8 +863,9 @@ export declare class Prompt implements PromptInterface {
|
|
|
841
863
|
}
|
|
842
864
|
|
|
843
865
|
/**
|
|
844
|
-
* Holds the
|
|
845
|
-
* the
|
|
866
|
+
* Holds the terminal-owned glyphs {@link DEFAULT_PROMPT_THEME} assembles its `icons` from, beside
|
|
867
|
+
* the console module's own success and error marks. Read only when the default theme is assembled;
|
|
868
|
+
* a view reads its resolved theme and never this constant. Frozen.
|
|
846
869
|
*
|
|
847
870
|
* @remarks
|
|
848
871
|
* - `question` — the leading mark on a prompt's message line.
|
|
@@ -867,8 +890,9 @@ export declare const PROMPT_ICONS: Readonly<{
|
|
|
867
890
|
export declare const PROMPT_ROLES: readonly PromptRole[];
|
|
868
891
|
|
|
869
892
|
/**
|
|
870
|
-
* Implements the SSE form bridge. It ingests serialized forms from a remote broker
|
|
871
|
-
* local terminal,
|
|
893
|
+
* Implements the SSE form bridge. It ingests serialized forms from a remote broker without waiting
|
|
894
|
+
* on a render, drives one form at a time through a local terminal, posts each answer back, and asks
|
|
895
|
+
* again when the authoritative form refuses one.
|
|
872
896
|
*
|
|
873
897
|
* @remarks
|
|
874
898
|
* - **Connect + reconnect.** {@link connect} opens the SSE stream and reconnects after a transport
|
|
@@ -880,8 +904,9 @@ export declare const PROMPT_ROLES: readonly PromptRole[];
|
|
|
880
904
|
* - **Safe local form.** The rendering copy omits every wire `pattern`, because Form compiles a
|
|
881
905
|
* pattern during local evaluation. The broker's parked form retains it and remains authoritative.
|
|
882
906
|
* - **Refusal retry.** A structured `rejected` response seeds a new rendering form with the values
|
|
883
|
-
*
|
|
884
|
-
* counter truncates the loop; acceptance, expiry, and the broker's own teardown
|
|
907
|
+
* the refused attempt submitted, applies every {@link FieldError} through `invalidate`, and asks
|
|
908
|
+
* again. No retry counter truncates the loop; acceptance, expiry, and the broker's own teardown
|
|
909
|
+
* are its bounds.
|
|
885
910
|
* - **Replay safety.** A replayed id is skipped while it is queued, rendering, or posting. Once an
|
|
886
911
|
* attempt ends, a later delivery of that id may be rendered again.
|
|
887
912
|
*
|
|
@@ -924,10 +949,10 @@ export declare type PromptClientEventMap = {
|
|
|
924
949
|
};
|
|
925
950
|
|
|
926
951
|
/**
|
|
927
|
-
* Declares the SSE form
|
|
928
|
-
* serialized {@link PendingForm} records from a remote broker, rebuilds each schema
|
|
929
|
-
* it through a {@link TerminalInterface}, and POSTs the answer back, so a human at
|
|
930
|
-
* answers forms a broker parked elsewhere.
|
|
952
|
+
* Declares the SSE form bridge — the client-side counterpart to {@link PromptInterface}. It
|
|
953
|
+
* receives serialized {@link PendingForm} records from a remote broker, rebuilds each schema
|
|
954
|
+
* locally, drives it through a {@link TerminalInterface}, and POSTs the answer back, so a human at
|
|
955
|
+
* this machine answers forms a broker parked elsewhere.
|
|
931
956
|
*
|
|
932
957
|
* @remarks
|
|
933
958
|
* - **Connect.** {@link connect} opens the SSE stream through the injected `fetch` and resolves
|
|
@@ -940,14 +965,29 @@ export declare type PromptClientEventMap = {
|
|
|
940
965
|
* the wire is never executed locally. The authoritative form decides.
|
|
941
966
|
* - **Refusal retries.** A rejected answer comes back with the parked form's own errors; the client
|
|
942
967
|
* applies them to the local form and asks again until the answer is accepted or the form expires.
|
|
943
|
-
* - **`connected`** reflects whether the stream is
|
|
968
|
+
* - **`connected`** reflects whether the stream is open.
|
|
944
969
|
*/
|
|
945
970
|
export declare interface PromptClientInterface {
|
|
971
|
+
/** Holds the typed emitter every client event is published on. */
|
|
946
972
|
readonly emitter: EmitterInterface<PromptClientEventMap>;
|
|
973
|
+
/** Holds the remote broker's SSE endpoint this client reads from and answers to. */
|
|
947
974
|
readonly url: string;
|
|
975
|
+
/** Reports whether the SSE stream is open. */
|
|
948
976
|
readonly connected: boolean;
|
|
977
|
+
/**
|
|
978
|
+
* Opens the stream and pumps it, queueing each received form for the local terminal; reconnects
|
|
979
|
+
* on the `delay` backoff.
|
|
980
|
+
*/
|
|
949
981
|
connect(): Promise<void>;
|
|
982
|
+
/**
|
|
983
|
+
* Stops the current connection and the reconnect loop. An active local render continues, and a
|
|
984
|
+
* later `connect()` can restart the stream.
|
|
985
|
+
*/
|
|
950
986
|
disconnect(): void;
|
|
987
|
+
/**
|
|
988
|
+
* Tears the client down permanently — disconnects, drops the queue, abandons the active local
|
|
989
|
+
* form, and destroys the emitter.
|
|
990
|
+
*/
|
|
951
991
|
destroy(): void;
|
|
952
992
|
}
|
|
953
993
|
|
|
@@ -957,8 +997,8 @@ export declare interface PromptClientInterface {
|
|
|
957
997
|
*
|
|
958
998
|
* @remarks
|
|
959
999
|
* - `url` — the remote broker's SSE endpoint. A GET opens the stream; answers POST back to it.
|
|
960
|
-
* - `terminal` — the
|
|
961
|
-
* at
|
|
1000
|
+
* - `terminal` — the local {@link TerminalInterface} each remote form is driven through, so a human
|
|
1001
|
+
* at this machine answers a form parked elsewhere.
|
|
962
1002
|
* - `token` — an optional auth token, sent as the {@link import('./constants.js').HEADER_TOKEN}
|
|
963
1003
|
* header on every request.
|
|
964
1004
|
* - `reconnect` — whether to reconnect after the stream drops, default true.
|
|
@@ -992,6 +1032,9 @@ export declare interface PromptClientOptions {
|
|
|
992
1032
|
*/
|
|
993
1033
|
export declare type PromptEventMap = {
|
|
994
1034
|
readonly pending: readonly [form: PendingForm];
|
|
1035
|
+
/**
|
|
1036
|
+
* Reports an accepted answer, carrying the parked form id and settled values.
|
|
1037
|
+
*/
|
|
995
1038
|
readonly answer: readonly [id: string, values: FormValues];
|
|
996
1039
|
readonly expire: readonly [id: string];
|
|
997
1040
|
};
|
|
@@ -1010,16 +1053,16 @@ export declare type PromptEventMap = {
|
|
|
1010
1053
|
export declare type PromptIcon = 'question' | 'pointer' | 'dot' | 'selected' | 'checked' | 'unchecked' | 'success' | 'error';
|
|
1011
1054
|
|
|
1012
1055
|
/**
|
|
1013
|
-
* Declares the headless form
|
|
1014
|
-
* arm of the local-TTY
|
|
1015
|
-
* each `pending` record to whoever can answer, and {@link answer} drives the
|
|
1016
|
-
* settlement.
|
|
1056
|
+
* Declares the headless form broker — parks a live form until somebody elsewhere answers it. The
|
|
1057
|
+
* headless arm of the local-TTY, headless, and remote trio: there is no terminal here, so a
|
|
1058
|
+
* transport forwards each `pending` record to whoever can answer, and {@link answer} drives the
|
|
1059
|
+
* parked form to settlement.
|
|
1017
1060
|
*
|
|
1018
1061
|
* @remarks
|
|
1019
1062
|
* - **The form is the unit.** {@link park} takes a live form, mints an id, emits `pending`, and
|
|
1020
1063
|
* returns the id. It wraps no promise, because the caller already holds one: the form's own
|
|
1021
1064
|
* `answer`.
|
|
1022
|
-
* - **The parked form is authoritative.** {@link answer} fills and submits
|
|
1065
|
+
* - **The parked form is authoritative.** {@link answer} fills and submits that form, so every rule
|
|
1023
1066
|
* it carries decides, including a `custom` validator the wire dropped. A refusal returns the
|
|
1024
1067
|
* form's own errors and leaves the form parked.
|
|
1025
1068
|
* - **Timeout abandons.** An unanswered form is destroyed after `timeout` ms; `expire` fires and
|
|
@@ -1040,15 +1083,34 @@ export declare type PromptIcon = 'question' | 'pointer' | 'dot' | 'selected' | '
|
|
|
1040
1083
|
* ```
|
|
1041
1084
|
*/
|
|
1042
1085
|
export declare interface PromptInterface {
|
|
1086
|
+
/** Holds the typed emitter every broker event is published on. */
|
|
1043
1087
|
readonly emitter: EmitterInterface<PromptEventMap>;
|
|
1088
|
+
/** Reports how many forms this broker holds parked. */
|
|
1044
1089
|
readonly count: number;
|
|
1090
|
+
/**
|
|
1091
|
+
* Parks a live form, mints its id, emits `pending`, and arms the expiry deadline. Returns the id;
|
|
1092
|
+
* the caller already holds the promise.
|
|
1093
|
+
*/
|
|
1045
1094
|
park(form: FormInterface, request?: ParkRequest): string;
|
|
1095
|
+
/** Lists every parked record (`pending()`), or looks one up by id (`pending(id)`). */
|
|
1046
1096
|
pending(): readonly PendingForm[];
|
|
1047
1097
|
pending(id: string): PendingForm | undefined;
|
|
1098
|
+
/**
|
|
1099
|
+
* Fills and submits the authoritative parked form. Accepted, it settles and the record is
|
|
1100
|
+
* dropped; refused, the form stays parked.
|
|
1101
|
+
*/
|
|
1048
1102
|
answer(id: string, values: FormValues): Result<FormValues, AnswerError>;
|
|
1103
|
+
/**
|
|
1104
|
+
* Releases a batch (`stop(ids)`, the array overload declared first), one id, or every parked
|
|
1105
|
+
* form. The broker stays usable.
|
|
1106
|
+
*/
|
|
1049
1107
|
stop(ids: readonly string[]): boolean;
|
|
1050
1108
|
stop(id: string): boolean;
|
|
1051
1109
|
stop(): void;
|
|
1110
|
+
/**
|
|
1111
|
+
* Tears the broker down — abandons every parked form, cancels every deadline, then destroys the
|
|
1112
|
+
* emitter. Idempotent.
|
|
1113
|
+
*/
|
|
1052
1114
|
destroy(): void;
|
|
1053
1115
|
}
|
|
1054
1116
|
|
|
@@ -1077,9 +1139,9 @@ export declare interface PromptOptions {
|
|
|
1077
1139
|
}
|
|
1078
1140
|
|
|
1079
1141
|
/**
|
|
1080
|
-
* Names one styling slot a rendered field paints through — the semantic axis of a
|
|
1081
|
-
* role says what a fragment
|
|
1082
|
-
* re-maps styled output by naming roles rather than reimplementing a renderer.
|
|
1142
|
+
* Names one styling slot a rendered field paints through — the semantic axis of a
|
|
1143
|
+
* {@link PromptTheme}. A role says what a fragment means; the theme decides what that meaning looks
|
|
1144
|
+
* like, so a consumer re-maps styled output by naming roles rather than reimplementing a renderer.
|
|
1083
1145
|
*
|
|
1084
1146
|
* @remarks
|
|
1085
1147
|
* - `question` — the leading mark on an active field's line.
|
|
@@ -1107,9 +1169,10 @@ export declare type PromptRole = 'question' | 'pointer' | 'message' | 'content'
|
|
|
1107
1169
|
export declare type PromptStatus = 'active' | 'submit' | 'cancel';
|
|
1108
1170
|
|
|
1109
1171
|
/**
|
|
1110
|
-
* Represents the result of one reducer step — the next `state`, the rendered `view`, the `status`,
|
|
1111
|
-
* `submit
|
|
1112
|
-
* the driver applies the next `state`, writes the `view`, and reads `value` on
|
|
1172
|
+
* Represents the result of one reducer step — the next `state`, the rendered `view`, the `status`,
|
|
1173
|
+
* and, on `submit` alone, the candidate `value`. The whole contract between a pure reducer and the
|
|
1174
|
+
* impure driver: the driver applies the next `state`, writes the `view`, and reads `value` on
|
|
1175
|
+
* `submit`.
|
|
1113
1176
|
*
|
|
1114
1177
|
* @typeParam T - The value this field resolves to, as its control admits it.
|
|
1115
1178
|
* @typeParam S - The reducer's concrete state shape, carried directly so `state` stays precisely
|
|
@@ -1120,7 +1183,7 @@ export declare type PromptStatus = 'active' | 'submit' | 'cancel';
|
|
|
1120
1183
|
* is the final state.
|
|
1121
1184
|
* - `view` — the styled string to render now, possibly multi-line. On a refused `submit` it carries
|
|
1122
1185
|
* the failure; the driver re-renders it each step.
|
|
1123
|
-
* - `value` — present
|
|
1186
|
+
* - `value` — present only on a `submit` step.
|
|
1124
1187
|
*/
|
|
1125
1188
|
export declare interface PromptStep<T, S> {
|
|
1126
1189
|
readonly state: S;
|
|
@@ -1130,9 +1193,9 @@ export declare interface PromptStep<T, S> {
|
|
|
1130
1193
|
}
|
|
1131
1194
|
|
|
1132
1195
|
/**
|
|
1133
|
-
* Represents a resolved
|
|
1134
|
-
* for every {@link PromptRole}. Plain JSON data with no functions, so it crosses the
|
|
1135
|
-
* form it decorates. Built by {@link import('./helpers.js').createPromptTheme}.
|
|
1196
|
+
* Represents a resolved presentation — the glyph for every {@link PromptIcon} and the console
|
|
1197
|
+
* {@link Style} for every {@link PromptRole}. Plain JSON data with no functions, so it crosses the
|
|
1198
|
+
* wire with the form it decorates. Built by {@link import('./helpers.js').createPromptTheme}.
|
|
1136
1199
|
*
|
|
1137
1200
|
* @remarks
|
|
1138
1201
|
* A role's value is the console module's own {@link Style} — the one style model the whole console
|
|
@@ -1147,8 +1210,8 @@ export declare interface PromptTheme {
|
|
|
1147
1210
|
}
|
|
1148
1211
|
|
|
1149
1212
|
/**
|
|
1150
|
-
* Represents the
|
|
1151
|
-
* and {@link import('./helpers.js').createPromptTheme} merges what is supplied over
|
|
1213
|
+
* Represents the partial {@link PromptTheme} an option bag carries — every icon and every role is
|
|
1214
|
+
* optional, and {@link import('./helpers.js').createPromptTheme} merges what is supplied over
|
|
1152
1215
|
* {@link import('./constants.js').DEFAULT_PROMPT_THEME} leaf by leaf. Supplying one icon or one
|
|
1153
1216
|
* role leaves every other slot at its default.
|
|
1154
1217
|
*/
|
|
@@ -1183,8 +1246,8 @@ export declare function reduceConfirm(state: ConfirmState, key: KeyEvent): Promp
|
|
|
1183
1246
|
/**
|
|
1184
1247
|
* Advances an editor prompt by one {@link KeyEvent} — the pure `(state, key) → PromptStep<string>`
|
|
1185
1248
|
* reducer. Printable characters extend the current line; backspace shrinks it; return commits the
|
|
1186
|
-
* current line and starts a fresh one; ctrl-d
|
|
1187
|
-
* default when empty
|
|
1249
|
+
* current line and starts a fresh one; ctrl-d finishes, joining every line and falling back to the
|
|
1250
|
+
* default when empty; ctrl-c cancels. The form validates the candidate after the driver fills it.
|
|
1188
1251
|
*
|
|
1189
1252
|
* @param state - The editor field's current reducer state
|
|
1190
1253
|
* @param key - The decoded keypress to apply
|
|
@@ -1216,7 +1279,7 @@ export declare function reducePassword(state: PasswordState, key: KeyEvent): Pro
|
|
|
1216
1279
|
|
|
1217
1280
|
/**
|
|
1218
1281
|
* Advances a select prompt by one {@link KeyEvent} — the pure `(state, key) → PromptStep<string>`
|
|
1219
|
-
* reducer. `up` / `down` (and `k` / `j`) move the focus,
|
|
1282
|
+
* reducer. `up` / `down` (and `k` / `j`) move the focus, wrapping at the ends; return submits the
|
|
1220
1283
|
* focused choice's `value`; ctrl-c cancels. An empty choice list can never submit (a higher layer
|
|
1221
1284
|
* guards against it); any other key is ignored.
|
|
1222
1285
|
*
|
|
@@ -1227,7 +1290,8 @@ export declare function reducePassword(state: PasswordState, key: KeyEvent): Pro
|
|
|
1227
1290
|
export declare function reduceSelect(state: SelectState, key: KeyEvent): PromptStep<string, SelectState>;
|
|
1228
1291
|
|
|
1229
1292
|
/**
|
|
1230
|
-
* Renders a checkbox-field
|
|
1293
|
+
* Renders a checkbox-field reducer state as a multi-line styled view — one box per choice, and the
|
|
1294
|
+
* selected count beneath them.
|
|
1231
1295
|
*
|
|
1232
1296
|
* @param state - The checkbox field's current reducer state
|
|
1233
1297
|
* @returns The rendered view — the header, one box per choice, and the selected count
|
|
@@ -1235,7 +1299,8 @@ export declare function reduceSelect(state: SelectState, key: KeyEvent): PromptS
|
|
|
1235
1299
|
export declare function renderCheckboxView(state: CheckboxState): string;
|
|
1236
1300
|
|
|
1237
1301
|
/**
|
|
1238
|
-
* Renders a confirm-field
|
|
1302
|
+
* Renders a confirm-field reducer state as a styled view — the header and the yes/no group, with
|
|
1303
|
+
* the default letter capitalized and painted by the `selected` role.
|
|
1239
1304
|
*
|
|
1240
1305
|
* @param state - The confirm field's current reducer state
|
|
1241
1306
|
* @returns The rendered view — the header and the yes/no group with the default capitalized
|
|
@@ -1243,7 +1308,8 @@ export declare function renderCheckboxView(state: CheckboxState): string;
|
|
|
1243
1308
|
export declare function renderConfirmView(state: ConfirmState): string;
|
|
1244
1309
|
|
|
1245
1310
|
/**
|
|
1246
|
-
* Renders an editor-field
|
|
1311
|
+
* Renders an editor-field reducer state as a multi-line styled view — the finish hint, the
|
|
1312
|
+
* committed lines, and the line in progress.
|
|
1247
1313
|
*
|
|
1248
1314
|
* @param state - The editor field's current reducer state
|
|
1249
1315
|
* @returns The rendered view — the hinted header, the committed lines, and the line in progress
|
|
@@ -1251,7 +1317,8 @@ export declare function renderConfirmView(state: ConfirmState): string;
|
|
|
1251
1317
|
export declare function renderEditorView(state: EditorState): string;
|
|
1252
1318
|
|
|
1253
1319
|
/**
|
|
1254
|
-
* Renders the styled failure line (`✖ message`) a form driver
|
|
1320
|
+
* Renders the styled failure line (`✖ message`) a form driver writes for each refused field before
|
|
1321
|
+
* it asks that field again.
|
|
1255
1322
|
*
|
|
1256
1323
|
* @param styler - The console styler that renders each role
|
|
1257
1324
|
* @param theme - The resolved prompt theme
|
|
@@ -1273,7 +1340,8 @@ export declare function renderErrorLine(styler: StylerInterface, theme: PromptTh
|
|
|
1273
1340
|
export declare function renderHintedHeader(styler: StylerInterface, theme: PromptTheme, message: string, hint?: string): string;
|
|
1274
1341
|
|
|
1275
1342
|
/**
|
|
1276
|
-
* Renders a text-field
|
|
1343
|
+
* Renders a text-field reducer state as a styled view — the header, the pointer, and the typed
|
|
1344
|
+
* value, or the default shown as a hint while nothing is typed.
|
|
1277
1345
|
*
|
|
1278
1346
|
* @param state - The text field's current reducer state
|
|
1279
1347
|
* @returns The rendered single-line view — header, pointer, and the typed value or the default
|
|
@@ -1281,7 +1349,8 @@ export declare function renderHintedHeader(styler: StylerInterface, theme: Promp
|
|
|
1281
1349
|
export declare function renderInputView(state: InputState): string;
|
|
1282
1350
|
|
|
1283
1351
|
/**
|
|
1284
|
-
* Renders a password-field
|
|
1352
|
+
* Renders a password-field reducer state as a styled view, with the value replaced by the mask
|
|
1353
|
+
* repeated so the secret is never echoed.
|
|
1285
1354
|
*
|
|
1286
1355
|
* @param state - The password field's current reducer state
|
|
1287
1356
|
* @returns The rendered view, with the mask repeated in place of the typed value
|
|
@@ -1300,7 +1369,8 @@ export declare function renderPasswordView(state: PasswordState): string;
|
|
|
1300
1369
|
export declare function renderPromptHeader(styler: StylerInterface, theme: PromptTheme, message: string): string;
|
|
1301
1370
|
|
|
1302
1371
|
/**
|
|
1303
|
-
* Renders a select-field
|
|
1372
|
+
* Renders a select-field reducer state as a multi-line styled view — one row per choice, with the
|
|
1373
|
+
* focused row marked and its help shown.
|
|
1304
1374
|
*
|
|
1305
1375
|
* @param state - The select field's current reducer state
|
|
1306
1376
|
* @returns The rendered view — the header, then one row per choice with the focused row marked
|
|
@@ -1336,7 +1406,8 @@ export declare const RETURN: string;
|
|
|
1336
1406
|
export declare function sanitizeDisplayText(text: string): string;
|
|
1337
1407
|
|
|
1338
1408
|
/**
|
|
1339
|
-
* Sanitizes every terminal-readable string in a parsed form schema
|
|
1409
|
+
* Sanitizes every terminal-readable string in a parsed form schema, keeping every identity and
|
|
1410
|
+
* answer string verbatim and dropping field metadata.
|
|
1340
1411
|
*
|
|
1341
1412
|
* @remarks
|
|
1342
1413
|
* Display strings pass through {@link sanitizeDisplayText}: labels, help, placeholders, masks,
|
|
@@ -1368,7 +1439,8 @@ export declare function sanitizeSchema(schema: FormSchema): FormSchema;
|
|
|
1368
1439
|
export declare function sanitizeThemeIcons(theme: PromptThemeOptions): PromptThemeOptions;
|
|
1369
1440
|
|
|
1370
1441
|
/**
|
|
1371
|
-
* Represents the immutable state a select field's reducer carries
|
|
1442
|
+
* Represents the immutable state a select field's reducer carries — the choices the list offers and
|
|
1443
|
+
* the index the cursor sits on.
|
|
1372
1444
|
*
|
|
1373
1445
|
* @remarks
|
|
1374
1446
|
* - `message` — the sanitized label the header renders.
|
|
@@ -1385,10 +1457,11 @@ export declare interface SelectState {
|
|
|
1385
1457
|
}
|
|
1386
1458
|
|
|
1387
1459
|
/**
|
|
1388
|
-
* Holds the exact escape
|
|
1389
|
-
* consults for the navigation
|
|
1390
|
-
* form (`ESCOA`…) of the arrows, plus the `home` / `end` / `delete`
|
|
1391
|
-
* their numeric-tilde variants
|
|
1460
|
+
* Holds the exact escape sequence to canonical key name table
|
|
1461
|
+
* {@link import('./helpers.js').parseKey} consults for the navigation and editing keys. Covers the
|
|
1462
|
+
* CSI form (`ESC[A`…) and the SS3 form (`ESCOA`…) of the arrows, plus the `home` / `end` / `delete`
|
|
1463
|
+
* CSI sequences with their numeric-tilde variants. The source of truth for the multi-byte key
|
|
1464
|
+
* decode; frozen.
|
|
1392
1465
|
*
|
|
1393
1466
|
* @remarks
|
|
1394
1467
|
* Terminals disagree on these: a cursor key is `ESC[A` (normal) or `ESCOA` (application mode),
|
|
@@ -1399,14 +1472,16 @@ export declare interface SelectState {
|
|
|
1399
1472
|
export declare const SEQUENCE_NAMES: Readonly<Record<string, string>>;
|
|
1400
1473
|
|
|
1401
1474
|
/**
|
|
1402
|
-
* Serializes the {@link WireEvent} a broker or manager sends when it is going away
|
|
1475
|
+
* Serializes the `destroy` {@link WireEvent} a broker or manager sends when it is going away, which
|
|
1476
|
+
* carries no payload.
|
|
1403
1477
|
*
|
|
1404
1478
|
* @returns The `destroy` frame, whose `data` is empty because the signal carries no payload
|
|
1405
1479
|
*/
|
|
1406
1480
|
export declare function serializeDestroy(): WireEvent;
|
|
1407
1481
|
|
|
1408
1482
|
/**
|
|
1409
|
-
* Serializes a parked
|
|
1483
|
+
* Serializes a parked form's expiry or release into an `expire` {@link WireEvent}, whose `data` is
|
|
1484
|
+
* the JSON `{ id }` payload.
|
|
1410
1485
|
*
|
|
1411
1486
|
* @param id - The id of the parked form that expired or was released
|
|
1412
1487
|
* @returns The `expire` frame, carrying the JSON-stringified `{ id }` payload as `data`
|
|
@@ -1414,7 +1489,8 @@ export declare function serializeDestroy(): WireEvent;
|
|
|
1414
1489
|
export declare function serializeExpire(id: string): WireEvent;
|
|
1415
1490
|
|
|
1416
1491
|
/**
|
|
1417
|
-
* Serializes a parked {@link PendingForm} into a {@link WireEvent}
|
|
1492
|
+
* Serializes a parked {@link PendingForm} into a `pending` {@link WireEvent}, whose frame `id` is
|
|
1493
|
+
* the form's own id.
|
|
1418
1494
|
*
|
|
1419
1495
|
* @param form - The parked form's wire-safe record
|
|
1420
1496
|
* @returns The `pending` frame — the JSON-stringified record as `data`, and the form's own `id`
|
|
@@ -1433,12 +1509,13 @@ export declare const SPACE = " ";
|
|
|
1433
1509
|
export declare const SSE_BUFFER_LIMIT = 1048576;
|
|
1434
1510
|
|
|
1435
1511
|
/**
|
|
1436
|
-
* Holds the SSE `event:` names the broker emits and the
|
|
1437
|
-
*
|
|
1512
|
+
* Holds the SSE `event:` names the broker emits and the
|
|
1513
|
+
* {@link import('./types.js').PromptClientInterface} dispatches on — `pending`, `expire`, and
|
|
1514
|
+
* `destroy`. Frozen; the source of truth for the wire event vocabulary.
|
|
1438
1515
|
*
|
|
1439
1516
|
* @remarks
|
|
1440
1517
|
* - `pending` — a serialized {@link import('./types.js').PendingForm} to dispatch and answer.
|
|
1441
|
-
* - `expire` — an `{ id }` payload: the broker expired or released a parked
|
|
1518
|
+
* - `expire` — an `{ id }` payload: the broker expired or released a parked form (the client drops it).
|
|
1442
1519
|
* - `destroy` — the broker is going away; the client disconnects (no auto-reconnect) but stays reusable.
|
|
1443
1520
|
*/
|
|
1444
1521
|
export declare const SSE_EVENTS: Readonly<{
|
|
@@ -1510,15 +1587,15 @@ export declare class TerminalError extends Error {
|
|
|
1510
1587
|
export declare type TerminalErrorCode = 'EXPIRE' | 'CANCEL' | 'DRIVER' | 'DEADLOCK' | 'TARGET' | 'LIMIT' | 'DESTROYED';
|
|
1511
1588
|
|
|
1512
1589
|
/**
|
|
1513
|
-
* Declares the contract for asking a form of a human at a keyboard —
|
|
1514
|
-
* question however many fields it holds. The server `Terminal` implements it
|
|
1515
|
-
* a {@link PromptClientInterface} holds one to answer forms parked elsewhere.
|
|
1590
|
+
* Declares the contract for asking a form of a human at a keyboard — `ask` and nothing beside it,
|
|
1591
|
+
* because a form is one question however many fields it holds. The server `Terminal` implements it
|
|
1592
|
+
* against a real TTY; a {@link PromptClientInterface} holds one to answer forms parked elsewhere.
|
|
1516
1593
|
*
|
|
1517
1594
|
* @remarks
|
|
1518
1595
|
* `ask` drives the form the caller passes: it walks the schema's fields in order, binds each
|
|
1519
1596
|
* keystroke through the form's own `fill`, submits, and returns the settled values. The returned
|
|
1520
1597
|
* promise is the form's `answer`, so a caller holding the form can await either one. Ctrl-c at an
|
|
1521
|
-
* interactive driver is the one exception: it rejects
|
|
1598
|
+
* interactive driver is the one exception: it rejects this promise with a `TerminalError` coded
|
|
1522
1599
|
* `CANCEL` and leaves the form `editing`, so the form's own `answer` stays pending for its owner.
|
|
1523
1600
|
*
|
|
1524
1601
|
* A driver never owns the form's lifetime. To interrupt an active walk, destroy the form: it
|
|
@@ -1526,28 +1603,32 @@ export declare type TerminalErrorCode = 'EXPIRE' | 'CANCEL' | 'DRIVER' | 'DEADLO
|
|
|
1526
1603
|
* is the only cancellation channel, which is why this contract needs no second method.
|
|
1527
1604
|
*/
|
|
1528
1605
|
export declare interface TerminalInterface {
|
|
1606
|
+
/**
|
|
1607
|
+
* Walks the given form to settlement and resolves its values. The Contract section names the
|
|
1608
|
+
* ctrl-c exception.
|
|
1609
|
+
*/
|
|
1529
1610
|
ask(form: FormInterface): Promise<FormValues>;
|
|
1530
1611
|
}
|
|
1531
1612
|
|
|
1532
1613
|
/**
|
|
1533
|
-
* Registers named {@link PromptInterface} brokers
|
|
1534
|
-
*
|
|
1535
|
-
*
|
|
1614
|
+
* Registers named {@link PromptInterface} brokers, one per endpoint, so several parties can `ask`
|
|
1615
|
+
* forms of each other by name with a `from` → `to` attribution edge on every parked form, and
|
|
1616
|
+
* refuses `DEADLOCK` on a transitive cycle across every in-flight ask.
|
|
1536
1617
|
*
|
|
1537
1618
|
* @remarks
|
|
1538
1619
|
* - **Registry.** `add(name, options?)` mints (or, if `name` is already mounted, returns the
|
|
1539
|
-
*
|
|
1620
|
+
* existing broker unchanged — idempotent, never clobbers a live/parked endpoint). Every mounted
|
|
1540
1621
|
* broker's `pending` / `answer` / `expire` events are re-emitted on the manager, attributed by
|
|
1541
1622
|
* `name`.
|
|
1542
|
-
* - **`ask`.** The target must already be mounted
|
|
1623
|
+
* - **`ask`.** The target must already be mounted through {@link add} — `ask` never auto-adds it;
|
|
1543
1624
|
* rejects `TARGET` for an unknown `to` (listing the known names). Rejects `DEADLOCK` when parking
|
|
1544
|
-
* `from → to` would close a cycle over the
|
|
1625
|
+
* `from → to` would close a cycle over the current in-flight edge set (walked transitively);
|
|
1545
1626
|
* otherwise parks the caller's live form through the target's broker and returns that form's own
|
|
1546
1627
|
* `answer` promise. Edge cleanup never alters the value or rejection the caller observes.
|
|
1547
1628
|
* - **Durable open / save.** `open(name)` restores an EMPTY broker from the `store` (parked
|
|
1548
1629
|
* Promises are process-bound and never resurrected); `save(name)` persists the endpoint's
|
|
1549
1630
|
* configured `timeout`.
|
|
1550
|
-
* - **Removal.** `remove` drops one endpoint, a batch (the array overload declared
|
|
1631
|
+
* - **Removal.** `remove` drops one endpoint, a batch (the array overload declared first), or every
|
|
1551
1632
|
* endpoint when called without an argument. It destroys each broker, which expires every form
|
|
1552
1633
|
* still parked on it. `destroy` is idempotent.
|
|
1553
1634
|
*
|
|
@@ -1582,8 +1663,8 @@ export declare class TerminalManager implements TerminalManagerInterface {
|
|
|
1582
1663
|
}
|
|
1583
1664
|
|
|
1584
1665
|
/**
|
|
1585
|
-
* Declares the manager's event map — the name-attributed re-emission of every mounted broker's
|
|
1586
|
-
* caller subscribes once for
|
|
1666
|
+
* Declares the manager's event map — the name-attributed re-emission of every mounted broker's
|
|
1667
|
+
* events, so a caller subscribes once for every endpoint instead of once per broker.
|
|
1587
1668
|
*
|
|
1588
1669
|
* @remarks
|
|
1589
1670
|
* - `pending` — an endpoint parked a form; the record itself carries `from` and `to`.
|
|
@@ -1598,8 +1679,8 @@ export declare type TerminalManagerEventMap = {
|
|
|
1598
1679
|
|
|
1599
1680
|
/**
|
|
1600
1681
|
* Declares a registry of named {@link PromptInterface} brokers, one per endpoint, so several
|
|
1601
|
-
* parties (agents, tools, humans) can ask forms of each other
|
|
1602
|
-
* `
|
|
1682
|
+
* parties (agents, tools, humans) can ask forms of each other by name, attributed with a `from` →
|
|
1683
|
+
* `to` edge on every parked record.
|
|
1603
1684
|
*
|
|
1604
1685
|
* @remarks
|
|
1605
1686
|
* - **Accessors.** `terminal(name)` looks up one endpoint's broker; `terminals()` lists every
|
|
@@ -1616,26 +1697,57 @@ export declare type TerminalManagerEventMap = {
|
|
|
1616
1697
|
* - **`open`** restores, or returns the live, broker for `name` from the `store`.
|
|
1617
1698
|
* - **`save`** persists an endpoint's config snapshot; false when there is no store, or `name` is
|
|
1618
1699
|
* unknown.
|
|
1619
|
-
* - **Batch `remove`.** The array overload is declared
|
|
1700
|
+
* - **Batch `remove`.** The array overload is declared first: `remove(names)` removes every listed
|
|
1620
1701
|
* endpoint and reports true only when all of them were mounted; `remove(name)` removes one;
|
|
1621
1702
|
* `remove()` removes every endpoint without destroying the manager.
|
|
1622
1703
|
* - **`destroy`** tears down every broker, then the manager's own emitter.
|
|
1623
1704
|
*/
|
|
1624
1705
|
export declare interface TerminalManagerInterface {
|
|
1706
|
+
/**
|
|
1707
|
+
* Holds the typed emitter every mounted broker's events are re-published on, attributed by name.
|
|
1708
|
+
*/
|
|
1625
1709
|
readonly emitter: EmitterInterface<TerminalManagerEventMap>;
|
|
1710
|
+
/** Reports how many endpoints are mounted. */
|
|
1626
1711
|
readonly count: number;
|
|
1712
|
+
/** Looks up one endpoint's broker by name. */
|
|
1627
1713
|
terminal(name: string): PromptInterface | undefined;
|
|
1714
|
+
/** Lists every mounted broker, in insertion order. */
|
|
1628
1715
|
terminals(): readonly PromptInterface[];
|
|
1716
|
+
/**
|
|
1717
|
+
* Mints, or returns unchanged, the broker for `name`. Idempotent; it never clobbers a live
|
|
1718
|
+
* endpoint.
|
|
1719
|
+
*/
|
|
1629
1720
|
add(name: string, options?: PromptOptions): PromptInterface;
|
|
1721
|
+
/**
|
|
1722
|
+
* Parks `form` from `from` to `to` and resolves with the settled values. Rejects `TARGET` or
|
|
1723
|
+
* `DEADLOCK`.
|
|
1724
|
+
*/
|
|
1630
1725
|
ask(from: string, to: string, form: FormInterface): Promise<FormValues>;
|
|
1726
|
+
/**
|
|
1727
|
+
* Lists every endpoint's parked records (`pending()`), or scopes to one endpoint (`pending(to)`).
|
|
1728
|
+
*/
|
|
1631
1729
|
pending(): readonly PendingForm[];
|
|
1632
1730
|
pending(to: string): readonly PendingForm[];
|
|
1731
|
+
/**
|
|
1732
|
+
* Routes an answer to the named endpoint's broker; `{ reason: 'target' }` when no endpoint
|
|
1733
|
+
* carries that name.
|
|
1734
|
+
*/
|
|
1633
1735
|
answer(to: string, id: string, values: FormValues): Result<FormValues, TerminalAnswerError>;
|
|
1736
|
+
/**
|
|
1737
|
+
* Returns the live broker for `name`, or restores an empty one from the `store`. Parked forms are
|
|
1738
|
+
* never resurrected.
|
|
1739
|
+
*/
|
|
1634
1740
|
open(name: string): Promise<PromptInterface | undefined>;
|
|
1741
|
+
/** Persists an endpoint's config snapshot; false with no store, or an unknown name. */
|
|
1635
1742
|
save(name: string): Promise<boolean>;
|
|
1743
|
+
/**
|
|
1744
|
+
* Removes a batch (`remove(names)`, the array overload declared first, true only when every name
|
|
1745
|
+
* was mounted), one endpoint, or every endpoint.
|
|
1746
|
+
*/
|
|
1636
1747
|
remove(names: readonly string[]): boolean;
|
|
1637
1748
|
remove(name: string): boolean;
|
|
1638
1749
|
remove(): void;
|
|
1750
|
+
/** Tears down every broker, then the manager's own emitter. */
|
|
1639
1751
|
destroy(): void;
|
|
1640
1752
|
}
|
|
1641
1753
|
|
|
@@ -1659,9 +1771,9 @@ export declare interface TerminalManagerOptions {
|
|
|
1659
1771
|
}
|
|
1660
1772
|
|
|
1661
1773
|
/**
|
|
1662
|
-
* Represents one endpoint's persisted
|
|
1663
|
-
* default. Parked forms are process-bound and are never resurrected, so `open` always
|
|
1664
|
-
*
|
|
1774
|
+
* Represents one endpoint's persisted config snapshot — `id` is the endpoint name and `timeout` its
|
|
1775
|
+
* configured default. Parked forms are process-bound and are never resurrected, so `open` always
|
|
1776
|
+
* restores an empty broker.
|
|
1665
1777
|
*/
|
|
1666
1778
|
export declare interface TerminalSnapshot {
|
|
1667
1779
|
readonly id: string;
|
|
@@ -1669,9 +1781,9 @@ export declare interface TerminalSnapshot {
|
|
|
1669
1781
|
}
|
|
1670
1782
|
|
|
1671
1783
|
/**
|
|
1672
|
-
* Represents one opaque persisted row — the shape a
|
|
1673
|
-
*
|
|
1674
|
-
* read.
|
|
1784
|
+
* Represents one opaque persisted row — the shape a table-backed store reads and writes. The store
|
|
1785
|
+
* is a `TableInterface<TerminalSnapshotRow>`, and `snapshot` is narrowed with
|
|
1786
|
+
* {@link import('./validators.js').isTerminalSnapshot} on read.
|
|
1675
1787
|
*/
|
|
1676
1788
|
export declare interface TerminalSnapshotRow {
|
|
1677
1789
|
readonly id: string;
|
|
@@ -1683,8 +1795,11 @@ export declare interface TerminalSnapshotRow {
|
|
|
1683
1795
|
* Every primitive is async; deleting an absent id is a no-op.
|
|
1684
1796
|
*/
|
|
1685
1797
|
export declare interface TerminalStoreInterface {
|
|
1798
|
+
/** Resolves the snapshot stored for `id`, or `undefined` when none is. */
|
|
1686
1799
|
get(id: string): Promise<TerminalSnapshot | undefined>;
|
|
1800
|
+
/** Inserts or replaces under the snapshot's own `id`; there is no id argument. */
|
|
1687
1801
|
set(snapshot: TerminalSnapshot): Promise<void>;
|
|
1802
|
+
/** Drops a snapshot by id. An absent id is a no-op, never a throw. */
|
|
1688
1803
|
delete(id: string): Promise<void>;
|
|
1689
1804
|
}
|
|
1690
1805
|
|
|
@@ -1702,7 +1817,7 @@ export { TimerHandler_2 as TimerHandler }
|
|
|
1702
1817
|
|
|
1703
1818
|
/**
|
|
1704
1819
|
* Toggles `index` in a readonly index list — copy-on-write, returning the new sorted-by-insertion
|
|
1705
|
-
* list.
|
|
1820
|
+
* list; the primitive {@link reduceCheckbox} calls.
|
|
1706
1821
|
*
|
|
1707
1822
|
* @param indices - The ticked indices, in tick order
|
|
1708
1823
|
* @param index - The index to add when absent, or drop when present
|