@pupt/react 0.0.1 → 1.2.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,922 @@
1
+ import { CHILDREN } from '@pupt/lib';
2
+ import { Component } from '@pupt/lib';
3
+ import { COMPONENT_MARKER } from '@pupt/lib';
4
+ import { Context } from 'react';
5
+ import { createRuntimeConfig } from '@pupt/lib';
6
+ import { DEFERRED_REF } from '@pupt/lib';
7
+ import { DeferredRef } from '@pupt/lib';
8
+ import { DiscoveredPromptWithMethods } from '@pupt/lib';
9
+ import { EnvironmentContext } from '@pupt/lib';
10
+ import { evaluateFormula } from '@pupt/lib';
11
+ import { InputRequirement } from '@pupt/lib';
12
+ import { isComponentClass } from '@pupt/lib';
13
+ import { isDeferredRef } from '@pupt/lib';
14
+ import { isPuptElement } from '@pupt/lib';
15
+ import { ModuleEntry } from '@pupt/lib';
16
+ import { OnMissingDefaultStrategy } from '@pupt/lib';
17
+ import { PostExecutionAction } from '@pupt/lib';
18
+ import { PROPS } from '@pupt/lib';
19
+ import { PuptElement } from '@pupt/lib';
20
+ import { PuptInitConfig } from '@pupt/lib';
21
+ import { PuptNode } from '@pupt/lib';
22
+ import { RenderError } from '@pupt/lib';
23
+ import { RenderOptions } from '@pupt/lib';
24
+ import { RenderResult } from '@pupt/lib';
25
+ import { RuntimeConfig } from '@pupt/lib';
26
+ import { SearchablePrompt } from '@pupt/lib';
27
+ import { SearchEngine } from '@pupt/lib';
28
+ import { SearchEngineConfig } from '@pupt/lib';
29
+ import { SearchOptions } from '@pupt/lib';
30
+ import { SearchResult } from '@pupt/lib';
31
+ import { TYPE } from '@pupt/lib';
32
+ import { ValidationResult } from '@pupt/lib';
33
+
34
+ /**
35
+ * Headless component for collecting user input through Ask components.
36
+ *
37
+ * Wraps the useAskIterator hook and adds getInputProps for generating
38
+ * accessible input element props.
39
+ *
40
+ * @example
41
+ * ```tsx
42
+ * <AskHandler element={element} onComplete={(values) => console.log(values)}>
43
+ * {({ current, submit, progress, getInputProps }) => {
44
+ * if (!current) return <div>Loading...</div>;
45
+ * const { inputProps } = getInputProps(current.name);
46
+ * return (
47
+ * <div>
48
+ * <label>{current.label}</label>
49
+ * <input {...inputProps} />
50
+ * <span>{progress}% complete</span>
51
+ * </div>
52
+ * );
53
+ * }}
54
+ * </AskHandler>
55
+ * ```
56
+ */
57
+ export declare function AskHandler({ children, element, onComplete, initialValues }: AskHandlerProps): React.ReactElement;
58
+
59
+ /**
60
+ * Props for AskHandler component
61
+ */
62
+ export declare interface AskHandlerProps {
63
+ /** Render function receiving handler state */
64
+ children: (props: AskHandlerRenderProps) => React.ReactNode;
65
+ /** The PuptElement containing Ask components */
66
+ element: PuptElement | null;
67
+ /** Called when all inputs have been collected */
68
+ onComplete?: (values: Map<string, unknown>) => void;
69
+ /** Pre-supplied initial values */
70
+ initialValues?: Map<string, unknown>;
71
+ }
72
+
73
+ /**
74
+ * Render props provided by AskHandler
75
+ */
76
+ export declare interface AskHandlerRenderProps {
77
+ /** All input requirements */
78
+ requirements: InputRequirement[];
79
+ /** The current input requirement being collected */
80
+ current: InputRequirement | null;
81
+ /** Current step index */
82
+ currentIndex: number;
83
+ /** Total number of inputs */
84
+ totalInputs: number;
85
+ /** Progress as a percentage (0-100) */
86
+ progress: number;
87
+ /** Whether all inputs have been collected */
88
+ isDone: boolean;
89
+ /** Whether the handler is initializing */
90
+ isLoading: boolean;
91
+ /** All collected values */
92
+ values: Map<string, unknown>;
93
+ /** Submit a value for the current input */
94
+ submit: (value: unknown) => Promise<ValidationResult>;
95
+ /** Go to the previous input */
96
+ previous: () => void;
97
+ /** Go to a specific input by index */
98
+ goTo: (index: number) => void;
99
+ /** Reset all inputs */
100
+ reset: () => void;
101
+ /** Get input props for a specific field by name */
102
+ getInputProps: (name: string) => AskInputProps;
103
+ }
104
+
105
+ /**
106
+ * Input props helper returned by AskHandler.getInputProps
107
+ */
108
+ export declare interface AskInputProps {
109
+ /** Props to spread onto an input element */
110
+ inputProps: {
111
+ id: string;
112
+ name: string;
113
+ type: string;
114
+ required: boolean;
115
+ "aria-label": string;
116
+ };
117
+ /** The input requirement metadata */
118
+ requirement: InputRequirement;
119
+ /** The current value for this input */
120
+ value: unknown;
121
+ /** Set the value for this input */
122
+ setValue: (value: unknown) => void;
123
+ /** Validation errors for this input */
124
+ errors: string[];
125
+ }
126
+
127
+ export { CHILDREN }
128
+
129
+ export { Component }
130
+
131
+ export { COMPONENT_MARKER }
132
+
133
+ export { createRuntimeConfig }
134
+
135
+ export { DEFERRED_REF }
136
+
137
+ export { DeferredRef }
138
+
139
+ export { DiscoveredPromptWithMethods }
140
+
141
+ export { EnvironmentContext }
142
+
143
+ export { evaluateFormula }
144
+
145
+ /**
146
+ * Extract input requirements from a PuptElement by traversing its tree
147
+ * and finding Ask components.
148
+ *
149
+ * Uses createInputIterator with validation disabled, submitting placeholder
150
+ * values to advance through all requirements.
151
+ *
152
+ * @param element - The PuptElement to extract requirements from
153
+ * @param options - Optional configuration including pre-supplied values
154
+ * @returns Array of InputRequirement objects
155
+ */
156
+ export declare function extractInputRequirements(element: PuptElement, options?: ExtractOptions): Promise<InputRequirement[]>;
157
+
158
+ /**
159
+ * Options for extractInputRequirements
160
+ */
161
+ declare interface ExtractOptions {
162
+ /** Pre-supply values to skip during iteration */
163
+ values?: Record<string, unknown>;
164
+ }
165
+
166
+ export { InputRequirement }
167
+
168
+ /**
169
+ * Check if a PuptElement type represents an Ask component
170
+ */
171
+ export declare function isAskComponent(type: string | symbol): boolean;
172
+
173
+ export { isComponentClass }
174
+
175
+ export { isDeferredRef }
176
+
177
+ /**
178
+ * Type guard to check if a value is a PuptElement
179
+ */
180
+ export declare function isElement(value: unknown): value is PuptElement;
181
+
182
+ export { isPuptElement }
183
+
184
+ export { OnMissingDefaultStrategy }
185
+
186
+ /**
187
+ * Handler function for a post-execution action
188
+ */
189
+ export declare type PostActionHandler = (action: PostExecutionAction) => void | Promise<void>;
190
+
191
+ export { PostExecutionAction }
192
+
193
+ /**
194
+ * Headless component that provides state and props for a prompt source editor.
195
+ *
196
+ * Uses the render-prop pattern to give consumers full control over the UI
197
+ * while managing source value state and transformation.
198
+ *
199
+ * @example
200
+ * ```tsx
201
+ * <PromptEditor defaultValue="<Prompt>Hello</Prompt>">
202
+ * {({ inputProps, error, isTransforming }) => (
203
+ * <div>
204
+ * <textarea {...inputProps} />
205
+ * {isTransforming && <span>Transforming...</span>}
206
+ * {error && <span>{error.message}</span>}
207
+ * </div>
208
+ * )}
209
+ * </PromptEditor>
210
+ * ```
211
+ */
212
+ export declare function PromptEditor({ children, defaultValue, onChange, debounce, }: PromptEditorProps): React.ReactElement;
213
+
214
+ /**
215
+ * Props for PromptEditor component
216
+ */
217
+ export declare interface PromptEditorProps {
218
+ /** Render function receiving editor state */
219
+ children: (props: PromptEditorRenderProps) => React.ReactNode;
220
+ /** Default source value */
221
+ defaultValue?: string;
222
+ /** Called when the source value changes */
223
+ onChange?: (value: string) => void;
224
+ /** Debounce delay for transformation in ms (default: 300) */
225
+ debounce?: number;
226
+ }
227
+
228
+ /**
229
+ * Render props provided by PromptEditor
230
+ */
231
+ export declare interface PromptEditorRenderProps {
232
+ /** Props to spread onto the textarea/input element */
233
+ inputProps: {
234
+ value: string;
235
+ onChange: (e: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => void;
236
+ };
237
+ /** The current source value */
238
+ value: string;
239
+ /** Set the source value directly */
240
+ setValue: (value: string) => void;
241
+ /** The transformed PuptElement (null if transformation failed or pending) */
242
+ element: PuptElement | null;
243
+ /** Transformation error */
244
+ error: Error | null;
245
+ /** Whether transformation is in progress */
246
+ isTransforming: boolean;
247
+ }
248
+
249
+ /**
250
+ * Headless component that renders a prompt and provides the result via render props.
251
+ *
252
+ * Wraps the usePromptRender hook and adds clipboard copy functionality.
253
+ *
254
+ * @example
255
+ * ```tsx
256
+ * <PromptRenderer source="<Prompt><Task>Hello</Task></Prompt>" autoRender>
257
+ * {({ output, copyToClipboard, isCopied }) => (
258
+ * <div>
259
+ * <pre>{output}</pre>
260
+ * <button onClick={copyToClipboard}>
261
+ * {isCopied ? 'Copied!' : 'Copy'}
262
+ * </button>
263
+ * </div>
264
+ * )}
265
+ * </PromptRenderer>
266
+ * ```
267
+ */
268
+ export declare function PromptRenderer({ children, source, autoRender, inputs, renderOptions, environment, filename, }: PromptRendererProps): React.ReactElement;
269
+
270
+ /**
271
+ * Props for PromptRenderer component
272
+ */
273
+ export declare interface PromptRendererProps {
274
+ /** Render function receiving renderer state */
275
+ children: (props: PromptRendererRenderProps) => React.ReactNode;
276
+ /** Prompt source (string or element) */
277
+ source: PromptSource | string;
278
+ /** Whether to automatically render when source changes (default: true) */
279
+ autoRender?: boolean;
280
+ /** Input values for Ask components */
281
+ inputs?: Map<string, unknown>;
282
+ /** Render options */
283
+ renderOptions?: Partial<RenderOptions>;
284
+ /** Environment context */
285
+ environment?: Partial<EnvironmentContext>;
286
+ /** Filename hint for source transformation (e.g. "prompt.prompt" or "prompt.tsx").
287
+ * Controls whether pupt-lib auto-injects imports for built-in components.
288
+ * Defaults to "prompt.tsx". Use "prompt.prompt" for raw JSX without imports. */
289
+ filename?: string;
290
+ }
291
+
292
+ /**
293
+ * Render props provided by PromptRenderer
294
+ */
295
+ export declare interface PromptRendererRenderProps {
296
+ /** The rendered text output */
297
+ output: string | null;
298
+ /** Whether the prompt is ready (has output and no pending inputs) */
299
+ isReady: boolean;
300
+ /** Whether rendering is in progress */
301
+ isLoading: boolean;
302
+ /** Rendering error */
303
+ error: Error | null;
304
+ /** Input requirements from Ask components */
305
+ pendingInputs: InputRequirement[];
306
+ /** Post-execution actions from the rendered prompt */
307
+ postActions: PostExecutionAction[];
308
+ /** Copy the rendered output to the clipboard */
309
+ copyToClipboard: () => Promise<void>;
310
+ /** Whether the output was recently copied */
311
+ isCopied: boolean;
312
+ /** Manually trigger a re-render */
313
+ render: () => Promise<void>;
314
+ }
315
+
316
+ /**
317
+ * Source for prompt rendering - either raw source code or pre-parsed element
318
+ */
319
+ export declare type PromptSource = {
320
+ type: "source";
321
+ value: string;
322
+ } | {
323
+ type: "element";
324
+ value: PuptElement;
325
+ };
326
+
327
+ export { PROPS }
328
+
329
+ /**
330
+ * React context for pupt-lib functionality
331
+ *
332
+ * Provides access to:
333
+ * - SearchEngine for prompt searching
334
+ * - Default render options
335
+ * - Environment context
336
+ *
337
+ * @example
338
+ * ```tsx
339
+ * import { useContext } from 'react';
340
+ * import { PuptContext } from '@pupt/react';
341
+ *
342
+ * function MyComponent() {
343
+ * const { searchEngine, isLoading, error } = useContext(PuptContext);
344
+ * // ...
345
+ * }
346
+ * ```
347
+ */
348
+ export declare const PuptContext: Context<PuptContextValue>;
349
+
350
+ /**
351
+ * Value provided by PuptContext
352
+ */
353
+ export declare interface PuptContextValue {
354
+ /** Internal marker indicating provider is present (not exposed to consumers) */
355
+ _initialized: boolean;
356
+ /** Search engine for finding prompts (null if no prompts provided) */
357
+ searchEngine: SearchEngine | null;
358
+ /** All indexed prompts (empty array if no prompts provided) */
359
+ prompts: SearchablePrompt[];
360
+ /** Default render options */
361
+ renderOptions: Partial<RenderOptions>;
362
+ /** Environment context */
363
+ environment: Partial<EnvironmentContext>;
364
+ /** Loading state during initialization */
365
+ isLoading: boolean;
366
+ /** Error state if initialization failed */
367
+ error: Error | null;
368
+ }
369
+
370
+ export { PuptElement }
371
+
372
+ export { PuptInitConfig }
373
+
374
+ /**
375
+ * Context value for PuptLibraryProvider
376
+ */
377
+ export declare const PuptLibraryContext: Context<UsePuptLibraryReturn | null>;
378
+
379
+ /**
380
+ * Provider component that wraps usePuptLibrary and provides library state via context.
381
+ *
382
+ * @example
383
+ * ```tsx
384
+ * <PuptLibraryProvider modules={["@my-org/prompts"]}>
385
+ * <MyApp />
386
+ * </PuptLibraryProvider>
387
+ * ```
388
+ */
389
+ export declare function PuptLibraryProvider({ children, modules, searchConfig }: PuptLibraryProviderProps): React.ReactElement;
390
+
391
+ /**
392
+ * Props for PuptLibraryProvider
393
+ */
394
+ declare interface PuptLibraryProviderProps extends UsePuptLibraryOptions {
395
+ children: React.ReactNode;
396
+ }
397
+
398
+ export { PuptNode }
399
+
400
+ /**
401
+ * Provider component that initializes pupt-lib and provides context to children
402
+ *
403
+ * @example
404
+ * ```tsx
405
+ * import { PuptProvider } from '@pupt/react';
406
+ *
407
+ * function App() {
408
+ * return (
409
+ * <PuptProvider>
410
+ * <MyComponent />
411
+ * </PuptProvider>
412
+ * );
413
+ * }
414
+ * ```
415
+ *
416
+ * @example
417
+ * With prompts for search:
418
+ * ```tsx
419
+ * const prompts = [
420
+ * { name: 'greeting', description: 'A greeting prompt', tags: ['hello'] }
421
+ * ];
422
+ *
423
+ * function App() {
424
+ * return (
425
+ * <PuptProvider prompts={prompts}>
426
+ * <MyComponent />
427
+ * </PuptProvider>
428
+ * );
429
+ * }
430
+ * ```
431
+ */
432
+ export declare function PuptProvider({ children, prompts, searchConfig, renderOptions, environment, }: PuptProviderProps): React.ReactElement;
433
+
434
+ /**
435
+ * Props for PuptProvider component
436
+ */
437
+ export declare interface PuptProviderProps {
438
+ /** Child components */
439
+ children: React.ReactNode;
440
+ /** Initial prompts to index for search */
441
+ prompts?: SearchablePrompt[];
442
+ /** Configuration for the search engine (threshold, weights, fuzzy matching, etc.) */
443
+ searchConfig?: SearchEngineConfig;
444
+ /** Default render options to use for all renders */
445
+ renderOptions?: Partial<RenderOptions>;
446
+ /** Environment context */
447
+ environment?: Partial<EnvironmentContext>;
448
+ }
449
+
450
+ export { RenderOptions }
451
+
452
+ export { RenderResult }
453
+
454
+ export { RuntimeConfig }
455
+
456
+ export { SearchablePrompt }
457
+
458
+ export { SearchEngineConfig }
459
+
460
+ export { SearchOptions }
461
+
462
+ export { SearchResult }
463
+
464
+ /**
465
+ * Options for transformSource function
466
+ */
467
+ declare interface TransformOptions {
468
+ /** Filename for error messages (default: "prompt.tsx") */
469
+ filename?: string;
470
+ }
471
+
472
+ /**
473
+ * Transform source code string into a PuptElement.
474
+ * Delegates to pupt-lib's createPromptFromSource.
475
+ *
476
+ * @param source - TSX/JSX source code (should export default a PuptElement)
477
+ * @param options - Transform options including filename
478
+ * @returns Promise resolving to the transformed PuptElement
479
+ */
480
+ export declare function transformSource(source: string, options?: TransformOptions): Promise<PuptElement>;
481
+
482
+ /**
483
+ * Recursively traverse a PuptElement tree and call a visitor function
484
+ * for each element.
485
+ */
486
+ export declare function traverseElement(element: PuptElement, visitor: (element: PuptElement) => void): void;
487
+
488
+ export { TYPE }
489
+
490
+ /**
491
+ * Hook for iterating through Ask components in a PuptElement and collecting
492
+ * validated user input.
493
+ *
494
+ * Provides a wizard-like interface for stepping through input requirements,
495
+ * validating submissions, and navigating back to previous inputs.
496
+ *
497
+ * @param options - Configuration including the element to iterate and callbacks
498
+ * @returns Object containing current state, navigation, and submission functions
499
+ *
500
+ * @example
501
+ * ```tsx
502
+ * function InputCollector({ element }) {
503
+ * const { current, submit, isDone, inputs } = useAskIterator({ element });
504
+ *
505
+ * if (isDone) return <div>All inputs collected!</div>;
506
+ * if (!current) return <div>Loading...</div>;
507
+ *
508
+ * return (
509
+ * <div>
510
+ * <label>{current.label}</label>
511
+ * <input onKeyDown={(e) => {
512
+ * if (e.key === 'Enter') submit(e.currentTarget.value);
513
+ * }} />
514
+ * </div>
515
+ * );
516
+ * }
517
+ * ```
518
+ */
519
+ export declare function useAskIterator(options: UseAskIteratorOptions): UseAskIteratorReturn;
520
+
521
+ /**
522
+ * Options for useAskIterator hook
523
+ */
524
+ export declare interface UseAskIteratorOptions {
525
+ /** The PuptElement to extract Ask components from */
526
+ element: PuptElement | null;
527
+ /** Callback when all inputs have been collected */
528
+ onComplete?: (values: Map<string, unknown>) => void;
529
+ /** Pre-supplied initial values for inputs */
530
+ initialValues?: Map<string, unknown>;
531
+ /** Pre-supply values that skip interactive iteration */
532
+ preSuppliedValues?: Record<string, unknown>;
533
+ /** Enable non-interactive mode to auto-fill with defaults */
534
+ nonInteractive?: boolean;
535
+ /** Strategy when required input has no default in non-interactive mode */
536
+ onMissingDefault?: OnMissingDefaultStrategy;
537
+ }
538
+
539
+ /**
540
+ * Return value of useAskIterator hook
541
+ */
542
+ export declare interface UseAskIteratorReturn {
543
+ /** All input requirements extracted from the element */
544
+ requirements: InputRequirement[];
545
+ /** The current input requirement being collected */
546
+ current: InputRequirement | null;
547
+ /** Index of the current requirement */
548
+ currentIndex: number;
549
+ /** Total number of input requirements */
550
+ totalInputs: number;
551
+ /** Whether all inputs have been collected */
552
+ isDone: boolean;
553
+ /** Whether the iterator is initializing */
554
+ isLoading: boolean;
555
+ /** All collected input values */
556
+ inputs: Map<string, unknown>;
557
+ /** Submit a value for the current input, returns validation result */
558
+ submit: (value: unknown) => Promise<ValidationResult>;
559
+ /** Navigate to the previous input */
560
+ previous: () => void;
561
+ /** Navigate to a specific input index */
562
+ goTo: (index: number) => void;
563
+ /** Reset all collected inputs and go back to the first */
564
+ reset: () => void;
565
+ /** Set a value for a specific input by name */
566
+ setValue: (name: string, value: unknown) => void;
567
+ /** Get the value for a specific input by name */
568
+ getValue: (name: string) => unknown;
569
+ /** Run all inputs non-interactively using defaults and pre-supplied values */
570
+ runNonInteractive: () => Promise<Map<string, unknown>>;
571
+ }
572
+
573
+ /**
574
+ * Hook for evaluating Excel-style formulas reactively against input values.
575
+ *
576
+ * Re-evaluates automatically when the formula string or inputs Map changes.
577
+ *
578
+ * @param options - Formula string and input values
579
+ * @returns Object containing the boolean result and any evaluation error
580
+ *
581
+ * @example
582
+ * ```tsx
583
+ * function ConditionalSection({ inputs }) {
584
+ * const { result } = useFormula({
585
+ * formula: "=count>5",
586
+ * inputs,
587
+ * });
588
+ *
589
+ * if (!result) return null;
590
+ * return <div>Count exceeds threshold!</div>;
591
+ * }
592
+ * ```
593
+ */
594
+ export declare function useFormula(options: UseFormulaOptions): UseFormulaReturn;
595
+
596
+ /**
597
+ * Options for useFormula hook
598
+ */
599
+ export declare interface UseFormulaOptions {
600
+ /** Formula string (e.g., "=count>5", "=AND(a>1, b<10)") */
601
+ formula: string;
602
+ /** Input values for formula variables */
603
+ inputs: Map<string, unknown>;
604
+ }
605
+
606
+ /**
607
+ * Return value of useFormula hook
608
+ */
609
+ export declare interface UseFormulaReturn {
610
+ /** Boolean result of formula evaluation */
611
+ result: boolean;
612
+ /** Error if evaluation failed */
613
+ error: Error | null;
614
+ }
615
+
616
+ /**
617
+ * Hook for managing post-execution actions extracted from rendered prompts.
618
+ *
619
+ * Tracks pending, executed, and dismissed actions. Supports custom handlers
620
+ * per action type and bulk operations.
621
+ *
622
+ * @param options - Configuration including actions and optional handlers
623
+ * @returns Object containing action lists and control functions
624
+ *
625
+ * @example
626
+ * ```tsx
627
+ * function PostActions({ actions }) {
628
+ * const { pendingActions, execute, dismiss, allDone } = usePostActions({
629
+ * actions,
630
+ * handlers: {
631
+ * openUrl: (action) => window.open(action.url),
632
+ * },
633
+ * });
634
+ *
635
+ * if (allDone) return <div>All actions handled!</div>;
636
+ *
637
+ * return (
638
+ * <ul>
639
+ * {pendingActions.map((action, i) => (
640
+ * <li key={i}>
641
+ * {action.type}
642
+ * <button onClick={() => execute(action)}>Execute</button>
643
+ * <button onClick={() => dismiss(action)}>Dismiss</button>
644
+ * </li>
645
+ * ))}
646
+ * </ul>
647
+ * );
648
+ * }
649
+ * ```
650
+ */
651
+ export declare function usePostActions(options: UsePostActionsOptions): UsePostActionsReturn;
652
+
653
+ /**
654
+ * Options for usePostActions hook
655
+ */
656
+ export declare interface UsePostActionsOptions {
657
+ /** Post-execution actions to manage */
658
+ actions: PostExecutionAction[];
659
+ /** Custom handlers by action type */
660
+ handlers?: Partial<Record<PostExecutionAction["type"], PostActionHandler>>;
661
+ }
662
+
663
+ /**
664
+ * Return value of usePostActions hook
665
+ */
666
+ export declare interface UsePostActionsReturn {
667
+ /** Actions that have not yet been executed or dismissed */
668
+ pendingActions: PostExecutionAction[];
669
+ /** Actions that have been executed */
670
+ executedActions: PostExecutionAction[];
671
+ /** Actions that have been dismissed */
672
+ dismissedActions: PostExecutionAction[];
673
+ /** Whether all actions have been handled (executed or dismissed) */
674
+ allDone: boolean;
675
+ /** Execute a specific action */
676
+ execute: (action: PostExecutionAction) => Promise<void>;
677
+ /** Dismiss a specific action without executing */
678
+ dismiss: (action: PostExecutionAction) => void;
679
+ /** Execute all remaining pending actions */
680
+ executeAll: () => Promise<void>;
681
+ /** Dismiss all remaining pending actions */
682
+ dismissAll: () => void;
683
+ /** Reset all actions back to pending */
684
+ reset: () => void;
685
+ }
686
+
687
+ /**
688
+ * Hook for transforming JSX/prompt source into rendered text output.
689
+ *
690
+ * Provides functionality to:
691
+ * - Transform source code strings into PuptElement trees
692
+ * - Render elements to text output
693
+ * - Extract input requirements from Ask components
694
+ * - Track loading and error states
695
+ *
696
+ * @param options - Configuration options for the hook
697
+ * @returns Object containing element, output, loading states, and control functions
698
+ *
699
+ * @example
700
+ * ```tsx
701
+ * function PromptDemo() {
702
+ * const { output, error, isLoading } = usePromptRender({
703
+ * source: { type: 'source', value: '<Prompt><Task>Hello</Task></Prompt>' },
704
+ * autoRender: true,
705
+ * });
706
+ *
707
+ * if (isLoading) return <div>Loading...</div>;
708
+ * if (error) return <div>Error: {error.message}</div>;
709
+ * return <pre>{output}</pre>;
710
+ * }
711
+ * ```
712
+ */
713
+ export declare function usePromptRender(options?: UsePromptRenderOptions): UsePromptRenderReturn;
714
+
715
+ /**
716
+ * Options for usePromptRender hook
717
+ */
718
+ export declare interface UsePromptRenderOptions {
719
+ /** Initial source to transform/render */
720
+ source?: PromptSource;
721
+ /** Input values to pass to the prompt during rendering */
722
+ inputs?: Map<string, unknown>;
723
+ /** Environment context for rendering */
724
+ environment?: Partial<EnvironmentContext>;
725
+ /** Render options to pass to pupt-lib */
726
+ renderOptions?: Partial<RenderOptions>;
727
+ /** Whether to automatically render after transformation (default: false) */
728
+ autoRender?: boolean;
729
+ /** Filename hint for source transformation (e.g. "prompt.prompt" or "prompt.tsx").
730
+ * Controls whether pupt-lib auto-injects imports for built-in components.
731
+ * Defaults to "prompt.tsx". Use "prompt.prompt" for raw JSX without imports. */
732
+ filename?: string;
733
+ }
734
+
735
+ /**
736
+ * Return value of usePromptRender hook
737
+ */
738
+ export declare interface UsePromptRenderReturn {
739
+ /** Current source being rendered */
740
+ source: PromptSource | null;
741
+ /** Set a new source to transform */
742
+ setSource: (source: PromptSource) => void;
743
+ /** The transformed PuptElement */
744
+ element: PuptElement | null;
745
+ /** The rendered text output */
746
+ output: string | null;
747
+ /** Error that occurred during transformation or rendering */
748
+ error: Error | null;
749
+ /** Detailed render errors from component validation/runtime failures */
750
+ renderErrors: RenderError[];
751
+ /** Whether transformation is in progress */
752
+ isTransforming: boolean;
753
+ /** Whether rendering is in progress */
754
+ isRendering: boolean;
755
+ /** Combined loading state (transforming or rendering) */
756
+ isLoading: boolean;
757
+ /** Input requirements extracted from Ask components */
758
+ inputRequirements: InputRequirement[];
759
+ /** Post-execution actions extracted from the prompt */
760
+ postActions: PostExecutionAction[];
761
+ /** Manually trigger rendering with current element and inputs */
762
+ render: () => Promise<void>;
763
+ /** Manually trigger transformation of source code */
764
+ transform: (sourceCode?: string) => Promise<PuptElement | null>;
765
+ }
766
+
767
+ /**
768
+ * Hook for searching through prompts indexed in the PuptProvider.
769
+ *
770
+ * Uses the search engine from PuptContext and provides debounced searching
771
+ * with query state management.
772
+ *
773
+ * @param options - Configuration including debounce delay and result limit
774
+ * @returns Object containing query state, results, and search controls
775
+ *
776
+ * @example
777
+ * ```tsx
778
+ * function SearchBar() {
779
+ * const { query, setQuery, results, isSearching } = usePromptSearch();
780
+ *
781
+ * return (
782
+ * <div>
783
+ * <input value={query} onChange={e => setQuery(e.target.value)} />
784
+ * {isSearching && <span>Searching...</span>}
785
+ * <ul>{results.map(r => <li key={r.prompt.name}>{r.prompt.name}</li>)}</ul>
786
+ * </div>
787
+ * );
788
+ * }
789
+ * ```
790
+ */
791
+ export declare function usePromptSearch(options?: UsePromptSearchOptions): UsePromptSearchReturn;
792
+
793
+ /**
794
+ * Options for usePromptSearch hook
795
+ */
796
+ export declare interface UsePromptSearchOptions {
797
+ /** Debounce delay in milliseconds (default: 200) */
798
+ debounce?: number;
799
+ /** Maximum number of results to return */
800
+ limit?: number;
801
+ }
802
+
803
+ /**
804
+ * Return value of usePromptSearch hook
805
+ */
806
+ export declare interface UsePromptSearchReturn {
807
+ /** Current search query */
808
+ query: string;
809
+ /** Set the search query */
810
+ setQuery: (query: string) => void;
811
+ /** Search results */
812
+ results: SearchResult[];
813
+ /** Whether a search is in progress */
814
+ isSearching: boolean;
815
+ /** All available tags from indexed prompts */
816
+ allTags: string[];
817
+ /** Clear the search query and results */
818
+ clear: () => void;
819
+ }
820
+
821
+ /**
822
+ * Hook to access the pupt-lib context
823
+ *
824
+ * Must be used within a PuptProvider component.
825
+ * Throws an error if used outside of provider.
826
+ *
827
+ * @returns The pupt context value containing searchEngine, renderOptions, etc.
828
+ *
829
+ * @example
830
+ * ```tsx
831
+ * function MyComponent() {
832
+ * const { searchEngine, isLoading, error } = usePupt();
833
+ *
834
+ * if (isLoading) return <div>Loading...</div>;
835
+ * if (error) return <div>Error: {error.message}</div>;
836
+ *
837
+ * // Use searchEngine for finding prompts...
838
+ * }
839
+ * ```
840
+ *
841
+ * @throws {Error} When used outside of PuptProvider
842
+ */
843
+ export declare function usePupt(): PuptContextValue;
844
+
845
+ /**
846
+ * Hook that wraps the Pupt class with React state management.
847
+ *
848
+ * Creates a Pupt instance, loads modules, and exposes discovered prompts.
849
+ * Re-initializes when the modules list changes.
850
+ *
851
+ * @example
852
+ * ```tsx
853
+ * const { prompts, isLoading, addModule } = usePuptLibrary({
854
+ * modules: ["@my-org/prompts"],
855
+ * });
856
+ * ```
857
+ */
858
+ export declare function usePuptLibrary(options?: UsePuptLibraryOptions): UsePuptLibraryReturn;
859
+
860
+ /**
861
+ * Hook to access the PuptLibraryProvider context.
862
+ *
863
+ * Must be used within a PuptLibraryProvider.
864
+ *
865
+ * @example
866
+ * ```tsx
867
+ * function MyComponent() {
868
+ * const { prompts, addModule, isLoading } = usePuptLibraryContext();
869
+ * // ...
870
+ * }
871
+ * ```
872
+ */
873
+ export declare function usePuptLibraryContext(): UsePuptLibraryReturn;
874
+
875
+ /**
876
+ * Options for usePuptLibrary hook
877
+ */
878
+ export declare interface UsePuptLibraryOptions {
879
+ /** Module entries to load prompts from */
880
+ modules?: ModuleEntry[];
881
+ /** Configuration for the search engine */
882
+ searchConfig?: SearchEngineConfig;
883
+ }
884
+
885
+ /**
886
+ * Return value of usePuptLibrary hook
887
+ */
888
+ export declare interface UsePuptLibraryReturn {
889
+ /** Whether the library is loading/initializing */
890
+ isLoading: boolean;
891
+ /** Error that occurred during initialization */
892
+ error: Error | null;
893
+ /** All discovered prompts from loaded modules */
894
+ prompts: DiscoveredPromptWithMethods[];
895
+ /** All unique tags from discovered prompts */
896
+ tags: string[];
897
+ /** Get a specific prompt by name */
898
+ getPrompt: (name: string) => DiscoveredPromptWithMethods | undefined;
899
+ /** Get all prompts with a specific tag */
900
+ getPromptsByTag: (tag: string) => DiscoveredPromptWithMethods[];
901
+ /** Add a module entry */
902
+ addModule: (source: ModuleEntry) => void;
903
+ /** Remove a module entry */
904
+ removeModule: (source: ModuleEntry) => void;
905
+ /** Currently loaded module entries */
906
+ modules: ModuleEntry[];
907
+ }
908
+
909
+ /**
910
+ * Validate a value against an InputRequirement's constraints.
911
+ *
912
+ * @param requirement - The input requirement to validate against
913
+ * @param value - The value to validate
914
+ * @returns A ValidationResult indicating success or failure
915
+ */
916
+ export declare function validateInput(requirement: InputRequirement, value: unknown): ValidationResult;
917
+
918
+ export { ValidationResult }
919
+
920
+ export declare const VERSION = "1.0.0";
921
+
922
+ export { }