@portel/photon-core 1.4.0 → 2.1.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 +123 -0
- package/dist/auto-ui.d.ts +103 -0
- package/dist/auto-ui.d.ts.map +1 -0
- package/dist/auto-ui.js +275 -0
- package/dist/auto-ui.js.map +1 -0
- package/dist/base.d.ts +9 -2
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +23 -10
- package/dist/base.js.map +1 -1
- package/dist/cli-ui-renderer.d.ts +31 -0
- package/dist/cli-ui-renderer.d.ts.map +1 -0
- package/dist/cli-ui-renderer.js +224 -0
- package/dist/cli-ui-renderer.js.map +1 -0
- package/dist/dependency-manager.d.ts.map +1 -1
- package/dist/dependency-manager.js +0 -1
- package/dist/dependency-manager.js.map +1 -1
- package/dist/design-system/index.d.ts +21 -0
- package/dist/design-system/index.d.ts.map +1 -0
- package/dist/design-system/index.js +27 -0
- package/dist/design-system/index.js.map +1 -0
- package/dist/design-system/tokens.d.ts +149 -0
- package/dist/design-system/tokens.d.ts.map +1 -0
- package/dist/design-system/tokens.js +413 -0
- package/dist/design-system/tokens.js.map +1 -0
- package/dist/design-system/transaction-ui.d.ts +70 -0
- package/dist/design-system/transaction-ui.d.ts.map +1 -0
- package/dist/design-system/transaction-ui.js +982 -0
- package/dist/design-system/transaction-ui.js.map +1 -0
- package/dist/generator.d.ts +58 -8
- package/dist/generator.d.ts.map +1 -1
- package/dist/generator.js +9 -4
- package/dist/generator.js.map +1 -1
- package/dist/index.d.ts +10 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +48 -44
- package/dist/index.js.map +1 -1
- package/dist/io.d.ts +395 -0
- package/dist/io.d.ts.map +1 -0
- package/dist/io.js +304 -0
- package/dist/io.js.map +1 -0
- package/dist/path-resolver.d.ts.map +1 -1
- package/dist/path-resolver.js +2 -1
- package/dist/path-resolver.js.map +1 -1
- package/dist/rendering/components.d.ts +29 -0
- package/dist/rendering/components.d.ts.map +1 -0
- package/dist/rendering/components.js +773 -0
- package/dist/rendering/components.js.map +1 -0
- package/dist/rendering/field-analyzer.d.ts +48 -0
- package/dist/rendering/field-analyzer.d.ts.map +1 -0
- package/dist/rendering/field-analyzer.js +270 -0
- package/dist/rendering/field-analyzer.js.map +1 -0
- package/dist/rendering/field-renderers.d.ts +64 -0
- package/dist/rendering/field-renderers.d.ts.map +1 -0
- package/dist/rendering/field-renderers.js +317 -0
- package/dist/rendering/field-renderers.js.map +1 -0
- package/dist/rendering/index.d.ts +28 -0
- package/dist/rendering/index.d.ts.map +1 -0
- package/dist/rendering/index.js +60 -0
- package/dist/rendering/index.js.map +1 -0
- package/dist/rendering/layout-selector.d.ts +48 -0
- package/dist/rendering/layout-selector.d.ts.map +1 -0
- package/dist/rendering/layout-selector.js +347 -0
- package/dist/rendering/layout-selector.js.map +1 -0
- package/dist/rendering/template-engine.d.ts +41 -0
- package/dist/rendering/template-engine.d.ts.map +1 -0
- package/dist/rendering/template-engine.js +236 -0
- package/dist/rendering/template-engine.js.map +1 -0
- package/dist/schema-extractor.d.ts +30 -0
- package/dist/schema-extractor.d.ts.map +1 -1
- package/dist/schema-extractor.js +205 -12
- package/dist/schema-extractor.js.map +1 -1
- package/dist/stateful.d.ts +63 -0
- package/dist/stateful.d.ts.map +1 -1
- package/dist/stateful.js +222 -0
- package/dist/stateful.js.map +1 -1
- package/dist/types.d.ts +9 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/ucp/ap2/handlers.d.ts +242 -0
- package/dist/ucp/ap2/handlers.d.ts.map +1 -0
- package/dist/ucp/ap2/handlers.js +482 -0
- package/dist/ucp/ap2/handlers.js.map +1 -0
- package/dist/ucp/ap2/mandates.d.ts +95 -0
- package/dist/ucp/ap2/mandates.d.ts.map +1 -0
- package/dist/ucp/ap2/mandates.js +234 -0
- package/dist/ucp/ap2/mandates.js.map +1 -0
- package/dist/ucp/ap2/types.d.ts +305 -0
- package/dist/ucp/ap2/types.d.ts.map +1 -0
- package/dist/ucp/ap2/types.js +8 -0
- package/dist/ucp/ap2/types.js.map +1 -0
- package/dist/ucp/capabilities/checkout.d.ts +118 -0
- package/dist/ucp/capabilities/checkout.d.ts.map +1 -0
- package/dist/ucp/capabilities/checkout.js +344 -0
- package/dist/ucp/capabilities/checkout.js.map +1 -0
- package/dist/ucp/capabilities/identity.d.ts +130 -0
- package/dist/ucp/capabilities/identity.d.ts.map +1 -0
- package/dist/ucp/capabilities/identity.js +290 -0
- package/dist/ucp/capabilities/identity.js.map +1 -0
- package/dist/ucp/capabilities/order.d.ts +142 -0
- package/dist/ucp/capabilities/order.d.ts.map +1 -0
- package/dist/ucp/capabilities/order.js +383 -0
- package/dist/ucp/capabilities/order.js.map +1 -0
- package/dist/ucp/index.d.ts +18 -0
- package/dist/ucp/index.d.ts.map +1 -0
- package/dist/ucp/index.js +19 -0
- package/dist/ucp/index.js.map +1 -0
- package/dist/ucp/manifest.d.ts +62 -0
- package/dist/ucp/manifest.d.ts.map +1 -0
- package/dist/ucp/manifest.js +180 -0
- package/dist/ucp/manifest.js.map +1 -0
- package/dist/ucp/types.d.ts +327 -0
- package/dist/ucp/types.d.ts.map +1 -0
- package/dist/ucp/types.js +8 -0
- package/dist/ucp/types.js.map +1 -0
- package/package.json +3 -4
- package/src/auto-ui.ts +413 -0
- package/src/base.ts +22 -9
- package/src/cli-ui-renderer.ts +264 -0
- package/src/dependency-manager.ts +0 -1
- package/src/design-system/index.ts +30 -0
- package/src/design-system/tokens.ts +451 -0
- package/src/design-system/transaction-ui.ts +1038 -0
- package/src/generator.ts +68 -8
- package/src/index.ts +159 -101
- package/src/io.ts +493 -0
- package/src/path-resolver.ts +2 -1
- package/src/rendering/components.ts +785 -0
- package/src/rendering/field-analyzer.ts +299 -0
- package/src/rendering/field-renderers.ts +356 -0
- package/src/rendering/index.ts +63 -0
- package/src/rendering/layout-selector.ts +390 -0
- package/src/rendering/template-engine.ts +254 -0
- package/src/schema-extractor.ts +225 -12
- package/src/stateful.ts +301 -0
- package/src/types.ts +10 -1
- package/src/ucp/ap2/handlers.ts +779 -0
- package/src/ucp/ap2/mandates.ts +354 -0
- package/src/ucp/ap2/types.ts +441 -0
- package/src/ucp/capabilities/checkout.ts +497 -0
- package/src/ucp/capabilities/identity.ts +425 -0
- package/src/ucp/capabilities/order.ts +549 -0
- package/src/ucp/index.ts +27 -0
- package/src/ucp/manifest.ts +257 -0
- package/src/ucp/types.ts +454 -0
- package/dist/cli-formatter.d.ts +0 -92
- package/dist/cli-formatter.d.ts.map +0 -1
- package/dist/cli-formatter.js +0 -486
- package/dist/cli-formatter.js.map +0 -1
- package/dist/elicit.d.ts +0 -93
- package/dist/elicit.d.ts.map +0 -1
- package/dist/elicit.js +0 -373
- package/dist/elicit.js.map +0 -1
- package/dist/mcp-client.d.ts +0 -218
- package/dist/mcp-client.d.ts.map +0 -1
- package/dist/mcp-client.js +0 -424
- package/dist/mcp-client.js.map +0 -1
- package/dist/mcp-sdk-transport.d.ts +0 -88
- package/dist/mcp-sdk-transport.d.ts.map +0 -1
- package/dist/mcp-sdk-transport.js +0 -360
- package/dist/mcp-sdk-transport.js.map +0 -1
- package/dist/photon-config.d.ts +0 -86
- package/dist/photon-config.d.ts.map +0 -1
- package/dist/photon-config.js +0 -156
- package/dist/photon-config.js.map +0 -1
- package/src/cli-formatter.ts +0 -579
- package/src/elicit.ts +0 -438
- package/src/mcp-client.ts +0 -561
- package/src/mcp-sdk-transport.ts +0 -449
- package/src/photon-config.ts +0 -201
package/dist/io.d.ts
ADDED
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IO Helper API
|
|
3
|
+
*
|
|
4
|
+
* Clean, ergonomic API for yielding emit and ask messages in Photon generators.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { io } from '@portel/photon-core';
|
|
9
|
+
*
|
|
10
|
+
* async *myTool() {
|
|
11
|
+
* yield io.emit.status('Starting...');
|
|
12
|
+
* yield io.emit.progress(0.5, 'Halfway there');
|
|
13
|
+
*
|
|
14
|
+
* const name = yield io.ask.text('What is your name?');
|
|
15
|
+
* const confirmed = yield io.ask.confirm('Continue?');
|
|
16
|
+
*
|
|
17
|
+
* return { name, confirmed };
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @module io
|
|
22
|
+
*/
|
|
23
|
+
import type { EmitStatus, EmitProgress, EmitStream, EmitLog, EmitToast, EmitThinking, EmitArtifact, EmitUI, AskText, AskPassword, AskConfirm, AskSelect, AskNumber, AskFile, AskDate, AskForm, AskUrl, FormSchema } from './generator.js';
|
|
24
|
+
/**
|
|
25
|
+
* Emit a status message
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* yield io.emit.status('Connecting...');
|
|
29
|
+
* yield io.emit.status('Done!', 'success');
|
|
30
|
+
*/
|
|
31
|
+
declare function status(message: string, type?: EmitStatus['type']): EmitStatus;
|
|
32
|
+
/**
|
|
33
|
+
* Emit a progress update
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* yield io.emit.progress(0.5); // 50%
|
|
37
|
+
* yield io.emit.progress(0.75, 'Almost done');
|
|
38
|
+
*/
|
|
39
|
+
declare function progress(value: number, message?: string, meta?: Record<string, any>): EmitProgress;
|
|
40
|
+
/**
|
|
41
|
+
* Emit a stream chunk
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* for await (const chunk of stream) {
|
|
45
|
+
* yield io.emit.stream(chunk);
|
|
46
|
+
* }
|
|
47
|
+
* yield io.emit.stream('', true); // final
|
|
48
|
+
*/
|
|
49
|
+
declare function stream(data: any, final?: boolean, contentType?: string): EmitStream;
|
|
50
|
+
/**
|
|
51
|
+
* Emit a log message (for debugging)
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* yield io.emit.log('Processing item', 'debug', { id: 123 });
|
|
55
|
+
*/
|
|
56
|
+
declare function log(message: string, level?: EmitLog['level'], data?: Record<string, any>): EmitLog;
|
|
57
|
+
/**
|
|
58
|
+
* Emit a toast notification
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* yield io.emit.toast('Saved!', 'success');
|
|
62
|
+
* yield io.emit.toast('Error!', 'error', 5000);
|
|
63
|
+
*/
|
|
64
|
+
declare function toast(message: string, type?: EmitToast['type'], duration?: number): EmitToast;
|
|
65
|
+
/**
|
|
66
|
+
* Emit thinking indicator
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* yield io.emit.thinking(true);
|
|
70
|
+
* // ... heavy computation
|
|
71
|
+
* yield io.emit.thinking(false);
|
|
72
|
+
*/
|
|
73
|
+
declare function thinking(active: boolean): EmitThinking;
|
|
74
|
+
/**
|
|
75
|
+
* Emit an artifact (image, code, document)
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* yield io.emit.artifact('image', { url: 'https://...', title: 'Chart' });
|
|
79
|
+
* yield io.emit.artifact('code', { content: 'const x = 1;', language: 'typescript' });
|
|
80
|
+
*/
|
|
81
|
+
declare function artifact(type: EmitArtifact['type'], options: Omit<EmitArtifact, 'emit' | 'type'>): EmitArtifact;
|
|
82
|
+
/**
|
|
83
|
+
* Emit a UI component
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* yield io.emit.ui('preferences', { currentTheme: 'dark' });
|
|
87
|
+
* yield io.emit.ui(null, { inline: '<div>Hello</div>' });
|
|
88
|
+
*/
|
|
89
|
+
declare function ui(id: string | null, options?: Omit<EmitUI, 'emit' | 'id'>): EmitUI;
|
|
90
|
+
/** Options for text input */
|
|
91
|
+
interface TextOptions {
|
|
92
|
+
id?: string;
|
|
93
|
+
default?: string;
|
|
94
|
+
placeholder?: string;
|
|
95
|
+
pattern?: string;
|
|
96
|
+
minLength?: number;
|
|
97
|
+
maxLength?: number;
|
|
98
|
+
required?: boolean;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Ask for text input
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* const name = yield io.ask.text('What is your name?');
|
|
105
|
+
* const email = yield io.ask.text('Email:', { pattern: '.*@.*' });
|
|
106
|
+
*/
|
|
107
|
+
declare function text(message: string, options?: TextOptions): AskText;
|
|
108
|
+
/**
|
|
109
|
+
* Ask for password input (masked)
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* const apiKey = yield io.ask.password('Enter API key:');
|
|
113
|
+
*/
|
|
114
|
+
declare function password(message: string, options?: Pick<TextOptions, 'id' | 'required'>): AskPassword;
|
|
115
|
+
/** Options for confirm input */
|
|
116
|
+
interface ConfirmOptions {
|
|
117
|
+
id?: string;
|
|
118
|
+
default?: boolean;
|
|
119
|
+
dangerous?: boolean;
|
|
120
|
+
required?: boolean;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Ask for confirmation (yes/no)
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* const ok = yield io.ask.confirm('Delete this file?');
|
|
127
|
+
* const dangerous = yield io.ask.confirm('Proceed?', { dangerous: true });
|
|
128
|
+
*/
|
|
129
|
+
declare function confirm(message: string, options?: ConfirmOptions): AskConfirm;
|
|
130
|
+
/** Options for select input */
|
|
131
|
+
interface SelectOptions {
|
|
132
|
+
id?: string;
|
|
133
|
+
default?: string | string[];
|
|
134
|
+
multi?: boolean;
|
|
135
|
+
required?: boolean;
|
|
136
|
+
/** Layout style for rendering options */
|
|
137
|
+
layout?: 'list' | 'grid' | 'cards';
|
|
138
|
+
/** Number of columns for grid/cards layout */
|
|
139
|
+
columns?: number;
|
|
140
|
+
/** Filter buttons to show (e.g., ['All', 'Vegetarian', 'Vegan']) */
|
|
141
|
+
filters?: string[];
|
|
142
|
+
/** Which option field to filter on (default: 'category') */
|
|
143
|
+
filterField?: string;
|
|
144
|
+
/** Show search box for filtering options */
|
|
145
|
+
searchable?: boolean;
|
|
146
|
+
/** Placeholder text for search box */
|
|
147
|
+
searchPlaceholder?: string;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Rich select option for e-commerce, catalogs, and other common use cases.
|
|
151
|
+
*
|
|
152
|
+
* Supports simple strings for basic options, or rich objects for
|
|
153
|
+
* product cards, catalog items, and other visual selections.
|
|
154
|
+
*
|
|
155
|
+
* @example Simple string options
|
|
156
|
+
* ['Red', 'Green', 'Blue']
|
|
157
|
+
*
|
|
158
|
+
* @example Rich product options
|
|
159
|
+
* [
|
|
160
|
+
* {
|
|
161
|
+
* value: 'prod-123',
|
|
162
|
+
* label: 'Wireless Headphones',
|
|
163
|
+
* description: 'Premium sound quality',
|
|
164
|
+
* image: 'https://example.com/headphones.jpg',
|
|
165
|
+
* price: 99.99,
|
|
166
|
+
* badge: 'Sale',
|
|
167
|
+
* }
|
|
168
|
+
* ]
|
|
169
|
+
*/
|
|
170
|
+
type SelectOption = string | {
|
|
171
|
+
/** Unique identifier returned when selected */
|
|
172
|
+
value: string;
|
|
173
|
+
/** Display label (product name, item title) */
|
|
174
|
+
label: string;
|
|
175
|
+
/** Secondary text (short description) */
|
|
176
|
+
description?: string;
|
|
177
|
+
/** Image URL (product photo, thumbnail) */
|
|
178
|
+
image?: string;
|
|
179
|
+
/** Price in currency units (rendered with locale formatting) */
|
|
180
|
+
price?: number;
|
|
181
|
+
/** Original price for showing discounts */
|
|
182
|
+
originalPrice?: number;
|
|
183
|
+
/** Currency code (default: USD) */
|
|
184
|
+
currency?: string;
|
|
185
|
+
/** Badge text (Sale, New, Low Stock, etc.) */
|
|
186
|
+
badge?: string;
|
|
187
|
+
/** Badge color/type for styling */
|
|
188
|
+
badgeType?: 'default' | 'success' | 'warning' | 'error' | 'info';
|
|
189
|
+
/** Quantity (for cart items) */
|
|
190
|
+
quantity?: number;
|
|
191
|
+
/** Enable +/- quantity controls */
|
|
192
|
+
adjustable?: boolean;
|
|
193
|
+
/** Minimum quantity (0 = can remove, default: 1) */
|
|
194
|
+
minQuantity?: number;
|
|
195
|
+
/** Maximum quantity allowed */
|
|
196
|
+
maxQuantity?: number;
|
|
197
|
+
/** Category for filtering (e.g., 'vegetarian', 'spicy') */
|
|
198
|
+
category?: string | string[];
|
|
199
|
+
/** Whether the option is disabled/unavailable */
|
|
200
|
+
disabled?: boolean;
|
|
201
|
+
/** Reason for being disabled (Out of stock, etc.) */
|
|
202
|
+
disabledReason?: string;
|
|
203
|
+
/** Pre-selected state for multi-select */
|
|
204
|
+
selected?: boolean;
|
|
205
|
+
/** Additional metadata (not rendered, returned with selection) */
|
|
206
|
+
meta?: Record<string, any>;
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* Ask for selection from options
|
|
210
|
+
*
|
|
211
|
+
* Supports simple string arrays for basic choices, or rich option objects
|
|
212
|
+
* for product catalogs, shopping carts, and other visual selections.
|
|
213
|
+
*
|
|
214
|
+
* @example Basic selection
|
|
215
|
+
* const env = yield io.ask.select('Choose environment:', ['dev', 'staging', 'prod']);
|
|
216
|
+
*
|
|
217
|
+
* @example Multi-select features
|
|
218
|
+
* const features = yield io.ask.select('Enable features:', ['auth', 'logs'], { multi: true });
|
|
219
|
+
*
|
|
220
|
+
* @example Product selection (e-commerce)
|
|
221
|
+
* const items = yield io.ask.select('Select items to purchase:', [
|
|
222
|
+
* {
|
|
223
|
+
* value: 'prod-1',
|
|
224
|
+
* label: 'Wireless Mouse',
|
|
225
|
+
* description: 'Ergonomic design',
|
|
226
|
+
* image: 'https://example.com/mouse.jpg',
|
|
227
|
+
* price: 29.99,
|
|
228
|
+
* badge: 'Bestseller'
|
|
229
|
+
* },
|
|
230
|
+
* {
|
|
231
|
+
* value: 'prod-2',
|
|
232
|
+
* label: 'Mechanical Keyboard',
|
|
233
|
+
* description: 'Cherry MX switches',
|
|
234
|
+
* image: 'https://example.com/keyboard.jpg',
|
|
235
|
+
* price: 149.99,
|
|
236
|
+
* originalPrice: 199.99,
|
|
237
|
+
* badge: 'Sale'
|
|
238
|
+
* }
|
|
239
|
+
* ], { multi: true, layout: 'cards', columns: 2 });
|
|
240
|
+
*
|
|
241
|
+
* @example Shopping cart review
|
|
242
|
+
* const confirmed = yield io.ask.select('Review your cart:', cartItems.map(item => ({
|
|
243
|
+
* value: item.id,
|
|
244
|
+
* label: item.name,
|
|
245
|
+
* image: item.thumbnail,
|
|
246
|
+
* price: item.price,
|
|
247
|
+
* quantity: item.qty,
|
|
248
|
+
* selected: true // Pre-selected
|
|
249
|
+
* })), { multi: true, layout: 'list' });
|
|
250
|
+
*/
|
|
251
|
+
declare function select(message: string, options: SelectOption[], config?: SelectOptions): AskSelect;
|
|
252
|
+
/** Options for number input */
|
|
253
|
+
interface NumberOptions {
|
|
254
|
+
id?: string;
|
|
255
|
+
default?: number;
|
|
256
|
+
min?: number;
|
|
257
|
+
max?: number;
|
|
258
|
+
step?: number;
|
|
259
|
+
required?: boolean;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Ask for number input
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* const qty = yield io.ask.number('Quantity:', { min: 1, max: 100 });
|
|
266
|
+
*/
|
|
267
|
+
declare function number(message: string, options?: NumberOptions): AskNumber;
|
|
268
|
+
/** Options for file input */
|
|
269
|
+
interface FileOptions {
|
|
270
|
+
id?: string;
|
|
271
|
+
accept?: string;
|
|
272
|
+
multiple?: boolean;
|
|
273
|
+
required?: boolean;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Ask for file selection
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* const file = yield io.ask.file('Select a document:', { accept: '.pdf,.doc' });
|
|
280
|
+
*/
|
|
281
|
+
declare function file(message: string, options?: FileOptions): AskFile;
|
|
282
|
+
/** Options for date input */
|
|
283
|
+
interface DateOptions {
|
|
284
|
+
id?: string;
|
|
285
|
+
default?: string;
|
|
286
|
+
min?: string;
|
|
287
|
+
max?: string;
|
|
288
|
+
includeTime?: boolean;
|
|
289
|
+
required?: boolean;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Ask for date selection
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* const date = yield io.ask.date('Select delivery date:');
|
|
296
|
+
* const datetime = yield io.ask.date('When?', { includeTime: true });
|
|
297
|
+
*/
|
|
298
|
+
declare function date(message: string, options?: DateOptions): AskDate;
|
|
299
|
+
/** Options for form input */
|
|
300
|
+
interface FormOptions {
|
|
301
|
+
id?: string;
|
|
302
|
+
required?: boolean;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Ask for form input (structured data)
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* const contact = yield io.ask.form('Enter contact details:', {
|
|
309
|
+
* type: 'object',
|
|
310
|
+
* properties: {
|
|
311
|
+
* name: { type: 'string', title: 'Full Name' },
|
|
312
|
+
* email: { type: 'string', format: 'email', title: 'Email' }
|
|
313
|
+
* },
|
|
314
|
+
* required: ['name', 'email']
|
|
315
|
+
* });
|
|
316
|
+
*/
|
|
317
|
+
declare function form(message: string, schema: FormSchema, options?: FormOptions): AskForm;
|
|
318
|
+
/** Options for url input */
|
|
319
|
+
interface UrlOptions {
|
|
320
|
+
id?: string;
|
|
321
|
+
elicitationId?: string;
|
|
322
|
+
required?: boolean;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Ask via URL (OAuth, external auth)
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* const auth = yield io.ask.url('Authenticate with GitHub:', 'https://github.com/login/...');
|
|
329
|
+
*/
|
|
330
|
+
declare function url(message: string, urlValue: string, options?: UrlOptions): AskUrl;
|
|
331
|
+
/**
|
|
332
|
+
* IO helper namespace for emit and ask yields
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* ```typescript
|
|
336
|
+
* import { io } from '@portel/photon-core';
|
|
337
|
+
*
|
|
338
|
+
* async *myTool() {
|
|
339
|
+
* yield io.emit.status('Starting...');
|
|
340
|
+
* const name = yield io.ask.text('Name?');
|
|
341
|
+
* }
|
|
342
|
+
* ```
|
|
343
|
+
*/
|
|
344
|
+
export declare const io: {
|
|
345
|
+
/**
|
|
346
|
+
* Emit helpers - fire and forget output
|
|
347
|
+
*/
|
|
348
|
+
readonly emit: {
|
|
349
|
+
readonly status: typeof status;
|
|
350
|
+
readonly progress: typeof progress;
|
|
351
|
+
readonly stream: typeof stream;
|
|
352
|
+
readonly log: typeof log;
|
|
353
|
+
readonly toast: typeof toast;
|
|
354
|
+
readonly thinking: typeof thinking;
|
|
355
|
+
readonly artifact: typeof artifact;
|
|
356
|
+
readonly ui: typeof ui;
|
|
357
|
+
};
|
|
358
|
+
/**
|
|
359
|
+
* Ask helpers - blocking input from user
|
|
360
|
+
*/
|
|
361
|
+
readonly ask: {
|
|
362
|
+
readonly text: typeof text;
|
|
363
|
+
readonly password: typeof password;
|
|
364
|
+
readonly confirm: typeof confirm;
|
|
365
|
+
readonly select: typeof select;
|
|
366
|
+
readonly number: typeof number;
|
|
367
|
+
readonly file: typeof file;
|
|
368
|
+
readonly date: typeof date;
|
|
369
|
+
readonly form: typeof form;
|
|
370
|
+
readonly url: typeof url;
|
|
371
|
+
};
|
|
372
|
+
};
|
|
373
|
+
export declare const emit: {
|
|
374
|
+
readonly status: typeof status;
|
|
375
|
+
readonly progress: typeof progress;
|
|
376
|
+
readonly stream: typeof stream;
|
|
377
|
+
readonly log: typeof log;
|
|
378
|
+
readonly toast: typeof toast;
|
|
379
|
+
readonly thinking: typeof thinking;
|
|
380
|
+
readonly artifact: typeof artifact;
|
|
381
|
+
readonly ui: typeof ui;
|
|
382
|
+
};
|
|
383
|
+
export declare const ask: {
|
|
384
|
+
readonly text: typeof text;
|
|
385
|
+
readonly password: typeof password;
|
|
386
|
+
readonly confirm: typeof confirm;
|
|
387
|
+
readonly select: typeof select;
|
|
388
|
+
readonly number: typeof number;
|
|
389
|
+
readonly file: typeof file;
|
|
390
|
+
readonly date: typeof date;
|
|
391
|
+
readonly form: typeof form;
|
|
392
|
+
readonly url: typeof url;
|
|
393
|
+
};
|
|
394
|
+
export {};
|
|
395
|
+
//# sourceMappingURL=io.d.ts.map
|
package/dist/io.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../src/io.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,YAAY,EACZ,UAAU,EACV,OAAO,EACP,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,MAAM,EACN,OAAO,EACP,WAAW,EACX,UAAU,EACV,SAAS,EACT,SAAS,EACT,OAAO,EACP,OAAO,EACP,OAAO,EACP,MAAM,EACN,UAAU,EACX,MAAM,gBAAgB,CAAC;AAMxB;;;;;;GAMG;AACH,iBAAS,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,GAAG,UAAU,CAEtE;AAED;;;;;;GAMG;AACH,iBAAS,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,YAAY,CAO3F;AAED;;;;;;;;GAQG;AACH,iBAAS,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,UAAU,CAO5E;AAED;;;;;GAKG;AACH,iBAAS,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAO3F;AAED;;;;;;GAMG;AACH,iBAAS,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,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
|
|
2
|
+
* IO Helper API
|
|
3
|
+
*
|
|
4
|
+
* Clean, ergonomic API for yielding emit and ask messages in Photon generators.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { io } from '@portel/photon-core';
|
|
9
|
+
*
|
|
10
|
+
* async *myTool() {
|
|
11
|
+
* yield io.emit.status('Starting...');
|
|
12
|
+
* yield io.emit.progress(0.5, 'Halfway there');
|
|
13
|
+
*
|
|
14
|
+
* const name = yield io.ask.text('What is your name?');
|
|
15
|
+
* const confirmed = yield io.ask.confirm('Continue?');
|
|
16
|
+
*
|
|
17
|
+
* return { name, confirmed };
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @module io
|
|
22
|
+
*/
|
|
23
|
+
// ══════════════════════════════════════════════════════════════════════════════
|
|
24
|
+
// EMIT HELPERS - Output to user (fire and forget)
|
|
25
|
+
// ══════════════════════════════════════════════════════════════════════════════
|
|
26
|
+
/**
|
|
27
|
+
* Emit a status message
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* yield io.emit.status('Connecting...');
|
|
31
|
+
* yield io.emit.status('Done!', 'success');
|
|
32
|
+
*/
|
|
33
|
+
function status(message, type) {
|
|
34
|
+
return { emit: 'status', message, ...(type && { type }) };
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Emit a progress update
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* yield io.emit.progress(0.5); // 50%
|
|
41
|
+
* yield io.emit.progress(0.75, 'Almost done');
|
|
42
|
+
*/
|
|
43
|
+
function progress(value, message, meta) {
|
|
44
|
+
return {
|
|
45
|
+
emit: 'progress',
|
|
46
|
+
value,
|
|
47
|
+
...(message && { message }),
|
|
48
|
+
...(meta && { meta }),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Emit a stream chunk
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* for await (const chunk of stream) {
|
|
56
|
+
* yield io.emit.stream(chunk);
|
|
57
|
+
* }
|
|
58
|
+
* yield io.emit.stream('', true); // final
|
|
59
|
+
*/
|
|
60
|
+
function stream(data, final, contentType) {
|
|
61
|
+
return {
|
|
62
|
+
emit: 'stream',
|
|
63
|
+
data,
|
|
64
|
+
...(final && { final }),
|
|
65
|
+
...(contentType && { contentType }),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Emit a log message (for debugging)
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* yield io.emit.log('Processing item', 'debug', { id: 123 });
|
|
73
|
+
*/
|
|
74
|
+
function log(message, level, data) {
|
|
75
|
+
return {
|
|
76
|
+
emit: 'log',
|
|
77
|
+
message,
|
|
78
|
+
...(level && { level }),
|
|
79
|
+
...(data && { data }),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Emit a toast notification
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* yield io.emit.toast('Saved!', 'success');
|
|
87
|
+
* yield io.emit.toast('Error!', 'error', 5000);
|
|
88
|
+
*/
|
|
89
|
+
function toast(message, type, duration) {
|
|
90
|
+
return {
|
|
91
|
+
emit: 'toast',
|
|
92
|
+
message,
|
|
93
|
+
...(type && { type }),
|
|
94
|
+
...(duration !== undefined && { duration }),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Emit thinking indicator
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* yield io.emit.thinking(true);
|
|
102
|
+
* // ... heavy computation
|
|
103
|
+
* yield io.emit.thinking(false);
|
|
104
|
+
*/
|
|
105
|
+
function thinking(active) {
|
|
106
|
+
return { emit: 'thinking', active };
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Emit an artifact (image, code, document)
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* yield io.emit.artifact('image', { url: 'https://...', title: 'Chart' });
|
|
113
|
+
* yield io.emit.artifact('code', { content: 'const x = 1;', language: 'typescript' });
|
|
114
|
+
*/
|
|
115
|
+
function artifact(type, options) {
|
|
116
|
+
return { emit: 'artifact', type, ...options };
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Emit a UI component
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* yield io.emit.ui('preferences', { currentTheme: 'dark' });
|
|
123
|
+
* yield io.emit.ui(null, { inline: '<div>Hello</div>' });
|
|
124
|
+
*/
|
|
125
|
+
function ui(id, options) {
|
|
126
|
+
return { emit: 'ui', ...(id && { id }), ...options };
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Ask for text input
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* const name = yield io.ask.text('What is your name?');
|
|
133
|
+
* const email = yield io.ask.text('Email:', { pattern: '.*@.*' });
|
|
134
|
+
*/
|
|
135
|
+
function text(message, options) {
|
|
136
|
+
return { ask: 'text', message, ...options };
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Ask for password input (masked)
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* const apiKey = yield io.ask.password('Enter API key:');
|
|
143
|
+
*/
|
|
144
|
+
function password(message, options) {
|
|
145
|
+
return { ask: 'password', message, ...options };
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Ask for confirmation (yes/no)
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* const ok = yield io.ask.confirm('Delete this file?');
|
|
152
|
+
* const dangerous = yield io.ask.confirm('Proceed?', { dangerous: true });
|
|
153
|
+
*/
|
|
154
|
+
function confirm(message, options) {
|
|
155
|
+
return { ask: 'confirm', message, ...options };
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Ask for selection from options
|
|
159
|
+
*
|
|
160
|
+
* Supports simple string arrays for basic choices, or rich option objects
|
|
161
|
+
* for product catalogs, shopping carts, and other visual selections.
|
|
162
|
+
*
|
|
163
|
+
* @example Basic selection
|
|
164
|
+
* const env = yield io.ask.select('Choose environment:', ['dev', 'staging', 'prod']);
|
|
165
|
+
*
|
|
166
|
+
* @example Multi-select features
|
|
167
|
+
* const features = yield io.ask.select('Enable features:', ['auth', 'logs'], { multi: true });
|
|
168
|
+
*
|
|
169
|
+
* @example Product selection (e-commerce)
|
|
170
|
+
* const items = yield io.ask.select('Select items to purchase:', [
|
|
171
|
+
* {
|
|
172
|
+
* value: 'prod-1',
|
|
173
|
+
* label: 'Wireless Mouse',
|
|
174
|
+
* description: 'Ergonomic design',
|
|
175
|
+
* image: 'https://example.com/mouse.jpg',
|
|
176
|
+
* price: 29.99,
|
|
177
|
+
* badge: 'Bestseller'
|
|
178
|
+
* },
|
|
179
|
+
* {
|
|
180
|
+
* value: 'prod-2',
|
|
181
|
+
* label: 'Mechanical Keyboard',
|
|
182
|
+
* description: 'Cherry MX switches',
|
|
183
|
+
* image: 'https://example.com/keyboard.jpg',
|
|
184
|
+
* price: 149.99,
|
|
185
|
+
* originalPrice: 199.99,
|
|
186
|
+
* badge: 'Sale'
|
|
187
|
+
* }
|
|
188
|
+
* ], { multi: true, layout: 'cards', columns: 2 });
|
|
189
|
+
*
|
|
190
|
+
* @example Shopping cart review
|
|
191
|
+
* const confirmed = yield io.ask.select('Review your cart:', cartItems.map(item => ({
|
|
192
|
+
* value: item.id,
|
|
193
|
+
* label: item.name,
|
|
194
|
+
* image: item.thumbnail,
|
|
195
|
+
* price: item.price,
|
|
196
|
+
* quantity: item.qty,
|
|
197
|
+
* selected: true // Pre-selected
|
|
198
|
+
* })), { multi: true, layout: 'list' });
|
|
199
|
+
*/
|
|
200
|
+
function select(message, options, config) {
|
|
201
|
+
return { ask: 'select', message, options, ...config };
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Ask for number input
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* const qty = yield io.ask.number('Quantity:', { min: 1, max: 100 });
|
|
208
|
+
*/
|
|
209
|
+
function number(message, options) {
|
|
210
|
+
return { ask: 'number', message, ...options };
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Ask for file selection
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* const file = yield io.ask.file('Select a document:', { accept: '.pdf,.doc' });
|
|
217
|
+
*/
|
|
218
|
+
function file(message, options) {
|
|
219
|
+
return { ask: 'file', message, ...options };
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Ask for date selection
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* const date = yield io.ask.date('Select delivery date:');
|
|
226
|
+
* const datetime = yield io.ask.date('When?', { includeTime: true });
|
|
227
|
+
*/
|
|
228
|
+
function date(message, options) {
|
|
229
|
+
return { ask: 'date', message, ...options };
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Ask for form input (structured data)
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* const contact = yield io.ask.form('Enter contact details:', {
|
|
236
|
+
* type: 'object',
|
|
237
|
+
* properties: {
|
|
238
|
+
* name: { type: 'string', title: 'Full Name' },
|
|
239
|
+
* email: { type: 'string', format: 'email', title: 'Email' }
|
|
240
|
+
* },
|
|
241
|
+
* required: ['name', 'email']
|
|
242
|
+
* });
|
|
243
|
+
*/
|
|
244
|
+
function form(message, schema, options) {
|
|
245
|
+
return { ask: 'form', message, schema, ...options };
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Ask via URL (OAuth, external auth)
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* const auth = yield io.ask.url('Authenticate with GitHub:', 'https://github.com/login/...');
|
|
252
|
+
*/
|
|
253
|
+
function url(message, urlValue, options) {
|
|
254
|
+
return { ask: 'url', message, url: urlValue, ...options };
|
|
255
|
+
}
|
|
256
|
+
// ══════════════════════════════════════════════════════════════════════════════
|
|
257
|
+
// EXPORTED API
|
|
258
|
+
// ══════════════════════════════════════════════════════════════════════════════
|
|
259
|
+
/**
|
|
260
|
+
* IO helper namespace for emit and ask yields
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```typescript
|
|
264
|
+
* import { io } from '@portel/photon-core';
|
|
265
|
+
*
|
|
266
|
+
* async *myTool() {
|
|
267
|
+
* yield io.emit.status('Starting...');
|
|
268
|
+
* const name = yield io.ask.text('Name?');
|
|
269
|
+
* }
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
export const io = {
|
|
273
|
+
/**
|
|
274
|
+
* Emit helpers - fire and forget output
|
|
275
|
+
*/
|
|
276
|
+
emit: {
|
|
277
|
+
status,
|
|
278
|
+
progress,
|
|
279
|
+
stream,
|
|
280
|
+
log,
|
|
281
|
+
toast,
|
|
282
|
+
thinking,
|
|
283
|
+
artifact,
|
|
284
|
+
ui,
|
|
285
|
+
},
|
|
286
|
+
/**
|
|
287
|
+
* Ask helpers - blocking input from user
|
|
288
|
+
*/
|
|
289
|
+
ask: {
|
|
290
|
+
text,
|
|
291
|
+
password,
|
|
292
|
+
confirm,
|
|
293
|
+
select,
|
|
294
|
+
number,
|
|
295
|
+
file,
|
|
296
|
+
date,
|
|
297
|
+
form,
|
|
298
|
+
url,
|
|
299
|
+
},
|
|
300
|
+
};
|
|
301
|
+
// Also export individual functions for direct import
|
|
302
|
+
export const emit = io.emit;
|
|
303
|
+
export const ask = io.ask;
|
|
304
|
+
//# sourceMappingURL=io.js.map
|