@nan0web/ui 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -14
- package/package.json +6 -4
- package/src/App/Command/DepsCommand.js +5 -9
- package/src/App/Core/CoreApp.js +18 -17
- package/src/App/Core/UI.js +11 -15
- package/src/App/Core/Widget.js +6 -10
- package/src/App/Core/index.js +3 -3
- package/src/App/Scenario.js +4 -4
- package/src/App/User/Command/Message.js +1 -1
- package/src/App/User/Command/index.js +1 -1
- package/src/App/User/UserApp.js +28 -21
- package/src/App/User/UserUI.js +2 -2
- package/src/App/User/index.js +2 -2
- package/src/App/index.js +5 -10
- package/src/Component/Process/Input.js +10 -17
- package/src/Component/Process/Process.js +3 -5
- package/src/Component/Process/index.js +2 -2
- package/src/Component/SortableList/SortableList.js +100 -0
- package/src/Component/SortableList/index.js +3 -0
- package/src/Component/Welcome/Input.js +2 -4
- package/src/Component/Welcome/Welcome.js +5 -9
- package/src/Component/Welcome/index.js +2 -2
- package/src/Component/index.js +5 -3
- package/src/Frame/Frame.js +163 -146
- package/src/Frame/Props.js +20 -20
- package/src/Locale.js +17 -18
- package/src/Model/User/User.js +3 -6
- package/src/Model/index.js +1 -1
- package/src/README.md.js +84 -94
- package/src/StdIn.js +8 -12
- package/src/StdOut.js +23 -27
- package/src/View/RenderOptions.js +1 -1
- package/src/View/View.js +40 -36
- package/src/core/Error/CancelError.js +2 -2
- package/src/core/Error/index.js +3 -5
- package/src/core/Flow.js +347 -0
- package/src/core/Form/Form.js +35 -33
- package/src/core/Form/Input.js +21 -6
- package/src/core/Form/Message.js +3 -6
- package/src/core/Form/index.js +4 -8
- package/src/core/InputAdapter.js +4 -6
- package/src/core/Message/Message.js +9 -12
- package/src/core/Message/OutputMessage.js +19 -17
- package/src/core/Message/index.js +2 -2
- package/src/core/OutputAdapter.js +12 -10
- package/src/core/Stream.js +1 -1
- package/src/core/StreamEntry.js +2 -2
- package/src/core/UiAdapter.js +31 -30
- package/src/core/index.js +33 -10
- package/src/functions.js +8 -15
- package/src/index.js +21 -32
- package/types/App/Command/DepsCommand.d.ts +1 -1
- package/types/App/Command/Options.d.ts +37 -40
- package/types/App/Command/index.d.ts +6 -6
- package/types/App/Core/CoreApp.d.ts +2 -2
- package/types/App/Core/UI.d.ts +4 -4
- package/types/App/Core/Widget.d.ts +4 -4
- package/types/App/Core/index.d.ts +3 -3
- package/types/App/Scenario.d.ts +1 -1
- package/types/App/User/Command/Message.d.ts +1 -1
- package/types/App/User/Command/Options.d.ts +29 -29
- package/types/App/User/Command/index.d.ts +1 -1
- package/types/App/User/UserApp.d.ts +5 -5
- package/types/App/User/index.d.ts +2 -2
- package/types/App/index.d.ts +4 -4
- package/types/Component/Process/Process.d.ts +2 -2
- package/types/Component/Process/index.d.ts +2 -2
- package/types/Component/SortableList/SortableList.d.ts +58 -0
- package/types/Component/SortableList/index.d.ts +2 -0
- package/types/Component/Welcome/Input.d.ts +1 -1
- package/types/Component/Welcome/Welcome.d.ts +1 -1
- package/types/Component/Welcome/index.d.ts +2 -2
- package/types/Component/index.d.ts +5 -3
- package/types/Frame/Frame.d.ts +1 -1
- package/types/Frame/Props.d.ts +1 -1
- package/types/Model/index.d.ts +1 -1
- package/types/StdIn.d.ts +2 -2
- package/types/StdOut.d.ts +1 -1
- package/types/View/View.d.ts +7 -7
- package/types/core/Error/index.d.ts +1 -1
- package/types/core/Flow.d.ts +320 -0
- package/types/core/Form/Form.d.ts +2 -2
- package/types/core/Form/Input.d.ts +11 -0
- package/types/core/Form/Message.d.ts +1 -1
- package/types/core/Form/index.d.ts +3 -3
- package/types/core/InputAdapter.d.ts +2 -2
- package/types/core/Intent.d.ts +65 -68
- package/types/core/Message/InputMessage.d.ts +65 -65
- package/types/core/Message/Message.d.ts +1 -1
- package/types/core/Message/OutputMessage.d.ts +1 -1
- package/types/core/Message/index.d.ts +2 -2
- package/types/core/Stream.d.ts +1 -1
- package/types/core/UiAdapter.d.ts +5 -5
- package/types/core/index.d.ts +4 -3
- package/types/index.d.ts +10 -10
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component types that can be yielded from a Flow.
|
|
3
|
+
*
|
|
4
|
+
* @typedef {'view' | 'prompt' | 'stream' | 'action' | 'flow'} ComponentType
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Base interface for all UI components.
|
|
8
|
+
*
|
|
9
|
+
* @typedef {Object} FlowComponent
|
|
10
|
+
* @property {ComponentType} type - Component type discriminator.
|
|
11
|
+
* @property {string} [name] - Optional component name for debugging.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Static view component (no user input required).
|
|
15
|
+
* Examples: Alert, Badge, Toast, Table, Text
|
|
16
|
+
*
|
|
17
|
+
* @typedef {Object} ViewComponent
|
|
18
|
+
* @property {'view'} type - Always 'view'.
|
|
19
|
+
* @property {string} name - Component name (e.g., 'Alert', 'Toast').
|
|
20
|
+
* @property {Object} props - Component-specific properties.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Interactive prompt component (requires user input).
|
|
24
|
+
* Examples: Input, Select, Confirm, Multiselect, Mask
|
|
25
|
+
*
|
|
26
|
+
* @typedef {Object} PromptComponent
|
|
27
|
+
* @property {'prompt'} type - Always 'prompt'.
|
|
28
|
+
* @property {string} name - Component name (e.g., 'Select', 'Input').
|
|
29
|
+
* @property {Object} props - Component-specific properties.
|
|
30
|
+
* @property {string} [props.message] - Prompt message to display.
|
|
31
|
+
* @property {any[]} [props.choices] - Options for Select/Multiselect.
|
|
32
|
+
* @property {Function} [props.validate] - Validation function.
|
|
33
|
+
*/
|
|
34
|
+
/**
|
|
35
|
+
* Streaming component for progress/async operations.
|
|
36
|
+
* Examples: Spinner, ProgressBar, StreamChunk
|
|
37
|
+
*
|
|
38
|
+
* @typedef {Object} StreamComponent
|
|
39
|
+
* @property {'stream'} type - Always 'stream'.
|
|
40
|
+
* @property {string} name - Component name (e.g., 'Spinner', 'Progress').
|
|
41
|
+
* @property {Object} props - Component-specific properties.
|
|
42
|
+
* @property {AsyncIterable} [iterable] - Async iterator for streaming content.
|
|
43
|
+
*/
|
|
44
|
+
/**
|
|
45
|
+
* Action component for physical or side-effect operations.
|
|
46
|
+
* Examples: Move, Sound, Light, Notify
|
|
47
|
+
*
|
|
48
|
+
* @typedef {Object} ActionComponent
|
|
49
|
+
* @property {'action'} type - Always 'action'.
|
|
50
|
+
* @property {string} name - Component name (e.g., 'Move', 'Beep').
|
|
51
|
+
* @property {Object} props - Component-specific properties.
|
|
52
|
+
*/
|
|
53
|
+
/**
|
|
54
|
+
* Result returned by prompt components.
|
|
55
|
+
*
|
|
56
|
+
* @typedef {Object} PromptResult
|
|
57
|
+
* @property {any} value - The value entered/selected by user.
|
|
58
|
+
* @property {boolean} [cancelled] - True if user cancelled the prompt.
|
|
59
|
+
*/
|
|
60
|
+
/**
|
|
61
|
+
* Adapter interface that all platform adapters must implement.
|
|
62
|
+
*
|
|
63
|
+
* @typedef {Object} FlowAdapter
|
|
64
|
+
* @property {(component: ViewComponent) => void | Promise<void>} renderView
|
|
65
|
+
* Renders a static view component.
|
|
66
|
+
* @property {(component: PromptComponent) => Promise<PromptResult>} executePrompt
|
|
67
|
+
* Execute an interactive prompt and returns user input.
|
|
68
|
+
* @property {(component: StreamComponent) => AsyncIterable} streamProgress
|
|
69
|
+
* Handles streaming components.
|
|
70
|
+
* @property {(component: ActionComponent) => Promise<any>} [executeAction]
|
|
71
|
+
* Executes an action component (physical or side-effect).
|
|
72
|
+
*/
|
|
73
|
+
/**
|
|
74
|
+
* Creates a View component.
|
|
75
|
+
*
|
|
76
|
+
* @param {string} name - Component name (e.g., 'Alert', 'Toast').
|
|
77
|
+
* @param {Object} props - Component properties.
|
|
78
|
+
* @returns {ViewComponent}
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* yield View('Alert', { variant: 'success', message: 'Done!' })
|
|
82
|
+
*/
|
|
83
|
+
export function View(name: string, props?: any): ViewComponent;
|
|
84
|
+
/**
|
|
85
|
+
* Creates a Prompt component.
|
|
86
|
+
*
|
|
87
|
+
* @param {string} name - Component name (e.g., 'Select', 'Input').
|
|
88
|
+
* @param {Object} props - Component properties.
|
|
89
|
+
* @returns {PromptComponent}
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* const value = yield Prompt('Select', { message: 'Choose:', choices: ['a', 'b'] })
|
|
93
|
+
*/
|
|
94
|
+
export function Prompt(name: string, props?: any): PromptComponent;
|
|
95
|
+
/**
|
|
96
|
+
* Creates a Stream component.
|
|
97
|
+
*
|
|
98
|
+
* @param {string} name - Component name (e.g., 'Spinner', 'Progress').
|
|
99
|
+
* @param {Object} props - Component properties.
|
|
100
|
+
* @returns {StreamComponent}
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* yield* Stream('Progress', { total: 100, current: 50 })
|
|
104
|
+
*/
|
|
105
|
+
export function Stream(name: string, props?: any): StreamComponent;
|
|
106
|
+
/**
|
|
107
|
+
* Creates an Action component.
|
|
108
|
+
*
|
|
109
|
+
* @param {string} name - Action name.
|
|
110
|
+
* @param {Object} props - Action properties.
|
|
111
|
+
* @returns {ActionComponent}
|
|
112
|
+
*/
|
|
113
|
+
export function Action(name: string, props?: any): ActionComponent;
|
|
114
|
+
/**
|
|
115
|
+
* Runs a Flow (async generator) with the provided adapter.
|
|
116
|
+
*
|
|
117
|
+
* The Flow runner iterates through yielded components and dispatches them
|
|
118
|
+
* to the appropriate adapter method based on component type.
|
|
119
|
+
*
|
|
120
|
+
* @param {AsyncGenerator} flow - The flow generator to execute.
|
|
121
|
+
* @param {FlowAdapter} adapter - The platform-specific adapter.
|
|
122
|
+
* @param {Object} [options={}] - Additional options.
|
|
123
|
+
* @param {AbortSignal} [options.signal] - Abort signal for cancellation.
|
|
124
|
+
* @returns {Promise<any>} The final return value of the flow.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* async function* loginFlow() {
|
|
128
|
+
* yield Alert({ message: 'Welcome!' })
|
|
129
|
+
* const username = yield Input({ message: 'Username:' })
|
|
130
|
+
* const password = yield Password({ message: 'Password:' })
|
|
131
|
+
* return { username, password }
|
|
132
|
+
* }
|
|
133
|
+
*
|
|
134
|
+
* const result = await runFlow(loginFlow(), cliAdapter)
|
|
135
|
+
*/
|
|
136
|
+
export function runFlow(flow: AsyncGenerator, adapter: FlowAdapter, options?: {
|
|
137
|
+
signal?: AbortSignal | undefined;
|
|
138
|
+
}): Promise<any>;
|
|
139
|
+
/**
|
|
140
|
+
* Wraps a nested flow for composition with yield*.
|
|
141
|
+
*
|
|
142
|
+
* @param {Function} flowFn - Flow generator function.
|
|
143
|
+
* @param {...any} args - Arguments to pass to the flow function.
|
|
144
|
+
* @returns {Object} A flow component.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* async function* mainFlow() {
|
|
148
|
+
* yield Alert({ message: 'Starting...' })
|
|
149
|
+
* const user = yield* flow(loginFlow)
|
|
150
|
+
* yield Alert({ message: `Welcome, ${user.name}!` })
|
|
151
|
+
* }
|
|
152
|
+
*/
|
|
153
|
+
export function flow(flowFn: Function, ...args: any[]): any;
|
|
154
|
+
export function Alert(props: any): ViewComponent;
|
|
155
|
+
export function Toast(props: any): ViewComponent;
|
|
156
|
+
export function Badge(props: any): ViewComponent;
|
|
157
|
+
export function Text(props: any): ViewComponent;
|
|
158
|
+
export function Table(props: any): ViewComponent;
|
|
159
|
+
export function Input(props: any): PromptComponent;
|
|
160
|
+
export function Select(props: any): PromptComponent;
|
|
161
|
+
export function Confirm(props: any): PromptComponent;
|
|
162
|
+
export function Multiselect(props: any): PromptComponent;
|
|
163
|
+
export function Mask(props: any): PromptComponent;
|
|
164
|
+
export function Password(props: any): PromptComponent;
|
|
165
|
+
export function Spinner(props: any): StreamComponent;
|
|
166
|
+
export function Progress(props: any): StreamComponent;
|
|
167
|
+
export function Beep(props: any): ActionComponent;
|
|
168
|
+
export function Move(props: any): ActionComponent;
|
|
169
|
+
declare namespace _default {
|
|
170
|
+
export { runFlow };
|
|
171
|
+
export { flow };
|
|
172
|
+
export { View };
|
|
173
|
+
export { Prompt };
|
|
174
|
+
export { Stream };
|
|
175
|
+
export { Alert };
|
|
176
|
+
export { Toast };
|
|
177
|
+
export { Badge };
|
|
178
|
+
export { Text };
|
|
179
|
+
export { Table };
|
|
180
|
+
export { Input };
|
|
181
|
+
export { Select };
|
|
182
|
+
export { Confirm };
|
|
183
|
+
export { Multiselect };
|
|
184
|
+
export { Mask };
|
|
185
|
+
export { Password };
|
|
186
|
+
export { Spinner };
|
|
187
|
+
export { Progress };
|
|
188
|
+
}
|
|
189
|
+
export default _default;
|
|
190
|
+
/**
|
|
191
|
+
* Component types that can be yielded from a Flow.
|
|
192
|
+
*/
|
|
193
|
+
export type ComponentType = "view" | "prompt" | "stream" | "action" | "flow";
|
|
194
|
+
/**
|
|
195
|
+
* Base interface for all UI components.
|
|
196
|
+
*/
|
|
197
|
+
export type FlowComponent = {
|
|
198
|
+
/**
|
|
199
|
+
* - Component type discriminator.
|
|
200
|
+
*/
|
|
201
|
+
type: ComponentType;
|
|
202
|
+
/**
|
|
203
|
+
* - Optional component name for debugging.
|
|
204
|
+
*/
|
|
205
|
+
name?: string | undefined;
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* Static view component (no user input required).
|
|
209
|
+
* Examples: Alert, Badge, Toast, Table, Text
|
|
210
|
+
*/
|
|
211
|
+
export type ViewComponent = {
|
|
212
|
+
/**
|
|
213
|
+
* - Always 'view'.
|
|
214
|
+
*/
|
|
215
|
+
type: "view";
|
|
216
|
+
/**
|
|
217
|
+
* - Component name (e.g., 'Alert', 'Toast').
|
|
218
|
+
*/
|
|
219
|
+
name: string;
|
|
220
|
+
/**
|
|
221
|
+
* - Component-specific properties.
|
|
222
|
+
*/
|
|
223
|
+
props: any;
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Interactive prompt component (requires user input).
|
|
227
|
+
* Examples: Input, Select, Confirm, Multiselect, Mask
|
|
228
|
+
*/
|
|
229
|
+
export type PromptComponent = {
|
|
230
|
+
/**
|
|
231
|
+
* - Always 'prompt'.
|
|
232
|
+
*/
|
|
233
|
+
type: "prompt";
|
|
234
|
+
/**
|
|
235
|
+
* - Component name (e.g., 'Select', 'Input').
|
|
236
|
+
*/
|
|
237
|
+
name: string;
|
|
238
|
+
/**
|
|
239
|
+
* - Component-specific properties.
|
|
240
|
+
*/
|
|
241
|
+
props: {
|
|
242
|
+
message?: string | undefined;
|
|
243
|
+
choices?: any[] | undefined;
|
|
244
|
+
validate?: Function | undefined;
|
|
245
|
+
};
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* Streaming component for progress/async operations.
|
|
249
|
+
* Examples: Spinner, ProgressBar, StreamChunk
|
|
250
|
+
*/
|
|
251
|
+
export type StreamComponent = {
|
|
252
|
+
/**
|
|
253
|
+
* - Always 'stream'.
|
|
254
|
+
*/
|
|
255
|
+
type: "stream";
|
|
256
|
+
/**
|
|
257
|
+
* - Component name (e.g., 'Spinner', 'Progress').
|
|
258
|
+
*/
|
|
259
|
+
name: string;
|
|
260
|
+
/**
|
|
261
|
+
* - Component-specific properties.
|
|
262
|
+
*/
|
|
263
|
+
props: any;
|
|
264
|
+
/**
|
|
265
|
+
* - Async iterator for streaming content.
|
|
266
|
+
*/
|
|
267
|
+
iterable?: AsyncIterable<any> | undefined;
|
|
268
|
+
};
|
|
269
|
+
/**
|
|
270
|
+
* Action component for physical or side-effect operations.
|
|
271
|
+
* Examples: Move, Sound, Light, Notify
|
|
272
|
+
*/
|
|
273
|
+
export type ActionComponent = {
|
|
274
|
+
/**
|
|
275
|
+
* - Always 'action'.
|
|
276
|
+
*/
|
|
277
|
+
type: "action";
|
|
278
|
+
/**
|
|
279
|
+
* - Component name (e.g., 'Move', 'Beep').
|
|
280
|
+
*/
|
|
281
|
+
name: string;
|
|
282
|
+
/**
|
|
283
|
+
* - Component-specific properties.
|
|
284
|
+
*/
|
|
285
|
+
props: any;
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* Result returned by prompt components.
|
|
289
|
+
*/
|
|
290
|
+
export type PromptResult = {
|
|
291
|
+
/**
|
|
292
|
+
* - The value entered/selected by user.
|
|
293
|
+
*/
|
|
294
|
+
value: any;
|
|
295
|
+
/**
|
|
296
|
+
* - True if user cancelled the prompt.
|
|
297
|
+
*/
|
|
298
|
+
cancelled?: boolean | undefined;
|
|
299
|
+
};
|
|
300
|
+
/**
|
|
301
|
+
* Adapter interface that all platform adapters must implement.
|
|
302
|
+
*/
|
|
303
|
+
export type FlowAdapter = {
|
|
304
|
+
/**
|
|
305
|
+
* Renders a static view component.
|
|
306
|
+
*/
|
|
307
|
+
renderView: (component: ViewComponent) => void | Promise<void>;
|
|
308
|
+
/**
|
|
309
|
+
* Execute an interactive prompt and returns user input.
|
|
310
|
+
*/
|
|
311
|
+
executePrompt: (component: PromptComponent) => Promise<PromptResult>;
|
|
312
|
+
/**
|
|
313
|
+
* Handles streaming components.
|
|
314
|
+
*/
|
|
315
|
+
streamProgress: (component: StreamComponent) => AsyncIterable<any>;
|
|
316
|
+
/**
|
|
317
|
+
* Executes an action component (physical or side-effect).
|
|
318
|
+
*/
|
|
319
|
+
executeAction?: ((component: ActionComponent) => Promise<any>) | undefined;
|
|
320
|
+
};
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* @property {string} placeholder - Placeholder text.
|
|
17
17
|
* @property {InputOptions} options - Select options (if type is 'select').
|
|
18
18
|
* @property {Function} validation - Custom validation function.
|
|
19
|
+
* @property {string} mask - Mask pattern (e.g. '###-###').
|
|
19
20
|
* @property {*} defaultValue - Default value.
|
|
20
21
|
*/
|
|
21
22
|
export default class FormInput {
|
|
@@ -29,6 +30,13 @@ export default class FormInput {
|
|
|
29
30
|
SELECT: string;
|
|
30
31
|
CHECKBOX: string;
|
|
31
32
|
TEXTAREA: string;
|
|
33
|
+
PASSWORD: string;
|
|
34
|
+
SECRET: string;
|
|
35
|
+
MASK: string;
|
|
36
|
+
CONFIRM: string;
|
|
37
|
+
TOGGLE: string;
|
|
38
|
+
MULTISELECT: string;
|
|
39
|
+
AUTOCOMPLETE: string;
|
|
32
40
|
};
|
|
33
41
|
/**
|
|
34
42
|
* @param {*} input
|
|
@@ -46,6 +54,7 @@ export default class FormInput {
|
|
|
46
54
|
* @param {string} [props.placeholder=''] - Placeholder.
|
|
47
55
|
* @param {InputOptions} [props.options=[]] - Select options or async function to retrieve data with the search and page.
|
|
48
56
|
* @param {Function} [props.validation] - Custom validation.
|
|
57
|
+
* @param {string} [props.mask=''] - Mask pattern.
|
|
49
58
|
* @param {*} [props.defaultValue=null] - Default value.
|
|
50
59
|
*/
|
|
51
60
|
constructor(props: {
|
|
@@ -56,6 +65,7 @@ export default class FormInput {
|
|
|
56
65
|
placeholder?: string | undefined;
|
|
57
66
|
options?: InputOptions | undefined;
|
|
58
67
|
validation?: Function | undefined;
|
|
68
|
+
mask?: string | undefined;
|
|
59
69
|
defaultValue?: any;
|
|
60
70
|
});
|
|
61
71
|
/** @type {string} */ name: string;
|
|
@@ -65,6 +75,7 @@ export default class FormInput {
|
|
|
65
75
|
/** @type {string} */ placeholder: string;
|
|
66
76
|
/** @type {InputOptions} */ options: InputOptions;
|
|
67
77
|
/** @type {Function} */ validation: Function;
|
|
78
|
+
/** @type {string} */ mask: string;
|
|
68
79
|
/** @type {*} */ defaultValue: any;
|
|
69
80
|
requireValidType(): void;
|
|
70
81
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default Form;
|
|
2
|
-
import FormInput from
|
|
3
|
-
import FormMessage from
|
|
4
|
-
import Form from
|
|
2
|
+
import FormInput from './Input.js';
|
|
3
|
+
import FormMessage from './Message.js';
|
|
4
|
+
import Form from './Form.js';
|
|
5
5
|
export { FormInput, FormMessage, Form };
|
|
@@ -42,5 +42,5 @@ export default class InputAdapter extends Event {
|
|
|
42
42
|
value: string | null;
|
|
43
43
|
}>;
|
|
44
44
|
}
|
|
45
|
-
import Event from
|
|
46
|
-
import CancelError from
|
|
45
|
+
import Event from '@nan0web/event/oop';
|
|
46
|
+
import CancelError from './Error/CancelError.js';
|
package/types/core/Intent.d.ts
CHANGED
|
@@ -18,74 +18,71 @@
|
|
|
18
18
|
* }
|
|
19
19
|
*/
|
|
20
20
|
declare class Intent extends Message {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
* @returns {object} serializable object with intent, body, and context
|
|
76
|
-
*/
|
|
77
|
-
toObject(): object;
|
|
21
|
+
/**
|
|
22
|
+
* Create a new Intent.
|
|
23
|
+
*
|
|
24
|
+
* @param {object} input
|
|
25
|
+
* @param {typeof Message} input.target - message class this intent wants to create
|
|
26
|
+
* @param {any} [input.context] - execution context
|
|
27
|
+
* @param {object} [body] - partial or complete data for the target message
|
|
28
|
+
*/
|
|
29
|
+
constructor({ target, context, ...body }?: { target: typeof Message; context?: any })
|
|
30
|
+
/**
|
|
31
|
+
* The target Message class this Intent aims to produce.
|
|
32
|
+
* Must be a class with a static `.Body` schema.
|
|
33
|
+
*
|
|
34
|
+
* @type {typeof Message | null}
|
|
35
|
+
*/
|
|
36
|
+
target: typeof Message | null
|
|
37
|
+
/**
|
|
38
|
+
* Optional context for execution (session, locale, state, etc.).
|
|
39
|
+
*
|
|
40
|
+
* @type {any}
|
|
41
|
+
*/
|
|
42
|
+
context: any
|
|
43
|
+
/**
|
|
44
|
+
* Validates all fields in the Intent's body against the target's schema.
|
|
45
|
+
*
|
|
46
|
+
* Checks:
|
|
47
|
+
* - Required fields presence and non-emptiness
|
|
48
|
+
* - Pattern matching (RegExp)
|
|
49
|
+
* - Value within allowed options (if defined)
|
|
50
|
+
* - Custom validation logic (if `validate` function is defined)
|
|
51
|
+
*
|
|
52
|
+
* @returns {Map<string, string>} Map of field → error message, empty if valid
|
|
53
|
+
*/
|
|
54
|
+
validateIntent(): Map<string, string>
|
|
55
|
+
/**
|
|
56
|
+
* Executes the Intent by creating a valid instance of the target message.
|
|
57
|
+
*
|
|
58
|
+
* If the Intent is not ready (has validation errors), returns null.
|
|
59
|
+
*
|
|
60
|
+
* @returns {Message | null} the created message, or null if invalid
|
|
61
|
+
*/
|
|
62
|
+
execute(): Message | null
|
|
63
|
+
/**
|
|
64
|
+
* Checks if the Intent can be executed immediately, without user input.
|
|
65
|
+
*
|
|
66
|
+
* @returns {boolean} true if all required fields are valid
|
|
67
|
+
*/
|
|
68
|
+
isReady(): boolean
|
|
69
|
+
/**
|
|
70
|
+
* Converts the Intent to a plain object for logging or inspection.
|
|
71
|
+
*
|
|
72
|
+
* @returns {object} serializable object with intent, body, and context
|
|
73
|
+
*/
|
|
74
|
+
toObject(): object
|
|
78
75
|
}
|
|
79
76
|
declare namespace Intent {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Handles an Intent by fulfilling missing or invalid fields.
|
|
79
|
+
*
|
|
80
|
+
* @param {Intent} intent - the declared intent to handle
|
|
81
|
+
* @param {object} inputAdapter - must have `.ask(prompt)`
|
|
82
|
+
* @returns {Promise<Message | null>} resolved when intent is fulfilled
|
|
83
|
+
* @throws {CancelError} if user cancels
|
|
84
|
+
*/
|
|
85
|
+
function handleIntent(intent: Intent, inputAdapter: object): Promise<Message | null>
|
|
89
86
|
}
|
|
90
|
-
export default Intent
|
|
91
|
-
import { Message } from
|
|
87
|
+
export default Intent
|
|
88
|
+
import { Message } from '@nan0web/co'
|
|
@@ -3,69 +3,69 @@
|
|
|
3
3
|
* Represents a message input with value, options, and metadata.
|
|
4
4
|
*/
|
|
5
5
|
export default class InputMessage {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
6
|
+
static ESCAPE: string
|
|
7
|
+
/**
|
|
8
|
+
* Creates an InputMessage instance from the given value.
|
|
9
|
+
* @param {InputMessage|object|string} value - The value to create from
|
|
10
|
+
* @returns {InputMessage} An InputMessage instance
|
|
11
|
+
*/
|
|
12
|
+
static from(value: InputMessage | object | string): InputMessage
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new InputMessage instance.
|
|
15
|
+
* @param {object} props - Input message properties
|
|
16
|
+
* @param {InputMessageValue} [props.value=null] - Input value
|
|
17
|
+
* @param {string[]|string} [props.options=[]] - Available options
|
|
18
|
+
* @param {boolean} [props.waiting=false] - Waiting state flag
|
|
19
|
+
* @param {boolean} [props.escaped=false] - Sets value to escape when true
|
|
20
|
+
*/
|
|
21
|
+
constructor(props?: {
|
|
22
|
+
value?: InputMessageValue | undefined
|
|
23
|
+
options?: string | string[] | undefined
|
|
24
|
+
waiting?: boolean | undefined
|
|
25
|
+
escaped?: boolean | undefined
|
|
26
|
+
})
|
|
27
|
+
/** @type {Message} Input value */
|
|
28
|
+
value: Message
|
|
29
|
+
/** @type {string[]} Available options for this input */
|
|
30
|
+
options: string[]
|
|
31
|
+
/** @type {boolean} Whether this input is waiting for response */
|
|
32
|
+
waiting: boolean
|
|
33
|
+
/**
|
|
34
|
+
* Checks if the input value is empty.
|
|
35
|
+
* @returns {boolean} True if value is empty or null, false otherwise
|
|
36
|
+
*/
|
|
37
|
+
get empty(): boolean
|
|
38
|
+
/**
|
|
39
|
+
* Gets the timestamp when input was created.
|
|
40
|
+
* @returns {number} Creation timestamp
|
|
41
|
+
*/
|
|
42
|
+
get time(): number
|
|
43
|
+
/**
|
|
44
|
+
* Returns the escape value.
|
|
45
|
+
* @returns {string}
|
|
46
|
+
*/
|
|
47
|
+
get ESCAPE(): string
|
|
48
|
+
/**
|
|
49
|
+
* Checks if the input is an escape sequence.
|
|
50
|
+
* @returns {boolean} True if input value is escape sequence, false otherwise
|
|
51
|
+
*/
|
|
52
|
+
get escaped(): boolean
|
|
53
|
+
/**
|
|
54
|
+
* Validates if the input has a non-empty value.
|
|
55
|
+
* @returns {boolean} True if input is valid, false otherwise
|
|
56
|
+
*/
|
|
57
|
+
get isValid(): boolean
|
|
58
|
+
/**
|
|
59
|
+
* Converts the input to a plain object representation.
|
|
60
|
+
* @returns {object} Object with all properties including timestamp
|
|
61
|
+
*/
|
|
62
|
+
toObject(): object
|
|
63
|
+
/**
|
|
64
|
+
* Converts the input to a string representation including timestamp.
|
|
65
|
+
* @returns {string} String representation with timestamp and value
|
|
66
|
+
*/
|
|
67
|
+
toString(): string
|
|
68
|
+
#private
|
|
69
69
|
}
|
|
70
|
-
export type InputMessageValue = Partial<Message> | null
|
|
71
|
-
import { Message } from
|
|
70
|
+
export type InputMessageValue = Partial<Message> | null
|
|
71
|
+
import { Message } from '@nan0web/co'
|