ai-props 2.3.0 → 2.4.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.
Files changed (75) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/CHANGELOG.md +9 -0
  3. package/dist/ai.d.ts +125 -0
  4. package/dist/ai.d.ts.map +1 -0
  5. package/dist/ai.js +199 -0
  6. package/dist/ai.js.map +1 -0
  7. package/dist/cache.d.ts +66 -0
  8. package/dist/cache.d.ts.map +1 -0
  9. package/dist/cache.js +183 -0
  10. package/dist/cache.js.map +1 -0
  11. package/dist/cascade.d.ts +329 -0
  12. package/dist/cascade.d.ts.map +1 -0
  13. package/dist/cascade.js +522 -0
  14. package/dist/cascade.js.map +1 -0
  15. package/dist/client.d.ts +233 -0
  16. package/dist/client.d.ts.map +1 -0
  17. package/dist/client.js +191 -0
  18. package/dist/client.js.map +1 -0
  19. package/dist/durable-cascade.d.ts +280 -0
  20. package/dist/durable-cascade.d.ts.map +1 -0
  21. package/dist/durable-cascade.js +469 -0
  22. package/dist/durable-cascade.js.map +1 -0
  23. package/dist/event-bridge.d.ts +257 -0
  24. package/dist/event-bridge.d.ts.map +1 -0
  25. package/dist/event-bridge.js +317 -0
  26. package/dist/event-bridge.js.map +1 -0
  27. package/dist/generate.d.ts +69 -0
  28. package/dist/generate.d.ts.map +1 -0
  29. package/dist/generate.js +227 -0
  30. package/dist/generate.js.map +1 -0
  31. package/dist/hoc.d.ts +164 -0
  32. package/dist/hoc.d.ts.map +1 -0
  33. package/dist/hoc.js +236 -0
  34. package/dist/hoc.js.map +1 -0
  35. package/dist/hono-jsx.d.ts +208 -0
  36. package/dist/hono-jsx.d.ts.map +1 -0
  37. package/dist/hono-jsx.js +459 -0
  38. package/dist/hono-jsx.js.map +1 -0
  39. package/dist/index.d.ts +16 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +23 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/mdx-types.d.ts +152 -0
  44. package/dist/mdx-types.d.ts.map +1 -0
  45. package/dist/mdx-types.js +9 -0
  46. package/dist/mdx-types.js.map +1 -0
  47. package/dist/mdx-utils.d.ts +106 -0
  48. package/dist/mdx-utils.d.ts.map +1 -0
  49. package/dist/mdx-utils.js +384 -0
  50. package/dist/mdx-utils.js.map +1 -0
  51. package/dist/mdx.d.ts +230 -0
  52. package/dist/mdx.d.ts.map +1 -0
  53. package/dist/mdx.js +820 -0
  54. package/dist/mdx.js.map +1 -0
  55. package/dist/rpc.d.ts +313 -0
  56. package/dist/rpc.d.ts.map +1 -0
  57. package/dist/rpc.js +359 -0
  58. package/dist/rpc.js.map +1 -0
  59. package/dist/streaming.d.ts +199 -0
  60. package/dist/streaming.d.ts.map +1 -0
  61. package/dist/streaming.js +402 -0
  62. package/dist/streaming.js.map +1 -0
  63. package/dist/types.d.ts +152 -0
  64. package/dist/types.d.ts.map +1 -0
  65. package/dist/types.js +7 -0
  66. package/dist/types.js.map +1 -0
  67. package/dist/validate.d.ts +58 -0
  68. package/dist/validate.d.ts.map +1 -0
  69. package/dist/validate.js +251 -0
  70. package/dist/validate.js.map +1 -0
  71. package/dist/worker.d.ts +270 -0
  72. package/dist/worker.d.ts.map +1 -0
  73. package/dist/worker.js +405 -0
  74. package/dist/worker.js.map +1 -0
  75. package/package.json +4 -4
@@ -0,0 +1,402 @@
1
+ /**
2
+ * Optimized streaming utilities for AI-powered props rendering
3
+ *
4
+ * This module provides high-performance streaming capabilities with:
5
+ * - Adaptive chunk sizing for network efficiency
6
+ * - Backpressure handling to prevent memory overflow
7
+ * - Progress callbacks for streaming status
8
+ * - Memory-efficient streaming for large components
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+ import { renderToReadableStream as baseRenderToReadableStream, streamJSXResponse as baseStreamJSXResponse, createStreamingRenderer as baseCreateStreamingRenderer, createHydrationContext, serializeHydrationData, } from './hono-jsx.js';
13
+ import { streamMDXWithProps as baseStreamMDXWithProps } from './mdx.js';
14
+ // ============================================================================
15
+ // Constants
16
+ // ============================================================================
17
+ /** Default chunk size for optimal network performance (16KB) */
18
+ export const DEFAULT_CHUNK_SIZE = 16 * 1024;
19
+ /** Minimum chunk size to avoid excessive overhead (1KB) */
20
+ export const MIN_CHUNK_SIZE = 1024;
21
+ /** Maximum chunk size for memory efficiency (64KB) */
22
+ export const MAX_CHUNK_SIZE = 64 * 1024;
23
+ /** High water mark for backpressure (64KB) */
24
+ export const DEFAULT_HIGH_WATER_MARK = 64 * 1024;
25
+ // ============================================================================
26
+ // Utility Functions
27
+ // ============================================================================
28
+ /**
29
+ * Calculate optimal chunk size based on content size
30
+ *
31
+ * @param contentLength - Total content length in bytes
32
+ * @returns Optimal chunk size
33
+ */
34
+ export function calculateOptimalChunkSize(contentLength) {
35
+ // For very small content, use minimum chunk size
36
+ if (contentLength < MIN_CHUNK_SIZE * 2) {
37
+ return MIN_CHUNK_SIZE;
38
+ }
39
+ // For medium content, use default
40
+ if (contentLength < MAX_CHUNK_SIZE * 4) {
41
+ return DEFAULT_CHUNK_SIZE;
42
+ }
43
+ // For large content, use larger chunks
44
+ return MAX_CHUNK_SIZE;
45
+ }
46
+ /**
47
+ * Create a progress tracker for streaming operations
48
+ */
49
+ function createProgressTracker(totalBytes, onProgress) {
50
+ const startTime = Date.now();
51
+ return {
52
+ startTime,
53
+ update(bytesProcessed, chunksProcessed, phase) {
54
+ if (!onProgress)
55
+ return;
56
+ const elapsedMs = Date.now() - startTime;
57
+ const progress = {
58
+ bytesProcessed,
59
+ chunksProcessed,
60
+ phase,
61
+ elapsedMs,
62
+ };
63
+ if (totalBytes !== undefined) {
64
+ progress.totalBytes = totalBytes;
65
+ progress.percentComplete = Math.min(100, (bytesProcessed / totalBytes) * 100);
66
+ }
67
+ onProgress(progress);
68
+ },
69
+ };
70
+ }
71
+ // ============================================================================
72
+ // Core Streaming Functions
73
+ // ============================================================================
74
+ /**
75
+ * Render a component to a ReadableStream with optimizations
76
+ *
77
+ * Features:
78
+ * - Adaptive chunk sizing based on content
79
+ * - Backpressure handling to prevent memory overflow
80
+ * - Progress callbacks for monitoring
81
+ * - Memory-efficient streaming for large content
82
+ *
83
+ * @param component - Component function to render
84
+ * @param props - Props to pass to component
85
+ * @param options - Optimized streaming options
86
+ * @returns ReadableStream of rendered HTML
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * const stream = await renderToReadableStream(
91
+ * MyComponent,
92
+ * { title: 'Hello' },
93
+ * {
94
+ * chunkSize: 8192,
95
+ * onProgress: (progress) => console.log(`${progress.percentComplete}% complete`),
96
+ * }
97
+ * )
98
+ * ```
99
+ */
100
+ export async function renderToReadableStream(component, props, options) {
101
+ const encoder = new TextEncoder();
102
+ const chunkSize = options?.chunkSize ?? DEFAULT_CHUNK_SIZE;
103
+ const highWaterMark = options?.highWaterMark ?? DEFAULT_HIGH_WATER_MARK;
104
+ // Create hydration context if needed
105
+ let hydrationContext = null;
106
+ if (options?.includeHydration) {
107
+ hydrationContext = createHydrationContext();
108
+ }
109
+ // Render the component
110
+ let content;
111
+ try {
112
+ content = await component(props);
113
+ }
114
+ catch (error) {
115
+ if (options?.onError && error instanceof Error) {
116
+ content = options.onError(error);
117
+ }
118
+ else {
119
+ throw error;
120
+ }
121
+ }
122
+ // Register for hydration
123
+ if (hydrationContext) {
124
+ const componentName = component.name || 'Anonymous';
125
+ hydrationContext.register(componentName, props);
126
+ }
127
+ // Prepare hydration script
128
+ let hydrationScript = '';
129
+ if (options?.includeHydration && hydrationContext) {
130
+ const hydrationData = hydrationContext.getData();
131
+ hydrationScript = `<script>window.__HYDRATION_DATA__=${serializeHydrationData(hydrationData)}</script>`;
132
+ }
133
+ const fullContent = content + hydrationScript;
134
+ const contentBytes = encoder.encode(fullContent);
135
+ const totalLength = contentBytes.length;
136
+ // Calculate optimal chunk size if not specified
137
+ const effectiveChunkSize = options?.chunkSize ?? calculateOptimalChunkSize(totalLength);
138
+ // Create progress tracker
139
+ const tracker = createProgressTracker(totalLength, options?.onProgress);
140
+ let bytesProcessed = 0;
141
+ let chunksProcessed = 0;
142
+ let offset = 0;
143
+ tracker.update(0, 0, 'starting');
144
+ return new ReadableStream({
145
+ pull(controller) {
146
+ // Check if we're done
147
+ if (offset >= totalLength) {
148
+ tracker.update(bytesProcessed, chunksProcessed, 'complete');
149
+ controller.close();
150
+ return;
151
+ }
152
+ // Calculate chunk end
153
+ const end = Math.min(offset + effectiveChunkSize, totalLength);
154
+ const chunk = contentBytes.slice(offset, end);
155
+ controller.enqueue(chunk);
156
+ bytesProcessed += chunk.length;
157
+ chunksProcessed++;
158
+ offset = end;
159
+ tracker.update(bytesProcessed, chunksProcessed, 'streaming');
160
+ },
161
+ cancel() {
162
+ tracker.update(bytesProcessed, chunksProcessed, 'error');
163
+ },
164
+ },
165
+ // Queuing strategy for backpressure
166
+ new ByteLengthQueuingStrategy({ highWaterMark }));
167
+ }
168
+ /**
169
+ * Create a streaming Response with optimizations
170
+ *
171
+ * @param component - Component function to render
172
+ * @param props - Props to pass to component
173
+ * @param options - Optimized streaming options
174
+ * @returns Response with streaming body
175
+ *
176
+ * @example
177
+ * ```ts
178
+ * // In a Hono/Worker handler
179
+ * export default {
180
+ * fetch(request, env) {
181
+ * return streamJSXResponse(
182
+ * PageComponent,
183
+ * { data: pageData },
184
+ * {
185
+ * streaming: true,
186
+ * compressionHint: true,
187
+ * }
188
+ * )
189
+ * }
190
+ * }
191
+ * ```
192
+ */
193
+ export async function streamJSXResponse(component, props, options) {
194
+ const stream = await renderToReadableStream(component, props, options);
195
+ const headers = new Headers({
196
+ 'Content-Type': 'text/html; charset=utf-8',
197
+ 'X-Content-Type-Options': 'nosniff',
198
+ ...options?.headers,
199
+ });
200
+ // Add streaming hints
201
+ if (options?.streaming) {
202
+ headers.set('Transfer-Encoding', 'chunked');
203
+ }
204
+ // Add compression hint
205
+ if (options?.compressionHint) {
206
+ headers.set('Vary', 'Accept-Encoding');
207
+ }
208
+ return new Response(stream, {
209
+ status: 200,
210
+ headers,
211
+ });
212
+ }
213
+ /**
214
+ * Create a reusable streaming renderer with configuration
215
+ *
216
+ * @param options - Renderer options with optimization controls
217
+ * @returns Streaming renderer instance with stats
218
+ *
219
+ * @example
220
+ * ```ts
221
+ * const renderer = createStreamingRenderer({
222
+ * doctype: '<!DOCTYPE html>',
223
+ * includeHydration: true,
224
+ * chunkSize: 8192,
225
+ * onProgress: (p) => console.log(p.phase),
226
+ * })
227
+ *
228
+ * const stream = await renderer.render(MyComponent, props)
229
+ * const stats = renderer.getStats()
230
+ * ```
231
+ */
232
+ export function createStreamingRenderer(options) {
233
+ const encoder = new TextEncoder();
234
+ const chunkSize = options.chunkSize ?? DEFAULT_CHUNK_SIZE;
235
+ const highWaterMark = options.highWaterMark ?? DEFAULT_HIGH_WATER_MARK;
236
+ // Stats tracking
237
+ let currentStats = null;
238
+ return {
239
+ async render(component, props) {
240
+ const startTime = Date.now();
241
+ let timeToFirstByte = 0;
242
+ let totalBytes = 0;
243
+ let totalChunks = 0;
244
+ let encounteredBackpressure = false;
245
+ // Create hydration context
246
+ const ctx = options.includeHydration ? createHydrationContext() : null;
247
+ // Render the component
248
+ const content = await component(props);
249
+ // Register for hydration data
250
+ if (ctx) {
251
+ const componentName = component.name || 'Anonymous';
252
+ ctx.register(componentName, props);
253
+ }
254
+ // Get hydration data
255
+ let hydrationJson = '';
256
+ if (options.includeHydration && ctx) {
257
+ hydrationJson = serializeHydrationData(ctx.getData());
258
+ }
259
+ // Apply shell wrapper if provided
260
+ let output;
261
+ if (options.shell) {
262
+ const hydrationScript = hydrationJson ? `window.__HYDRATION_DATA__=${hydrationJson}` : '';
263
+ output = options.shell(content, hydrationScript);
264
+ }
265
+ else {
266
+ output = content;
267
+ if (options.includeHydration && hydrationJson) {
268
+ output += `<script>window.__HYDRATION_DATA__=${hydrationJson}</script>`;
269
+ }
270
+ }
271
+ // Prepend doctype if provided
272
+ if (options.doctype) {
273
+ output = options.doctype + '\n' + output;
274
+ }
275
+ const contentBytes = encoder.encode(output);
276
+ const contentLength = contentBytes.length;
277
+ // Create progress tracker
278
+ const tracker = createProgressTracker(contentLength, options.onProgress);
279
+ tracker.update(0, 0, 'starting');
280
+ let offset = 0;
281
+ return new ReadableStream({
282
+ pull(controller) {
283
+ // Track time to first byte
284
+ if (totalChunks === 0) {
285
+ timeToFirstByte = Date.now() - startTime;
286
+ }
287
+ if (offset >= contentLength) {
288
+ // Finalize stats
289
+ currentStats = {
290
+ totalBytes,
291
+ totalChunks,
292
+ averageChunkSize: totalChunks > 0 ? totalBytes / totalChunks : 0,
293
+ timeToFirstByte,
294
+ totalDuration: Date.now() - startTime,
295
+ encounteredBackpressure,
296
+ };
297
+ tracker.update(totalBytes, totalChunks, 'complete');
298
+ controller.close();
299
+ return;
300
+ }
301
+ const end = Math.min(offset + chunkSize, contentLength);
302
+ const chunk = contentBytes.slice(offset, end);
303
+ controller.enqueue(chunk);
304
+ totalBytes += chunk.length;
305
+ totalChunks++;
306
+ offset = end;
307
+ tracker.update(totalBytes, totalChunks, 'streaming');
308
+ },
309
+ cancel() {
310
+ tracker.update(totalBytes, totalChunks, 'error');
311
+ },
312
+ }, new ByteLengthQueuingStrategy({ highWaterMark }));
313
+ },
314
+ getStats() {
315
+ return currentStats;
316
+ },
317
+ resetStats() {
318
+ currentStats = null;
319
+ },
320
+ };
321
+ }
322
+ /**
323
+ * Stream MDX content with AI-generated props and optimizations
324
+ *
325
+ * @param mdx - MDX content string
326
+ * @param props - Props for each component
327
+ * @param options - Stream options with optimizations
328
+ * @returns ReadableStream of rendered content
329
+ *
330
+ * @example
331
+ * ```ts
332
+ * const stream = await streamMDXWithProps(
333
+ * '<Hero title="Welcome" />',
334
+ * { Hero: { title: 'Welcome', subtitle: 'To the site' } },
335
+ * {
336
+ * chunkSize: 8192,
337
+ * onProgress: (p) => console.log(`${p.chunksProcessed} chunks sent`),
338
+ * }
339
+ * )
340
+ * ```
341
+ */
342
+ export async function streamMDXWithProps(mdx, props, options) {
343
+ // Get base stream from mdx module
344
+ const baseStream = await baseStreamMDXWithProps(mdx, props, options);
345
+ // If no optimization options, return base stream
346
+ if (!options?.chunkSize && !options?.highWaterMark && !options?.onProgress) {
347
+ return baseStream;
348
+ }
349
+ // Apply optimizations by re-chunking the stream
350
+ const reader = baseStream.getReader();
351
+ const encoder = new TextEncoder();
352
+ const chunkSize = options?.chunkSize ?? DEFAULT_CHUNK_SIZE;
353
+ const highWaterMark = options?.highWaterMark ?? DEFAULT_HIGH_WATER_MARK;
354
+ // Buffer for accumulating content
355
+ let buffer = new Uint8Array(0);
356
+ let bytesProcessed = 0;
357
+ let chunksProcessed = 0;
358
+ const tracker = createProgressTracker(undefined, options?.onProgress);
359
+ tracker.update(0, 0, 'starting');
360
+ return new ReadableStream({
361
+ async pull(controller) {
362
+ // Read from source stream
363
+ const { done, value } = await reader.read();
364
+ if (done) {
365
+ // Flush remaining buffer
366
+ if (buffer.length > 0) {
367
+ controller.enqueue(buffer);
368
+ bytesProcessed += buffer.length;
369
+ chunksProcessed++;
370
+ }
371
+ tracker.update(bytesProcessed, chunksProcessed, 'complete');
372
+ controller.close();
373
+ return;
374
+ }
375
+ // Append to buffer
376
+ const newBuffer = new Uint8Array(buffer.length + value.length);
377
+ newBuffer.set(buffer);
378
+ newBuffer.set(value, buffer.length);
379
+ buffer = newBuffer;
380
+ // Emit full chunks
381
+ while (buffer.length >= chunkSize) {
382
+ const chunk = buffer.slice(0, chunkSize);
383
+ controller.enqueue(chunk);
384
+ buffer = buffer.slice(chunkSize);
385
+ bytesProcessed += chunk.length;
386
+ chunksProcessed++;
387
+ tracker.update(bytesProcessed, chunksProcessed, 'streaming');
388
+ }
389
+ },
390
+ cancel() {
391
+ reader.cancel();
392
+ tracker.update(bytesProcessed, chunksProcessed, 'error');
393
+ },
394
+ }, new ByteLengthQueuingStrategy({ highWaterMark }));
395
+ }
396
+ // ============================================================================
397
+ // Re-exports from hono-jsx for convenience
398
+ // ============================================================================
399
+ export { createHydrationContext, serializeHydrationData, collectHydrationData, HydrationProvider, useHydration, } from './hono-jsx.js';
400
+ // Re-export base functions with different names for direct access
401
+ export { baseRenderToReadableStream as renderToReadableStreamBasic, baseStreamJSXResponse as streamJSXResponseBasic, baseCreateStreamingRenderer as createStreamingRendererBasic, };
402
+ //# sourceMappingURL=streaming.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streaming.js","sourceRoot":"","sources":["../src/streaming.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,sBAAsB,IAAI,0BAA0B,EACpD,iBAAiB,IAAI,qBAAqB,EAC1C,uBAAuB,IAAI,2BAA2B,EACtD,sBAAsB,EACtB,sBAAsB,GAMvB,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,kBAAkB,IAAI,sBAAsB,EAAyB,MAAM,UAAU,CAAA;AAE9F,+EAA+E;AAC/E,YAAY;AACZ,+EAA+E;AAE/E,gEAAgE;AAChE,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,CAAA;AAE3C,2DAA2D;AAC3D,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAA;AAElC,sDAAsD;AACtD,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,GAAG,IAAI,CAAA;AAEvC,8CAA8C;AAC9C,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,GAAG,IAAI,CAAA;AA6EhD,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAE/E;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAC,aAAqB;IAC7D,iDAAiD;IACjD,IAAI,aAAa,GAAG,cAAc,GAAG,CAAC,EAAE,CAAC;QACvC,OAAO,cAAc,CAAA;IACvB,CAAC;IAED,kCAAkC;IAClC,IAAI,aAAa,GAAG,cAAc,GAAG,CAAC,EAAE,CAAC;QACvC,OAAO,kBAAkB,CAAA;IAC3B,CAAC;IAED,uCAAuC;IACvC,OAAO,cAAc,CAAA;AACvB,CAAC;AAED;;GAEG;AACH,SAAS,qBAAqB,C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AM,eAAe,CAAA;AAEtB,kEAAkE;AAClE,OAAO,EACL,0BAA0B,IAAI,2BAA2B,EACzD,qBAAqB,IAAI,sBAAsB,EAC/C,2BAA2B,IAAI,4BAA4B,GAC5D,CAAA"}
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Type definitions for ai-props
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ import type { SimpleSchema } from 'ai-functions';
7
+ /**
8
+ * Configuration for AI prop generation
9
+ */
10
+ export interface AIPropsConfig {
11
+ /** Model to use for generation (default: 'sonnet') */
12
+ model?: string;
13
+ /** System prompt for generation context */
14
+ system?: string;
15
+ /** Whether to cache generated props */
16
+ cache?: boolean;
17
+ /** Cache TTL in milliseconds (default: 5 minutes) */
18
+ cacheTTL?: number;
19
+ /** Custom generation function */
20
+ generate?: <T>(schema: SimpleSchema, context: Record<string, unknown>) => Promise<T>;
21
+ }
22
+ /**
23
+ * Schema definition for component props
24
+ * Can be a SimpleSchema or a named type string
25
+ */
26
+ export type PropSchema = SimpleSchema | string;
27
+ /**
28
+ * Options for prop generation
29
+ */
30
+ export interface GeneratePropsOptions {
31
+ /** Schema defining the props to generate */
32
+ schema: PropSchema;
33
+ /** Partial props to use as context */
34
+ context?: Record<string, unknown>;
35
+ /** Additional prompt context */
36
+ prompt?: string;
37
+ /** Model to use */
38
+ model?: string;
39
+ /** System prompt */
40
+ system?: string;
41
+ }
42
+ /**
43
+ * Result of prop generation
44
+ */
45
+ export interface GeneratePropsResult<T> {
46
+ /** Generated props */
47
+ props: T;
48
+ /** Whether props were from cache */
49
+ cached: boolean;
50
+ /** Generation metadata */
51
+ metadata?: {
52
+ model: string;
53
+ tokens?: number;
54
+ duration?: number;
55
+ };
56
+ }
57
+ /**
58
+ * Cache entry for generated props
59
+ */
60
+ export interface PropsCacheEntry<T = unknown> {
61
+ props: T;
62
+ timestamp: number;
63
+ key: string;
64
+ }
65
+ /**
66
+ * Props cache interface
67
+ */
68
+ export interface PropsCache {
69
+ get<T>(key: string): PropsCacheEntry<T> | undefined;
70
+ set<T>(key: string, props: T): void;
71
+ delete(key: string): boolean;
72
+ clear(): void;
73
+ size: number;
74
+ }
75
+ /**
76
+ * Hook result for useAIProps
77
+ */
78
+ export interface UseAIPropsResult<T> {
79
+ /** Generated props (null while loading) */
80
+ props: T | null;
81
+ /** Whether generation is in progress */
82
+ loading: boolean;
83
+ /** Error if generation failed */
84
+ error: Error | null;
85
+ /** Regenerate props */
86
+ regenerate: () => Promise<void>;
87
+ /** Whether props were from cache */
88
+ cached: boolean;
89
+ }
90
+ /**
91
+ * Options for useAIProps hook
92
+ */
93
+ export interface UseAIPropsOptions<T> extends Omit<GeneratePropsOptions, 'context'> {
94
+ /** Partial props to merge and use as context */
95
+ partialProps?: Partial<T>;
96
+ /** Skip generation if all required props are provided */
97
+ skipIfComplete?: boolean;
98
+ /** Dependencies that trigger regeneration */
99
+ deps?: unknown[];
100
+ }
101
+ /**
102
+ * Component wrapper options for AI()
103
+ */
104
+ export interface AIComponentOptions<P> {
105
+ /** Schema for the component props */
106
+ schema: PropSchema;
107
+ /** Default props */
108
+ defaults?: Partial<P>;
109
+ /** Props that are always required (never generated) */
110
+ required?: (keyof P)[];
111
+ /** Props to exclude from generation */
112
+ exclude?: (keyof P)[];
113
+ /** AI generation config */
114
+ config?: AIPropsConfig;
115
+ }
116
+ /**
117
+ * Enhanced component type with AI capabilities
118
+ */
119
+ export interface AIComponent<P> {
120
+ (props: Partial<P>): Promise<P>;
121
+ /** Original schema */
122
+ schema: PropSchema;
123
+ /** Generate props without rendering */
124
+ generateProps: (context?: Partial<P>) => Promise<P>;
125
+ /** Configuration */
126
+ config: AIPropsConfig;
127
+ }
128
+ /**
129
+ * Type helper to extract props type from a schema
130
+ */
131
+ export type InferProps<S extends PropSchema> = S extends SimpleSchema ? S extends string ? string : S extends {
132
+ [key: string]: SimpleSchema;
133
+ } ? {
134
+ [K in keyof S]: InferProps<S[K]>;
135
+ } : unknown : unknown;
136
+ /**
137
+ * Validation result for props
138
+ */
139
+ export interface ValidationResult {
140
+ valid: boolean;
141
+ errors: ValidationError[];
142
+ }
143
+ /**
144
+ * Individual validation error
145
+ */
146
+ export interface ValidationError {
147
+ path: string;
148
+ message: string;
149
+ expected?: string;
150
+ received?: unknown;
151
+ }
152
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAEhD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,sDAAsD;IACtD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,2CAA2C;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,uCAAuC;IACvC,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,qDAAqD;IACrD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,iCAAiC;IACjC,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAA;CACrF;AAED;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,YAAY,GAAG,MAAM,CAAA;AAE9C;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,4CAA4C;IAC5C,MAAM,EAAE,UAAU,CAAA;IAClB,sCAAsC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACjC,gCAAgC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,mBAAmB;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,oBAAoB;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC,sBAAsB;IACtB,KAAK,EAAE,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EG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB"}
package/dist/types.js ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Type definitions for ai-props
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Validation utilities for ai-props
3
+ *
4
+ * Provides prop validation against schemas.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ import type { PropSchema, ValidationResult } from './types.js';
9
+ /**
10
+ * Validate props against a schema
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const result = validateProps(
15
+ * { name: 'John', age: '25' }, // props
16
+ * { name: 'Name', age: 'Age (number)' } // schema
17
+ * )
18
+ *
19
+ * if (!result.valid) {
20
+ * console.log(result.errors)
21
+ * // [{ path: 'age', message: 'Expected number, got string' }]
22
+ * }
23
+ * ```
24
+ */
25
+ export declare function validateProps(props: Record<string, unknown>, schema: PropSchema): ValidationResult;
26
+ /**
27
+ * Check if all required props are present
28
+ */
29
+ export declare function hasRequiredProps<P extends Record<string, unknown>>(props: Partial<P>, required: (keyof P)[]): boolean;
30
+ /**
31
+ * Get list of missing required props
32
+ */
33
+ export declare function getMissingProps<P extends Record<string, unknown>>(props: Partial<P>, required: (keyof P)[]): (keyof P)[];
34
+ /**
35
+ * Check if props are complete according to schema
36
+ */
37
+ export declare function isComplete(props: Record<string, unknown>, schema: PropSchema): boolean;
38
+ /**
39
+ * Get list of missing props according to schema
40
+ */
41
+ export declare function getMissingFromSchema(props: Record<string, unknown>, schema: PropSchema): string[];
42
+ /**
43
+ * Sanitize props by removing extra keys not in schema
44
+ */
45
+ export declare function sanitizeProps<P extends Record<string, unknown>>(props: P, schema: PropSchema): Partial<P>;
46
+ /**
47
+ * Merge props with defaults, respecting schema types
48
+ */
49
+ export declare function mergeWithDefaults<P extends Record<string, unknown>>(props: Partial<P>, defaults: Partial<P>, schema: PropSchema): Partial<P>;
50
+ /**
51
+ * Create a props validator function
52
+ */
53
+ export declare function createValidator<P extends Record<string, unknown>>(schema: PropSchema): (props: Partial<P>) => ValidationResult;
54
+ /**
55
+ * Assert props are valid, throwing on error
56
+ */
57
+ export declare function assertValidProps(props: Record<string, unknown>, schema: PropSchema): void;
58
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAmB,MAAM,YAAY,CAAA;AAE/E;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,MAAM,EAAE,UAAU,GACjB,gBAAgB,CAwBlB;AAuID;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,EACjB,QAAQ,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,GACpB,OAAO,CAET;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/D,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,EACjB,QAAQ,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,GACpB,CAAC,MAAM,CAAC,CAAC,EAAE,CAEb;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAA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