@portel/photon-core 1.0.1 → 1.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.
@@ -0,0 +1,205 @@
1
+ /**
2
+ * Generator-based Tool Execution
3
+ *
4
+ * Enables photon tools to use generator functions with `yield` for:
5
+ * - User prompts (text, password, confirm, select)
6
+ * - Progress updates
7
+ * - Streaming responses
8
+ * - Multi-step wizards
9
+ *
10
+ * The runtime handles yields appropriately based on the protocol:
11
+ * - REST: Extract yields as optional parameters
12
+ * - WebSocket/MCP: Interactive prompts
13
+ * - CLI: readline prompts
14
+ * - Fallback: Native OS dialogs
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * async *connect(params: { ip: string }) {
19
+ * await this.startConnection(params.ip);
20
+ *
21
+ * const code: string = yield {
22
+ * prompt: 'Enter the 6-digit code:',
23
+ * type: 'text'
24
+ * };
25
+ *
26
+ * await this.sendCode(code);
27
+ * return { success: true };
28
+ * }
29
+ * ```
30
+ */
31
+ /**
32
+ * Text input prompt
33
+ */
34
+ export interface PromptYield {
35
+ prompt: string;
36
+ type?: 'text' | 'password';
37
+ default?: string;
38
+ /** Unique identifier for this prompt (auto-generated if not provided) */
39
+ id?: string;
40
+ /** Validation pattern */
41
+ pattern?: string;
42
+ /** Whether this prompt is required */
43
+ required?: boolean;
44
+ }
45
+ /**
46
+ * Confirmation dialog
47
+ */
48
+ export interface ConfirmYield {
49
+ confirm: string;
50
+ /** Mark as dangerous action (UI can show warning styling) */
51
+ dangerous?: boolean;
52
+ id?: string;
53
+ }
54
+ /**
55
+ * Selection from options
56
+ */
57
+ export interface SelectYield {
58
+ select: string;
59
+ options: Array<string | {
60
+ value: string;
61
+ label: string;
62
+ }>;
63
+ /** Allow multiple selections */
64
+ multi?: boolean;
65
+ id?: string;
66
+ }
67
+ /**
68
+ * Progress update (for long-running operations)
69
+ */
70
+ export interface ProgressYield {
71
+ progress: number;
72
+ status?: string;
73
+ /** Additional data to stream to client */
74
+ data?: any;
75
+ }
76
+ /**
77
+ * Stream data to client
78
+ */
79
+ export interface StreamYield {
80
+ stream: any;
81
+ /** Whether this is the final chunk */
82
+ final?: boolean;
83
+ }
84
+ /**
85
+ * Log/debug message
86
+ */
87
+ export interface LogYield {
88
+ log: string;
89
+ level?: 'debug' | 'info' | 'warn' | 'error';
90
+ }
91
+ /**
92
+ * All possible yield types
93
+ */
94
+ export type PhotonYield = PromptYield | ConfirmYield | SelectYield | ProgressYield | StreamYield | LogYield;
95
+ /**
96
+ * Check if a yield requires user input
97
+ */
98
+ export declare function isInputYield(y: PhotonYield): y is PromptYield | ConfirmYield | SelectYield;
99
+ /**
100
+ * Check if a yield is a progress update
101
+ */
102
+ export declare function isProgressYield(y: PhotonYield): y is ProgressYield;
103
+ /**
104
+ * Check if a yield is streaming data
105
+ */
106
+ export declare function isStreamYield(y: PhotonYield): y is StreamYield;
107
+ /**
108
+ * Check if a yield is a log message
109
+ */
110
+ export declare function isLogYield(y: PhotonYield): y is LogYield;
111
+ /**
112
+ * Function that provides input for a yield
113
+ * Runtimes implement this based on their protocol
114
+ */
115
+ export type InputProvider = (yielded: PhotonYield) => Promise<any>;
116
+ /**
117
+ * Handler for non-input yields (progress, stream, log)
118
+ */
119
+ export type OutputHandler = (yielded: PhotonYield) => void | Promise<void>;
120
+ /**
121
+ * Configuration for generator execution
122
+ */
123
+ export interface GeneratorExecutorConfig {
124
+ /** Provides input for prompt/confirm/select yields */
125
+ inputProvider: InputProvider;
126
+ /** Handles progress/stream/log yields */
127
+ outputHandler?: OutputHandler;
128
+ /** Pre-provided inputs (for REST APIs) */
129
+ preProvidedInputs?: Record<string, any>;
130
+ /** Timeout for waiting for input (ms) */
131
+ inputTimeout?: number;
132
+ }
133
+ /**
134
+ * Execute a generator-based tool
135
+ *
136
+ * @param generator - The async generator to execute
137
+ * @param config - Configuration for handling yields
138
+ * @returns The final return value of the generator
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * const result = await executeGenerator(tool.connect({ ip: '192.168.1.1' }), {
143
+ * inputProvider: async (y) => {
144
+ * if ('prompt' in y) return await readline(y.prompt);
145
+ * if ('confirm' in y) return await confirm(y.confirm);
146
+ * },
147
+ * outputHandler: (y) => {
148
+ * if ('progress' in y) console.log(`Progress: ${y.progress}%`);
149
+ * }
150
+ * });
151
+ * ```
152
+ */
153
+ export declare function executeGenerator<T>(generator: AsyncGenerator<PhotonYield, T, any>, config: GeneratorExecutorConfig): Promise<T>;
154
+ /**
155
+ * Check if a function is an async generator function
156
+ */
157
+ export declare function isAsyncGeneratorFunction(fn: any): fn is (...args: any[]) => AsyncGenerator;
158
+ /**
159
+ * Check if a value is an async generator (already invoked)
160
+ */
161
+ export declare function isAsyncGenerator(obj: any): obj is AsyncGenerator;
162
+ /**
163
+ * Information about a yield point extracted from a generator
164
+ */
165
+ export interface ExtractedYield {
166
+ id: string;
167
+ type: 'prompt' | 'confirm' | 'select';
168
+ prompt?: string;
169
+ options?: Array<string | {
170
+ value: string;
171
+ label: string;
172
+ }>;
173
+ default?: string;
174
+ required?: boolean;
175
+ pattern?: string;
176
+ dangerous?: boolean;
177
+ multi?: boolean;
178
+ }
179
+ /**
180
+ * Extract yield information by running generator with mock provider
181
+ * This is used for REST API schema generation
182
+ *
183
+ * Note: This only extracts yields that are reachable with default/empty inputs
184
+ * Complex conditional yields may not be extracted
185
+ */
186
+ export declare function extractYields(generatorFn: (...args: any[]) => AsyncGenerator<PhotonYield, any, any>, mockParams?: any): Promise<ExtractedYield[]>;
187
+ /**
188
+ * Create an input provider from pre-provided values
189
+ * Throws if a required value is missing
190
+ */
191
+ export declare function createPrefilledProvider(inputs: Record<string, any>): InputProvider;
192
+ /**
193
+ * Error thrown when input is needed but not available
194
+ * Runtimes can catch this to return appropriate responses
195
+ */
196
+ export declare class NeedsInputError extends Error {
197
+ readonly yielded: PhotonYield;
198
+ constructor(yielded: PhotonYield);
199
+ }
200
+ /**
201
+ * Wrap a regular async function to behave like a generator
202
+ * Useful for uniform handling in runtimes
203
+ */
204
+ export declare function wrapAsGenerator<T>(asyncFn: () => Promise<T>): AsyncGenerator<never, T, unknown>;
205
+ //# sourceMappingURL=generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAMH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yEAAyE;IACzE,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,yBAAyB;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sCAAsC;IACtC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,KAAK,CAAC,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC1D,gCAAgC;IAChC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,GAAG,CAAC;IACZ,sCAAsC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,CAAC;gBAEzB,OAAO,EAAE,WAAW;CAQjC;AAMD;;;GAGG;AACH,wBAAuB,eAAe,CAAC,CAAC,EACtC,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACxB,cAAc,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,CAAC,CAEnC"}
@@ -0,0 +1,248 @@
1
+ /**
2
+ * Generator-based Tool Execution
3
+ *
4
+ * Enables photon tools to use generator functions with `yield` for:
5
+ * - User prompts (text, password, confirm, select)
6
+ * - Progress updates
7
+ * - Streaming responses
8
+ * - Multi-step wizards
9
+ *
10
+ * The runtime handles yields appropriately based on the protocol:
11
+ * - REST: Extract yields as optional parameters
12
+ * - WebSocket/MCP: Interactive prompts
13
+ * - CLI: readline prompts
14
+ * - Fallback: Native OS dialogs
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * async *connect(params: { ip: string }) {
19
+ * await this.startConnection(params.ip);
20
+ *
21
+ * const code: string = yield {
22
+ * prompt: 'Enter the 6-digit code:',
23
+ * type: 'text'
24
+ * };
25
+ *
26
+ * await this.sendCode(code);
27
+ * return { success: true };
28
+ * }
29
+ * ```
30
+ */
31
+ /**
32
+ * Check if a yield requires user input
33
+ */
34
+ export function isInputYield(y) {
35
+ return 'prompt' in y || 'confirm' in y || 'select' in y;
36
+ }
37
+ /**
38
+ * Check if a yield is a progress update
39
+ */
40
+ export function isProgressYield(y) {
41
+ return 'progress' in y;
42
+ }
43
+ /**
44
+ * Check if a yield is streaming data
45
+ */
46
+ export function isStreamYield(y) {
47
+ return 'stream' in y;
48
+ }
49
+ /**
50
+ * Check if a yield is a log message
51
+ */
52
+ export function isLogYield(y) {
53
+ return 'log' in y;
54
+ }
55
+ // ============================================================================
56
+ // Generator Executor - Runs generator tools
57
+ // ============================================================================
58
+ /**
59
+ * Execute a generator-based tool
60
+ *
61
+ * @param generator - The async generator to execute
62
+ * @param config - Configuration for handling yields
63
+ * @returns The final return value of the generator
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const result = await executeGenerator(tool.connect({ ip: '192.168.1.1' }), {
68
+ * inputProvider: async (y) => {
69
+ * if ('prompt' in y) return await readline(y.prompt);
70
+ * if ('confirm' in y) return await confirm(y.confirm);
71
+ * },
72
+ * outputHandler: (y) => {
73
+ * if ('progress' in y) console.log(`Progress: ${y.progress}%`);
74
+ * }
75
+ * });
76
+ * ```
77
+ */
78
+ export async function executeGenerator(generator, config) {
79
+ const { inputProvider, outputHandler, preProvidedInputs } = config;
80
+ let promptIndex = 0;
81
+ let result = await generator.next();
82
+ while (!result.done) {
83
+ const yielded = result.value;
84
+ // Handle input yields (prompt, confirm, select)
85
+ if (isInputYield(yielded)) {
86
+ // Generate ID if not provided
87
+ const yieldId = yielded.id || `prompt_${promptIndex++}`;
88
+ // Check for pre-provided input (REST API style)
89
+ if (preProvidedInputs && yieldId in preProvidedInputs) {
90
+ result = await generator.next(preProvidedInputs[yieldId]);
91
+ continue;
92
+ }
93
+ // Get input from provider
94
+ const input = await inputProvider(yielded);
95
+ result = await generator.next(input);
96
+ }
97
+ // Handle output yields (progress, stream, log)
98
+ else {
99
+ if (outputHandler) {
100
+ await outputHandler(yielded);
101
+ }
102
+ // Continue without providing a value
103
+ result = await generator.next();
104
+ }
105
+ }
106
+ return result.value;
107
+ }
108
+ // ============================================================================
109
+ // Generator Detection - Check if a function is a generator
110
+ // ============================================================================
111
+ /**
112
+ * Check if a function is an async generator function
113
+ */
114
+ export function isAsyncGeneratorFunction(fn) {
115
+ if (!fn)
116
+ return false;
117
+ const constructor = fn.constructor;
118
+ if (!constructor)
119
+ return false;
120
+ if (constructor.name === 'AsyncGeneratorFunction')
121
+ return true;
122
+ // Check prototype chain
123
+ const prototype = Object.getPrototypeOf(fn);
124
+ return prototype && prototype.constructor &&
125
+ prototype.constructor.name === 'AsyncGeneratorFunction';
126
+ }
127
+ /**
128
+ * Check if a value is an async generator (already invoked)
129
+ */
130
+ export function isAsyncGenerator(obj) {
131
+ return obj &&
132
+ typeof obj.next === 'function' &&
133
+ typeof obj.return === 'function' &&
134
+ typeof obj.throw === 'function' &&
135
+ typeof obj[Symbol.asyncIterator] === 'function';
136
+ }
137
+ /**
138
+ * Extract yield information by running generator with mock provider
139
+ * This is used for REST API schema generation
140
+ *
141
+ * Note: This only extracts yields that are reachable with default/empty inputs
142
+ * Complex conditional yields may not be extracted
143
+ */
144
+ export async function extractYields(generatorFn, mockParams = {}) {
145
+ const yields = [];
146
+ let promptIndex = 0;
147
+ try {
148
+ const generator = generatorFn(mockParams);
149
+ let result = await generator.next();
150
+ while (!result.done) {
151
+ const yielded = result.value;
152
+ if (isInputYield(yielded)) {
153
+ const id = yielded.id || `prompt_${promptIndex++}`;
154
+ if ('prompt' in yielded) {
155
+ yields.push({
156
+ id,
157
+ type: yielded.type === 'password' ? 'prompt' : 'prompt',
158
+ prompt: yielded.prompt,
159
+ default: yielded.default,
160
+ required: yielded.required,
161
+ pattern: yielded.pattern,
162
+ });
163
+ // Provide mock value to continue
164
+ result = await generator.next(yielded.default || '');
165
+ }
166
+ else if ('confirm' in yielded) {
167
+ yields.push({
168
+ id,
169
+ type: 'confirm',
170
+ prompt: yielded.confirm,
171
+ dangerous: yielded.dangerous,
172
+ });
173
+ result = await generator.next(true);
174
+ }
175
+ else if ('select' in yielded) {
176
+ yields.push({
177
+ id,
178
+ type: 'select',
179
+ prompt: yielded.select,
180
+ options: yielded.options,
181
+ multi: yielded.multi,
182
+ });
183
+ const firstOption = yielded.options[0];
184
+ const mockValue = typeof firstOption === 'string' ? firstOption : firstOption.value;
185
+ result = await generator.next(yielded.multi ? [mockValue] : mockValue);
186
+ }
187
+ }
188
+ else {
189
+ // Skip non-input yields
190
+ result = await generator.next();
191
+ }
192
+ }
193
+ }
194
+ catch (error) {
195
+ // Generator may throw if it needs real resources
196
+ // Return what we've extracted so far
197
+ console.warn('[generator] Yield extraction incomplete:', error);
198
+ }
199
+ return yields;
200
+ }
201
+ // ============================================================================
202
+ // Default Input Providers - Built-in implementations for common scenarios
203
+ // ============================================================================
204
+ /**
205
+ * Create an input provider from pre-provided values
206
+ * Throws if a required value is missing
207
+ */
208
+ export function createPrefilledProvider(inputs) {
209
+ return async (yielded) => {
210
+ if (!isInputYield(yielded))
211
+ return undefined;
212
+ const id = yielded.id || 'default';
213
+ if (id in inputs) {
214
+ return inputs[id];
215
+ }
216
+ // Check for default value
217
+ if ('prompt' in yielded && yielded.default !== undefined) {
218
+ return yielded.default;
219
+ }
220
+ throw new NeedsInputError(yielded);
221
+ };
222
+ }
223
+ /**
224
+ * Error thrown when input is needed but not available
225
+ * Runtimes can catch this to return appropriate responses
226
+ */
227
+ export class NeedsInputError extends Error {
228
+ yielded;
229
+ constructor(yielded) {
230
+ const message = 'prompt' in yielded ? yielded.prompt :
231
+ 'confirm' in yielded ? yielded.confirm :
232
+ 'select' in yielded ? yielded.select : 'Input required';
233
+ super(`Input required: ${message}`);
234
+ this.name = 'NeedsInputError';
235
+ this.yielded = yielded;
236
+ }
237
+ }
238
+ // ============================================================================
239
+ // Utility: Wrap regular async function to match generator interface
240
+ // ============================================================================
241
+ /**
242
+ * Wrap a regular async function to behave like a generator
243
+ * Useful for uniform handling in runtimes
244
+ */
245
+ export async function* wrapAsGenerator(asyncFn) {
246
+ return await asyncFn();
247
+ }
248
+ //# sourceMappingURL=generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAgFH;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,CAAc;IACzC,OAAO,QAAQ,IAAI,CAAC,IAAI,SAAS,IAAI,CAAC,IAAI,QAAQ,IAAI,CAAC,CAAC;AAC1D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,CAAc;IAC5C,OAAO,UAAU,IAAI,CAAC,CAAC;AACzB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,CAA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;QAC9B,MAAM,OAAO,GAAG,QAAQ,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACtC,SAAS,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;gBACxC,QAAQ,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,gBAAgB,CAAC;QACxE,KAAK,CAAC,mBAAmB,OAAO,EAAE,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF;AAED,+EAA+E;AAC/E,oEAAoE;AACpE,+EAA+E;AAE/E;;;GAGG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,eAAe,CACpC,OAAyB;IAEzB,OAAO,MAAM,OAAO,EAAE,CAAC;AACzB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -38,4 +38,6 @@ export { SchemaExtractor } from './schema-extractor.js';
38
38
  export { formatOutput, detectFormat, renderPrimitive, renderList, renderTable, renderTree, renderNone, formatKey, formatValue, formatToMimeType, printSuccess, printError, printInfo, printWarning, printHeader, STATUS, } from './cli-formatter.js';
39
39
  export { resolvePath, listFiles, ensureDir, resolvePhotonPath, listPhotonFiles, ensurePhotonDir, DEFAULT_PHOTON_DIR, type ResolverOptions, } from './path-resolver.js';
40
40
  export * from './types.js';
41
+ export { isInputYield, isProgressYield, isStreamYield, isLogYield, isAsyncGeneratorFunction, isAsyncGenerator, executeGenerator, extractYields, createPrefilledProvider, NeedsInputError, wrapAsGenerator, type PhotonYield, type PromptYield, type ConfirmYield, type SelectYield, type ProgressYield, type StreamYield, type LogYield, type InputProvider, type OutputHandler, type GeneratorExecutorConfig, type ExtractedYield, } from './generator.js';
42
+ export { prompt, confirm, elicit, elicitReadline, elicitNativeDialog, setPromptHandler, getPromptHandler, setElicitHandler, getElicitHandler, type ElicitOptions, type ElicitResult, type ElicitHandler, type PromptHandler, } from './elicit.js';
41
43
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG5D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGxD,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,UAAU,EACV,WAAW,EACX,UAAU,EACV,UAAU,EACV,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,SAAS,EACT,YAAY,EACZ,WAAW,EACX,MAAM,GACP,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,WAAW,EACX,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,KAAK,eAAe,GACrB,MAAM,oBAAoB,CAAC;AAG5B,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG5D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGxD,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,UAAU,EACV,WAAW,EACX,UAAU,EACV,UAAU,EACV,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,SAAS,EACT,YAAY,EACZ,WAAW,EACX,MAAM,GACP,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,WAAW,EACX,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,KAAK,eAAe,GACrB,MAAM,oBAAoB,CAAC;AAG5B,cAAc,YAAY,CAAC;AAG3B,OAAO,EAEL,YAAY,EACZ,eAAe,EACf,aAAa,EACb,UAAU,EAEV,wBAAwB,EACxB,gBAAgB,EAEhB,gBAAgB,EAEhB,aAAa,EAEb,uBAAuB,EACvB,eAAe,EAEf,eAAe,EAEf,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,uBAAuB,EAC5B,KAAK,cAAc,GACpB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAEL,MAAM,EACN,OAAO,EAEP,MAAM,EACN,cAAc,EACd,kBAAkB,EAElB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAEhB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,aAAa,GACnB,MAAM,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -44,4 +44,26 @@ export { formatOutput, detectFormat, renderPrimitive, renderList, renderTable, r
44
44
  export { resolvePath, listFiles, ensureDir, resolvePhotonPath, listPhotonFiles, ensurePhotonDir, DEFAULT_PHOTON_DIR, } from './path-resolver.js';
45
45
  // Types
46
46
  export * from './types.js';
47
+ // Generator-based tools - yield for prompts, progress, streaming
48
+ export {
49
+ // Yield type checking
50
+ isInputYield, isProgressYield, isStreamYield, isLogYield,
51
+ // Generator detection
52
+ isAsyncGeneratorFunction, isAsyncGenerator,
53
+ // Executor
54
+ executeGenerator,
55
+ // Yield extraction (for REST schema generation)
56
+ extractYields,
57
+ // Built-in providers
58
+ createPrefilledProvider, NeedsInputError,
59
+ // Utility
60
+ wrapAsGenerator, } from './generator.js';
61
+ // Elicit - Cross-platform user input (legacy, prefer generators)
62
+ export {
63
+ // Simple functions (no imports needed in photon files)
64
+ prompt, confirm,
65
+ // Full elicit with options
66
+ elicit, elicitReadline, elicitNativeDialog,
67
+ // Handler management (for runtimes)
68
+ setPromptHandler, getPromptHandler, setElicitHandler, getElicitHandler, } from './elicit.js';
47
69
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,wBAAwB;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,oBAAoB;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,iBAAiB;AACjB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,UAAU,EACV,WAAW,EACX,UAAU,EACV,UAAU,EACV,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,SAAS,EACT,YAAY,EACZ,WAAW,EACX,MAAM,GACP,MAAM,oBAAoB,CAAC;AAE5B,kBAAkB;AAClB,OAAO,EACL,WAAW,EACX,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,kBAAkB,GAEnB,MAAM,oBAAoB,CAAC;AAE5B,QAAQ;AACR,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,wBAAwB;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,oBAAoB;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,iBAAiB;AACjB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,UAAU,EACV,WAAW,EACX,UAAU,EACV,UAAU,EACV,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,SAAS,EACT,YAAY,EACZ,WAAW,EACX,MAAM,GACP,MAAM,oBAAoB,CAAC;AAE5B,kBAAkB;AAClB,OAAO,EACL,WAAW,EACX,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,kBAAkB,GAEnB,MAAM,oBAAoB,CAAC;AAE5B,QAAQ;AACR,cAAc,YAAY,CAAC;AAE3B,iEAAiE;AACjE,OAAO;AACL,sBAAsB;AACtB,YAAY,EACZ,eAAe,EACf,aAAa,EACb,UAAU;AACV,sBAAsB;AACtB,wBAAwB,EACxB,gBAAgB;AAChB,WAAW;AACX,gBAAgB;AAChB,gDAAgD;AAChD,aAAa;AACb,qBAAqB;AACrB,uBAAuB,EACvB,eAAe;AACf,UAAU;AACV,eAAe,GAahB,MAAM,gBAAgB,CAAC;AAExB,iEAAiE;AACjE,OAAO;AACL,uDAAuD;AACvD,MAAM,EACN,OAAO;AACP,2BAA2B;AAC3B,MAAM,EACN,cAAc,EACd,kBAAkB;AAClB,oCAAoC;AACpC,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,GAMjB,MAAM,aAAa,CAAC"}
@@ -108,5 +108,11 @@ export declare class SchemaExtractor {
108
108
  * Example: @mimeType text/markdown
109
109
  */
110
110
  private extractMimeType;
111
+ /**
112
+ * Extract yield information from JSDoc for generator methods
113
+ * Supports @yields tags with id, type, and description
114
+ * Example: @yields {pairing_code} text Enter the 6-digit code shown on TV
115
+ */
116
+ private extractYieldsFromJSDoc;
111
117
  }
112
118
  //# sourceMappingURL=schema-extractor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema-extractor.d.ts","sourceRoot":"","sources":["../src/schema-extractor.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAE,UAAU,EAAgB,MAAM,YAAY,CAAC;AAEvG,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,OAAO,EAAE,UAAU,EAAE,CAAC;CACvB;AAED;;GAEG;AACH,qBAAa,eAAe;IAC1B;;OAEG;IACG,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAUnE;;OAEG;IACH,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB;IAyHvD;;OAEG;IACH,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe,EAAE;IAIpD;;OAEG;IACH,OAAO,CAAC,eAAe;IAqBvB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAS7B;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAiC3B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAyGxB;;;;;OAKG;IACH,OAAO,CAAC,oBAAoB;IA0F5B;;OAEG;IACH,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,EAAE;IAmD5D;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAuB3B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAqB1B;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IA4BxB;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;IA2G/B;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IA0FxB;;OAEG;IACH,OAAO,CAAC,cAAc;IAItB;;OAEG;IACH,OAAO,CAAC,YAAY;IAIpB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAKx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AIpB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAKxB;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IAsBrB;;;OAGG;IACH,OAAO,CAAC,eAAe;IAKvB;;;;OAIG;IACH,OAAO,CAAC,sBAAsB;CAiB/B"}
@@ -45,6 +45,8 @@ export class SchemaExtractor {
45
45
  const processMethod = (member) => {
46
46
  const methodName = member.name.getText(sourceFile);
47
47
  const jsdoc = this.getJSDocComment(member, sourceFile);
48
+ // Check if this is an async generator method (has asterisk token)
49
+ const isGenerator = member.asteriskToken !== undefined;
48
50
  // Extract parameter type information
49
51
  const paramsType = this.getFirstParameterType(member, sourceFile);
50
52
  if (!paramsType) {
@@ -100,11 +102,14 @@ export class SchemaExtractor {
100
102
  // Otherwise, it's a regular tool
101
103
  else {
102
104
  const outputFormat = this.extractFormat(jsdoc);
105
+ const yields = isGenerator ? this.extractYieldsFromJSDoc(jsdoc) : undefined;
103
106
  tools.push({
104
107
  name: methodName,
105
108
  description,
106
109
  inputSchema,
107
110
  ...(outputFormat ? { outputFormat } : {}),
111
+ ...(isGenerator ? { isGenerator: true } : {}),
112
+ ...(yields && yields.length > 0 ? { yields } : {}),
108
113
  });
109
114
  }
110
115
  };
@@ -113,7 +118,7 @@ export class SchemaExtractor {
113
118
  // Look for class declarations
114
119
  if (ts.isClassDeclaration(node)) {
115
120
  node.members.forEach((member) => {
116
- // Look for async methods
121
+ // Look for async methods (including async generators with *)
117
122
  if (ts.isMethodDeclaration(member) &&
118
123
  member.modifiers?.some(m => m.kind === ts.SyntaxKind.AsyncKeyword)) {
119
124
  processMethod(member);
@@ -736,5 +741,25 @@ export class SchemaExtractor {
736
741
  const match = jsdocContent.match(/@mimeType\s+([\w\/\-+.]+)/i);
737
742
  return match ? match[1].trim() : undefined;
738
743
  }
744
+ /**
745
+ * Extract yield information from JSDoc for generator methods
746
+ * Supports @yields tags with id, type, and description
747
+ * Example: @yields {pairing_code} text Enter the 6-digit code shown on TV
748
+ */
749
+ extractYieldsFromJSDoc(jsdocContent) {
750
+ const yields = [];
751
+ // Match @yields {id} type description
752
+ const yieldRegex = /@yields?\s+\{(\w+)\}\s+(prompt|confirm|select)\s+(.+)/gi;
753
+ let match;
754
+ while ((match = yieldRegex.exec(jsdocContent)) !== null) {
755
+ const [, id, type, description] = match;
756
+ yields.push({
757
+ id,
758
+ type: type.toLowerCase(),
759
+ prompt: description.trim(),
760
+ });
761
+ }
762
+ return yields;
763
+ }
739
764
  }
740
765
  //# sourceMappingURL=schema-extractor.js.map