@agentuity/cli 0.0.69 → 0.0.71
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/AGENTS.md +1 -1
- package/README.md +1 -1
- package/dist/cmd/ai/capabilities/show.d.ts.map +1 -1
- package/dist/cmd/ai/capabilities/show.js +0 -13
- package/dist/cmd/ai/capabilities/show.js.map +1 -1
- package/dist/cmd/ai/prompt/agent.js +1 -1
- package/dist/cmd/ai/prompt/api.js +1 -1
- package/dist/cmd/build/ast.d.ts +1 -2
- package/dist/cmd/build/ast.d.ts.map +1 -1
- package/dist/cmd/build/ast.js +261 -260
- package/dist/cmd/build/ast.js.map +1 -1
- package/dist/cmd/build/bundler.d.ts +4 -1
- package/dist/cmd/build/bundler.d.ts.map +1 -1
- package/dist/cmd/build/bundler.js +89 -6
- package/dist/cmd/build/bundler.js.map +1 -1
- package/dist/cmd/build/index.d.ts.map +1 -1
- package/dist/cmd/build/index.js +2 -1
- package/dist/cmd/build/index.js.map +1 -1
- package/dist/cmd/build/plugin.d.ts.map +1 -1
- package/dist/cmd/build/plugin.js +152 -414
- package/dist/cmd/build/plugin.js.map +1 -1
- package/dist/cmd/build/route-registry.d.ts +36 -0
- package/dist/cmd/build/route-registry.d.ts.map +1 -0
- package/dist/cmd/build/route-registry.js +151 -0
- package/dist/cmd/build/route-registry.js.map +1 -0
- package/dist/cmd/cloud/deploy.d.ts.map +1 -1
- package/dist/cmd/cloud/deploy.js +2 -0
- package/dist/cmd/cloud/deploy.js.map +1 -1
- package/dist/cmd/cloud/index.d.ts.map +1 -1
- package/dist/cmd/cloud/index.js +0 -2
- package/dist/cmd/cloud/index.js.map +1 -1
- package/dist/cmd/dev/index.d.ts.map +1 -1
- package/dist/cmd/dev/index.js +4 -3
- package/dist/cmd/dev/index.js.map +1 -1
- package/dist/cmd/dev/sync.d.ts.map +1 -1
- package/dist/cmd/dev/sync.js +0 -15
- package/dist/cmd/dev/sync.js.map +1 -1
- package/dist/cmd/dev/templates.d.ts.map +1 -1
- package/dist/cmd/dev/templates.js +11 -35
- package/dist/cmd/dev/templates.js.map +1 -1
- package/dist/cmd/profile/create.d.ts.map +1 -1
- package/dist/cmd/profile/create.js +0 -1
- package/dist/cmd/profile/create.js.map +1 -1
- package/dist/cmd/project/template-flow.d.ts.map +1 -1
- package/dist/cmd/project/template-flow.js +64 -53
- package/dist/cmd/project/template-flow.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +0 -3
- package/dist/config.js.map +1 -1
- package/dist/env-util.d.ts.map +1 -1
- package/dist/env-util.js +0 -3
- package/dist/env-util.js.map +1 -1
- package/dist/tui/box.d.ts +19 -0
- package/dist/tui/box.d.ts.map +1 -0
- package/dist/tui/box.js +160 -0
- package/dist/tui/box.js.map +1 -0
- package/dist/tui/colors.d.ts +20 -0
- package/dist/tui/colors.d.ts.map +1 -0
- package/dist/tui/colors.js +52 -0
- package/dist/tui/colors.js.map +1 -0
- package/dist/tui/group.d.ts +25 -0
- package/dist/tui/group.d.ts.map +1 -0
- package/dist/tui/group.js +32 -0
- package/dist/tui/group.js.map +1 -0
- package/dist/tui/prompt.d.ts +65 -0
- package/dist/tui/prompt.d.ts.map +1 -0
- package/dist/tui/prompt.js +377 -0
- package/dist/tui/prompt.js.map +1 -0
- package/dist/tui/symbols.d.ts +32 -0
- package/dist/tui/symbols.d.ts.map +1 -0
- package/dist/tui/symbols.js +52 -0
- package/dist/tui/symbols.js.map +1 -0
- package/dist/tui.d.ts +6 -0
- package/dist/tui.d.ts.map +1 -1
- package/dist/tui.js +6 -0
- package/dist/tui.js.map +1 -1
- package/dist/types.d.ts +0 -24
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -1
- package/dist/types.js.map +1 -1
- package/package.json +3 -3
- package/src/cmd/ai/capabilities/show.ts +0 -13
- package/src/cmd/ai/prompt/agent.ts +1 -1
- package/src/cmd/ai/prompt/api.ts +1 -1
- package/src/cmd/build/ast.ts +364 -334
- package/src/cmd/build/bundler.ts +123 -9
- package/src/cmd/build/index.ts +2 -1
- package/src/cmd/build/plugin.ts +171 -493
- package/src/cmd/build/route-registry.ts +198 -0
- package/src/cmd/cloud/deploy.ts +2 -0
- package/src/cmd/cloud/index.ts +0 -2
- package/src/cmd/dev/index.ts +4 -3
- package/src/cmd/dev/sync.ts +0 -28
- package/src/cmd/dev/templates.ts +11 -35
- package/src/cmd/profile/create.ts +0 -1
- package/src/cmd/project/template-flow.ts +77 -57
- package/src/config.ts +0 -3
- package/src/env-util.ts +0 -3
- package/src/tui/box.ts +202 -0
- package/src/tui/colors.ts +55 -0
- package/src/tui/group.ts +56 -0
- package/src/tui/prompt.ts +506 -0
- package/src/tui/symbols.ts +64 -0
- package/src/tui.ts +14 -0
- package/src/types.ts +0 -1
- package/dist/cmd/cloud/objectstore/delete-bucket.d.ts +0 -3
- package/dist/cmd/cloud/objectstore/delete-bucket.d.ts.map +0 -1
- package/dist/cmd/cloud/objectstore/delete-bucket.js +0 -72
- package/dist/cmd/cloud/objectstore/delete-bucket.js.map +0 -1
- package/dist/cmd/cloud/objectstore/delete.d.ts +0 -3
- package/dist/cmd/cloud/objectstore/delete.d.ts.map +0 -1
- package/dist/cmd/cloud/objectstore/delete.js +0 -65
- package/dist/cmd/cloud/objectstore/delete.js.map +0 -1
- package/dist/cmd/cloud/objectstore/get.d.ts +0 -3
- package/dist/cmd/cloud/objectstore/get.d.ts.map +0 -1
- package/dist/cmd/cloud/objectstore/get.js +0 -75
- package/dist/cmd/cloud/objectstore/get.js.map +0 -1
- package/dist/cmd/cloud/objectstore/index.d.ts +0 -3
- package/dist/cmd/cloud/objectstore/index.d.ts.map +0 -1
- package/dist/cmd/cloud/objectstore/index.js +0 -36
- package/dist/cmd/cloud/objectstore/index.js.map +0 -1
- package/dist/cmd/cloud/objectstore/list-buckets.d.ts +0 -3
- package/dist/cmd/cloud/objectstore/list-buckets.d.ts.map +0 -1
- package/dist/cmd/cloud/objectstore/list-buckets.js +0 -46
- package/dist/cmd/cloud/objectstore/list-buckets.js.map +0 -1
- package/dist/cmd/cloud/objectstore/list-keys.d.ts +0 -3
- package/dist/cmd/cloud/objectstore/list-keys.d.ts.map +0 -1
- package/dist/cmd/cloud/objectstore/list-keys.js +0 -58
- package/dist/cmd/cloud/objectstore/list-keys.js.map +0 -1
- package/dist/cmd/cloud/objectstore/put.d.ts +0 -3
- package/dist/cmd/cloud/objectstore/put.d.ts.map +0 -1
- package/dist/cmd/cloud/objectstore/put.js +0 -66
- package/dist/cmd/cloud/objectstore/put.js.map +0 -1
- package/dist/cmd/cloud/objectstore/repl.d.ts +0 -3
- package/dist/cmd/cloud/objectstore/repl.d.ts.map +0 -1
- package/dist/cmd/cloud/objectstore/repl.js +0 -224
- package/dist/cmd/cloud/objectstore/repl.js.map +0 -1
- package/dist/cmd/cloud/objectstore/url.d.ts +0 -3
- package/dist/cmd/cloud/objectstore/url.d.ts.map +0 -1
- package/dist/cmd/cloud/objectstore/url.js +0 -64
- package/dist/cmd/cloud/objectstore/url.js.map +0 -1
- package/dist/cmd/cloud/objectstore/util.d.ts +0 -11
- package/dist/cmd/cloud/objectstore/util.d.ts.map +0 -1
- package/dist/cmd/cloud/objectstore/util.js +0 -18
- package/dist/cmd/cloud/objectstore/util.js.map +0 -1
- package/src/cmd/build/ast.test.ts +0 -418
- package/src/cmd/build/fix-duplicate-exports.test.ts +0 -387
- package/src/cmd/cloud/objectstore/delete-bucket.ts +0 -77
- package/src/cmd/cloud/objectstore/delete.ts +0 -67
- package/src/cmd/cloud/objectstore/get.ts +0 -77
- package/src/cmd/cloud/objectstore/index.ts +0 -36
- package/src/cmd/cloud/objectstore/list-buckets.ts +0 -51
- package/src/cmd/cloud/objectstore/list-keys.ts +0 -63
- package/src/cmd/cloud/objectstore/put.ts +0 -74
- package/src/cmd/cloud/objectstore/repl.ts +0 -239
- package/src/cmd/cloud/objectstore/url.ts +0 -67
- package/src/cmd/cloud/objectstore/util.ts +0 -29
- package/src/crypto/box.test.ts +0 -431
- package/src/env-util.test.ts +0 -194
package/src/tui/box.ts
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Box and note rendering utilities for TUI
|
|
3
|
+
*/
|
|
4
|
+
import { symbols } from './symbols';
|
|
5
|
+
import { colors } from './colors';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Get terminal width
|
|
9
|
+
*/
|
|
10
|
+
function getTerminalWidth(): number {
|
|
11
|
+
return process.stdout.columns || 80;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Get string width (accounting for ANSI codes)
|
|
16
|
+
*/
|
|
17
|
+
function stringWidth(str: string): number {
|
|
18
|
+
// Remove ANSI escape codes
|
|
19
|
+
// eslint-disable-next-line no-control-regex
|
|
20
|
+
const cleaned = str.replace(/\x1b\[[0-9;]*m/g, '');
|
|
21
|
+
return cleaned.length;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Wrap text to fit within width
|
|
26
|
+
*/
|
|
27
|
+
function wrapText(text: string, width: number): string[] {
|
|
28
|
+
const words = text.split(' ');
|
|
29
|
+
const lines: string[] = [];
|
|
30
|
+
let currentLine = '';
|
|
31
|
+
|
|
32
|
+
for (const word of words) {
|
|
33
|
+
// Handle words longer than width
|
|
34
|
+
if (stringWidth(word) > width) {
|
|
35
|
+
if (currentLine) lines.push(currentLine);
|
|
36
|
+
// Truncate long words with ellipsis if width allows, otherwise just slice
|
|
37
|
+
if (width >= 4) {
|
|
38
|
+
lines.push(word.slice(0, width - 3) + '...');
|
|
39
|
+
} else {
|
|
40
|
+
lines.push(word.slice(0, Math.max(0, width)));
|
|
41
|
+
}
|
|
42
|
+
currentLine = '';
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const testLine = currentLine ? `${currentLine} ${word}` : word;
|
|
47
|
+
if (stringWidth(testLine) <= width) {
|
|
48
|
+
currentLine = testLine;
|
|
49
|
+
} else {
|
|
50
|
+
if (currentLine) lines.push(currentLine);
|
|
51
|
+
currentLine = word;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (currentLine) lines.push(currentLine);
|
|
55
|
+
|
|
56
|
+
return lines;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface BoxOptions {
|
|
60
|
+
title?: string;
|
|
61
|
+
content: string;
|
|
62
|
+
titleAlign?: 'left' | 'center' | 'right';
|
|
63
|
+
contentAlign?: 'left' | 'center' | 'right';
|
|
64
|
+
width?: number;
|
|
65
|
+
padding?: number;
|
|
66
|
+
withGuide?: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Draw a boxed message (like clack's note)
|
|
71
|
+
*/
|
|
72
|
+
export function drawBox(options: BoxOptions): string {
|
|
73
|
+
const {
|
|
74
|
+
title = '',
|
|
75
|
+
content,
|
|
76
|
+
titleAlign = 'left',
|
|
77
|
+
contentAlign = 'left',
|
|
78
|
+
withGuide = true,
|
|
79
|
+
} = options;
|
|
80
|
+
|
|
81
|
+
const termWidth = getTerminalWidth();
|
|
82
|
+
|
|
83
|
+
// Calculate box width (no guide prefix inside the box)
|
|
84
|
+
const maxWidth = termWidth - 3; // Account for guide prefix space
|
|
85
|
+
const boxWidth = options.width || Math.min(60, maxWidth);
|
|
86
|
+
// Ensure we never end up with negative inner/content widths
|
|
87
|
+
const innerWidth = Math.max(boxWidth - 2, 1); // Subtract left/right borders safely
|
|
88
|
+
|
|
89
|
+
// Clamp padding to non-negative
|
|
90
|
+
const padding = Math.max(0, options.padding ?? 2);
|
|
91
|
+
|
|
92
|
+
// Prepare title line
|
|
93
|
+
// Title format: ◇ [title] ───────╮
|
|
94
|
+
// The title line should match the width of content lines: │[innerWidth]│
|
|
95
|
+
let titleLine = '';
|
|
96
|
+
|
|
97
|
+
if (title) {
|
|
98
|
+
const symbol = `${colors.success(symbols.completed)}`;
|
|
99
|
+
const titleText = colors.reset(title);
|
|
100
|
+
const titleTextWidth = stringWidth(symbols.completed) + stringWidth(title);
|
|
101
|
+
const barsNeeded = Math.max(innerWidth - titleTextWidth - 3, 1); // -3 for symbol, 2 spaces, and 1 space before bars
|
|
102
|
+
|
|
103
|
+
// Apply title alignment
|
|
104
|
+
if (titleAlign === 'center') {
|
|
105
|
+
const leftBars = Math.floor(barsNeeded / 2);
|
|
106
|
+
const rightBars = barsNeeded - leftBars;
|
|
107
|
+
titleLine = `${colors.secondary(symbols.barH.repeat(leftBars))} ${symbol} ${titleText} ${colors.secondary(symbols.barH.repeat(rightBars) + symbols.cornerTR)}`;
|
|
108
|
+
} else if (titleAlign === 'right') {
|
|
109
|
+
titleLine = `${colors.secondary(symbols.barH.repeat(barsNeeded))} ${symbol} ${titleText} ${colors.secondary(symbols.cornerTR)}`;
|
|
110
|
+
} else {
|
|
111
|
+
// left (default)
|
|
112
|
+
titleLine = `${symbol} ${titleText} ${colors.secondary(symbols.barH.repeat(barsNeeded) + symbols.cornerTR)}`;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Prepare content lines
|
|
117
|
+
const contentLines = content.split('\n');
|
|
118
|
+
const wrappedLines: string[] = [];
|
|
119
|
+
|
|
120
|
+
// Ensure content width is non-negative
|
|
121
|
+
const wrapWidth = Math.max(innerWidth - padding * 2, 0);
|
|
122
|
+
|
|
123
|
+
for (const line of contentLines) {
|
|
124
|
+
if (stringWidth(line) > wrapWidth) {
|
|
125
|
+
wrappedLines.push(...wrapText(line, wrapWidth));
|
|
126
|
+
} else {
|
|
127
|
+
wrappedLines.push(line);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Build box (without guide prefix on each line)
|
|
132
|
+
const boxLines: string[] = [];
|
|
133
|
+
|
|
134
|
+
// Title line
|
|
135
|
+
if (title) {
|
|
136
|
+
boxLines.push(titleLine);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Content lines with borders
|
|
140
|
+
// The title line is innerWidth + 1 wide, so content should be innerWidth - 1 between bars
|
|
141
|
+
const contentWidth = Math.max(innerWidth - 1, 0);
|
|
142
|
+
const emptyLine = `${colors.secondary(symbols.bar)}${' '.repeat(contentWidth)}${colors.secondary(symbols.bar)}`;
|
|
143
|
+
boxLines.push(emptyLine);
|
|
144
|
+
|
|
145
|
+
for (const line of wrappedLines) {
|
|
146
|
+
const lineLen = stringWidth(line);
|
|
147
|
+
let leftPad =
|
|
148
|
+
contentAlign === 'right'
|
|
149
|
+
? contentWidth - lineLen - padding
|
|
150
|
+
: contentAlign === 'center'
|
|
151
|
+
? Math.floor((contentWidth - lineLen) / 2)
|
|
152
|
+
: padding;
|
|
153
|
+
|
|
154
|
+
// Clamp to non-negative
|
|
155
|
+
leftPad = Math.max(leftPad, 0);
|
|
156
|
+
const rightPad = Math.max(contentWidth - lineLen - leftPad, 0);
|
|
157
|
+
|
|
158
|
+
boxLines.push(
|
|
159
|
+
`${colors.secondary(symbols.bar)}${' '.repeat(leftPad)}${line}${' '.repeat(rightPad)}${colors.secondary(symbols.bar)}`
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
boxLines.push(emptyLine);
|
|
164
|
+
|
|
165
|
+
// Now add guide bar before/after if needed
|
|
166
|
+
const lines: string[] = [];
|
|
167
|
+
|
|
168
|
+
if (withGuide) {
|
|
169
|
+
lines.push(colors.secondary(symbols.bar));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Add all box lines (no prefix - flush left)
|
|
173
|
+
lines.push(...boxLines);
|
|
174
|
+
|
|
175
|
+
// Bottom border - should match content line width (│ + contentWidth + │)
|
|
176
|
+
// contentWidth = innerWidth - 1, so total is innerWidth + 1
|
|
177
|
+
// Bottom border: ├ + (innerWidth - 1) bars + ╯ = innerWidth + 1
|
|
178
|
+
if (withGuide) {
|
|
179
|
+
lines.push(
|
|
180
|
+
colors.secondary(symbols.connect + symbols.barH.repeat(innerWidth - 1) + symbols.cornerBR)
|
|
181
|
+
);
|
|
182
|
+
} else {
|
|
183
|
+
lines.push(
|
|
184
|
+
colors.secondary(symbols.cornerBL + symbols.barH.repeat(innerWidth - 1) + symbols.cornerBR)
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return lines.join('\n');
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Render a note box (matches clack style)
|
|
193
|
+
*/
|
|
194
|
+
export function note(message: string, title = ''): void {
|
|
195
|
+
const output = drawBox({
|
|
196
|
+
title,
|
|
197
|
+
content: message,
|
|
198
|
+
contentAlign: 'left',
|
|
199
|
+
withGuide: true,
|
|
200
|
+
});
|
|
201
|
+
console.log(output);
|
|
202
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Color utilities for TUI components using existing tui.ts color system
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// ANSI escape codes for additional colors not in main tui.ts
|
|
6
|
+
const RESET = '\x1b[0m';
|
|
7
|
+
const CYAN = '\x1b[36m';
|
|
8
|
+
const GRAY = '\x1b[90m';
|
|
9
|
+
const RED = '\x1b[31m';
|
|
10
|
+
const YELLOW = '\x1b[33m';
|
|
11
|
+
const GREEN = '\x1b[32m';
|
|
12
|
+
const BLUE = '\x1b[34m';
|
|
13
|
+
const DIM = '\x1b[2m';
|
|
14
|
+
const BOLD = '\x1b[1m';
|
|
15
|
+
const UNDERLINE = '\x1b[4m';
|
|
16
|
+
const BG_CYAN = '\x1b[46m';
|
|
17
|
+
const BLACK = '\x1b[30m';
|
|
18
|
+
const WHITE = '\x1b[37m';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Detect if terminal is in dark mode
|
|
22
|
+
*/
|
|
23
|
+
function isDarkMode(): boolean {
|
|
24
|
+
const scheme = process.env.COLOR_SCHEME;
|
|
25
|
+
if (scheme === 'light') return false;
|
|
26
|
+
if (scheme === 'dark') return true;
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const colors = {
|
|
31
|
+
// State colors - using simple ANSI codes (consistent with tui.ts approach)
|
|
32
|
+
active: (text: string) => `${CYAN}${text}${RESET}`,
|
|
33
|
+
completed: (text: string) => `${GRAY}${text}${RESET}`,
|
|
34
|
+
error: (text: string) => `${RED}${text}${RESET}`,
|
|
35
|
+
warning: (text: string) => `${YELLOW}${text}${RESET}`,
|
|
36
|
+
success: (text: string) => `${GREEN}${text}${RESET}`,
|
|
37
|
+
info: (text: string) => `${BLUE}${text}${RESET}`,
|
|
38
|
+
|
|
39
|
+
// Text formatting
|
|
40
|
+
muted: (text: string) => `${DIM}${text}${RESET}`,
|
|
41
|
+
bold: (text: string) => `${BOLD}${text}${RESET}`,
|
|
42
|
+
underline: (text: string) => `${UNDERLINE}${text}${RESET}`,
|
|
43
|
+
reset: (text: string) => `${RESET}${text}`,
|
|
44
|
+
|
|
45
|
+
// Semantic colors
|
|
46
|
+
primary: (text: string) => `${CYAN}${text}${RESET}`,
|
|
47
|
+
secondary: (text: string) => `${GRAY}${text}${RESET}`,
|
|
48
|
+
link: (text: string) => `${CYAN}${UNDERLINE}${text}${RESET}`,
|
|
49
|
+
|
|
50
|
+
// Inversed colors (adapt to light/dark mode)
|
|
51
|
+
inverseCyan: (text: string) => {
|
|
52
|
+
const dark = isDarkMode();
|
|
53
|
+
return dark ? `${BG_CYAN}${BLACK}${text}${RESET}` : `${BG_CYAN}${WHITE}${text}${RESET}`;
|
|
54
|
+
},
|
|
55
|
+
};
|
package/src/tui/group.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Grouped prompts orchestration
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
type Prettify<T> = {
|
|
6
|
+
[P in keyof T]: T[P];
|
|
7
|
+
} & {};
|
|
8
|
+
|
|
9
|
+
export type PromptGroupAwaitedReturn<T> = {
|
|
10
|
+
[P in keyof T]: Exclude<Awaited<T[P]>, symbol>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type PromptGroup<T> = {
|
|
14
|
+
[P in keyof T]: (opts: {
|
|
15
|
+
results: Prettify<Partial<PromptGroupAwaitedReturn<Omit<T, P>>>>;
|
|
16
|
+
}) => undefined | Promise<T[P] | undefined>;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export interface PromptGroupOptions<T> {
|
|
20
|
+
onCancel?: (opts: { results: Prettify<Partial<PromptGroupAwaitedReturn<T>>> }) => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Execute a group of prompts sequentially
|
|
25
|
+
*/
|
|
26
|
+
export async function group<T>(
|
|
27
|
+
prompts: PromptGroup<T>,
|
|
28
|
+
opts?: PromptGroupOptions<T>
|
|
29
|
+
): Promise<Prettify<PromptGroupAwaitedReturn<T>>> {
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
|
+
const results: any = {};
|
|
32
|
+
const promptNames = Object.keys(prompts);
|
|
33
|
+
|
|
34
|
+
for (const name of promptNames) {
|
|
35
|
+
const prompt = prompts[name as keyof T];
|
|
36
|
+
try {
|
|
37
|
+
const result = await prompt({ results });
|
|
38
|
+
|
|
39
|
+
// Skip if undefined (conditional prompt)
|
|
40
|
+
if (result === undefined) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
results[name] = result;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
// Handle cancellation
|
|
47
|
+
if (opts?.onCancel) {
|
|
48
|
+
results[name] = 'canceled';
|
|
49
|
+
opts.onCancel({ results });
|
|
50
|
+
}
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return results as Prettify<PromptGroupAwaitedReturn<T>>;
|
|
56
|
+
}
|