ai-props 2.1.3 → 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.
- package/.dev.vars +2 -0
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +20 -0
- package/README.md +2 -0
- package/dist/ai.d.ts.map +1 -1
- package/dist/ai.js +4 -4
- package/dist/ai.js.map +1 -1
- package/dist/cascade.d.ts +329 -0
- package/dist/cascade.d.ts.map +1 -0
- package/dist/cascade.js +522 -0
- package/dist/cascade.js.map +1 -0
- package/dist/client.d.ts +233 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +191 -0
- package/dist/client.js.map +1 -0
- package/dist/durable-cascade.d.ts +280 -0
- package/dist/durable-cascade.d.ts.map +1 -0
- package/dist/durable-cascade.js +469 -0
- package/dist/durable-cascade.js.map +1 -0
- package/dist/event-bridge.d.ts +257 -0
- package/dist/event-bridge.d.ts.map +1 -0
- package/dist/event-bridge.js +317 -0
- package/dist/event-bridge.js.map +1 -0
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +12 -6
- package/dist/generate.js.map +1 -1
- package/dist/hoc.d.ts.map +1 -1
- package/dist/hoc.js +13 -13
- package/dist/hoc.js.map +1 -1
- package/dist/hono-jsx.d.ts +208 -0
- package/dist/hono-jsx.d.ts.map +1 -0
- package/dist/hono-jsx.js +459 -0
- package/dist/hono-jsx.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/mdx-types.d.ts +152 -0
- package/dist/mdx-types.d.ts.map +1 -0
- package/dist/mdx-types.js +9 -0
- package/dist/mdx-types.js.map +1 -0
- package/dist/mdx-utils.d.ts +106 -0
- package/dist/mdx-utils.d.ts.map +1 -0
- package/dist/mdx-utils.js +384 -0
- package/dist/mdx-utils.js.map +1 -0
- package/dist/mdx.d.ts +230 -0
- package/dist/mdx.d.ts.map +1 -0
- package/dist/mdx.js +820 -0
- package/dist/mdx.js.map +1 -0
- package/dist/rpc.d.ts +313 -0
- package/dist/rpc.d.ts.map +1 -0
- package/dist/rpc.js +359 -0
- package/dist/rpc.js.map +1 -0
- package/dist/streaming.d.ts +199 -0
- package/dist/streaming.d.ts.map +1 -0
- package/dist/streaming.js +402 -0
- package/dist/streaming.js.map +1 -0
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +11 -13
- package/dist/validate.js.map +1 -1
- package/dist/worker.d.ts +270 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +405 -0
- package/dist/worker.js.map +1 -0
- package/package.json +39 -13
- package/src/ai.ts +12 -31
- package/src/cascade.ts +795 -0
- package/src/client.ts +440 -0
- package/src/durable-cascade.ts +743 -0
- package/src/event-bridge.ts +478 -0
- package/src/generate.ts +14 -12
- package/src/hoc.ts +15 -19
- package/src/hono-jsx.ts +675 -0
- package/src/index.ts +30 -0
- package/src/mdx-types.ts +169 -0
- package/src/mdx-utils.ts +437 -0
- package/src/mdx.ts +1008 -0
- package/src/rpc.ts +614 -0
- package/src/streaming.ts +618 -0
- package/src/validate.ts +15 -29
- package/src/worker.ts +547 -0
- package/test/cascade.test.ts +338 -0
- package/test/durable-cascade.test.ts +319 -0
- package/test/event-bridge.test.ts +351 -0
- package/test/generate.test.ts +6 -16
- package/test/mdx.test.ts +817 -0
- package/test/worker/capnweb-rpc.test.ts +1084 -0
- package/test/worker/full-flow.integration.test.ts +1463 -0
- package/test/worker/hono-jsx.test.ts +1258 -0
- package/test/worker/mdx-parsing.test.ts +1148 -0
- package/test/worker/setup.ts +56 -0
- package/test/worker.test.ts +595 -0
- package/tsconfig.json +2 -1
- package/vitest.config.js +6 -0
- package/vitest.config.ts +15 -1
- package/vitest.workers.config.ts +58 -0
- package/wrangler.jsonc +27 -0
- package/LICENSE +0 -21
- package/src/ai.js +0 -198
- package/src/cache.js +0 -182
- package/src/generate.js +0 -220
- package/src/hoc.js +0 -235
- package/src/index.js +0 -20
- package/src/types.js +0 -6
- package/src/validate.js +0 -252
package/dist/mdx.d.ts
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MDX parsing and rendering with AI-generated props
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for parsing MDX content, extracting component schemas,
|
|
5
|
+
* and rendering with AI-generated props.
|
|
6
|
+
*
|
|
7
|
+
* Key features:
|
|
8
|
+
* - Content-hash based caching for parsed MDX
|
|
9
|
+
* - Parallel prop generation for multiple components
|
|
10
|
+
* - Streaming-ready architecture
|
|
11
|
+
* - Graceful error handling with detailed messages
|
|
12
|
+
*
|
|
13
|
+
* @packageDocumentation
|
|
14
|
+
*/
|
|
15
|
+
export type { ParsedMDX, ComponentSchemas, MDXPropsGeneratorOptions, MDXPropsGenerator, RenderMDXOptions, CompileMDXOptions, CompiledMDXFunction, StreamMDXOptions, MDXCacheEntry, MDXParseError, CacheInvalidationStrategy, MDXCacheOptions, MDXCacheStats, } from './mdx-types.js';
|
|
16
|
+
import type { ParsedMDX, ComponentSchemas, MDXPropsGeneratorOptions, MDXPropsGenerator, RenderMDXOptions, CompileMDXOptions, CompiledMDXFunction, StreamMDXOptions, MDXCacheOptions, MDXCacheStats } from './mdx-types.js';
|
|
17
|
+
/**
|
|
18
|
+
* Configure the global MDX parse cache
|
|
19
|
+
*
|
|
20
|
+
* @param options - Cache configuration options
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* // Configure with larger cache and longer TTL
|
|
25
|
+
* configureMDXCache({
|
|
26
|
+
* maxSize: 500,
|
|
27
|
+
* ttl: 30 * 60 * 1000, // 30 minutes
|
|
28
|
+
* autoCleanup: true,
|
|
29
|
+
* })
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function configureMDXCache(options: MDXCacheOptions): void;
|
|
33
|
+
/**
|
|
34
|
+
* Get MDX cache statistics
|
|
35
|
+
*
|
|
36
|
+
* Useful for monitoring cache performance and tuning configuration.
|
|
37
|
+
*
|
|
38
|
+
* @returns Cache statistics
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* const stats = getMDXCacheStats()
|
|
43
|
+
* console.log(`Cache hit ratio: ${(stats.hitRatio * 100).toFixed(1)}%`)
|
|
44
|
+
* console.log(`Cache size: ${stats.size}/${stats.maxSize}`)
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function getMDXCacheStats(): MDXCacheStats;
|
|
48
|
+
/**
|
|
49
|
+
* Invalidate MDX cache entries by tag
|
|
50
|
+
*
|
|
51
|
+
* @param tag - Tag to invalidate
|
|
52
|
+
* @returns Number of entries invalidated
|
|
53
|
+
*/
|
|
54
|
+
export declare function invalidateMDXCacheByTag(tag: string): number;
|
|
55
|
+
/**
|
|
56
|
+
* Cleanup expired MDX cache entries
|
|
57
|
+
*
|
|
58
|
+
* @returns Number of entries removed
|
|
59
|
+
*/
|
|
60
|
+
export declare function cleanupMDXCache(): number;
|
|
61
|
+
/**
|
|
62
|
+
* Options for parsing MDX
|
|
63
|
+
*/
|
|
64
|
+
export interface ParseMDXOptions {
|
|
65
|
+
/**
|
|
66
|
+
* Tags to associate with the cached result for group invalidation
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* parseMDX(content, { tags: ['page:/products', 'component:Hero'] })
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
tags?: string[];
|
|
74
|
+
/**
|
|
75
|
+
* Skip caching for this parse operation
|
|
76
|
+
*/
|
|
77
|
+
skipCache?: boolean;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Parse MDX content string
|
|
81
|
+
*
|
|
82
|
+
* Extracts frontmatter, identifies components, and parses component props.
|
|
83
|
+
* Results are cached based on content hash for performance.
|
|
84
|
+
*
|
|
85
|
+
* @param mdx - MDX content string
|
|
86
|
+
* @param options - Parse options (optional)
|
|
87
|
+
* @returns Parsed MDX structure
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* const result = parseMDX(`---
|
|
92
|
+
* title: Hello
|
|
93
|
+
* ---
|
|
94
|
+
*
|
|
95
|
+
* # {title}
|
|
96
|
+
*
|
|
97
|
+
* <Hero />
|
|
98
|
+
* `)
|
|
99
|
+
*
|
|
100
|
+
* console.log(result.frontmatter.title) // 'Hello'
|
|
101
|
+
* console.log(result.components) // ['Hero']
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* // Parse with cache tags for group invalidation
|
|
107
|
+
* const result = parseMDX(content, {
|
|
108
|
+
* tags: ['page:/home', 'component:Hero']
|
|
109
|
+
* })
|
|
110
|
+
*
|
|
111
|
+
* // Later, invalidate all home page entries
|
|
112
|
+
* invalidateMDXCacheByTag('page:/home')
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export declare function parseMDX(mdx: string, options?: ParseMDXOptions): ParsedMDX;
|
|
116
|
+
/**
|
|
117
|
+
* Extract prop schemas from MDX component usage
|
|
118
|
+
*
|
|
119
|
+
* Analyzes component tags in MDX to infer prop schemas.
|
|
120
|
+
*
|
|
121
|
+
* @param mdx - MDX content string
|
|
122
|
+
* @returns Schemas for each component
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* const schemas = extractComponentSchemas(`
|
|
127
|
+
* <Card title="Hello" count={5} />
|
|
128
|
+
* `)
|
|
129
|
+
*
|
|
130
|
+
* // schemas.Card = { title: 'title (string)', count: 'count (number)' }
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export declare function extractComponentSchemas(mdx: string): ComponentSchemas;
|
|
134
|
+
/**
|
|
135
|
+
* Create an MDX props generator
|
|
136
|
+
*
|
|
137
|
+
* The generator uses content-hash based caching and supports parallel
|
|
138
|
+
* generation for multiple components.
|
|
139
|
+
*
|
|
140
|
+
* @param options - Generator options
|
|
141
|
+
* @returns MDX props generator instance
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* const generator = createMDXPropsGenerator({
|
|
146
|
+
* schemas: {
|
|
147
|
+
* Hero: { title: 'Hero title', subtitle: 'Hero subtitle' },
|
|
148
|
+
* },
|
|
149
|
+
* cache: true,
|
|
150
|
+
* maxParallel: 3,
|
|
151
|
+
* })
|
|
152
|
+
*
|
|
153
|
+
* const props = await generator.generate(`<Hero />`)
|
|
154
|
+
* // props.Hero = { title: '...', subtitle: '...' }
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export declare function createMDXPropsGenerator(options: MDXPropsGeneratorOptions): MDXPropsGenerator;
|
|
158
|
+
/**
|
|
159
|
+
* Render MDX with injected props
|
|
160
|
+
*
|
|
161
|
+
* @param mdx - MDX content string
|
|
162
|
+
* @param props - Props for each component
|
|
163
|
+
* @param options - Render options
|
|
164
|
+
* @returns Rendered content (string or stream)
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```ts
|
|
168
|
+
* const html = await renderMDXWithProps(
|
|
169
|
+
* `<Hero title="Welcome" />`,
|
|
170
|
+
* { Hero: { title: 'Welcome', subtitle: 'To the site' } }
|
|
171
|
+
* )
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
export declare function renderMDXWithProps(mdx: string, props: Record<string, Record<string, unknown> | null>, options?: RenderMDXOptions): Promise<string | ReadableStream<string>>;
|
|
175
|
+
/**
|
|
176
|
+
* Stream MDX content with injected props
|
|
177
|
+
*
|
|
178
|
+
* Returns a ReadableStream for progressive rendering of MDX content.
|
|
179
|
+
*
|
|
180
|
+
* @param mdx - MDX content string
|
|
181
|
+
* @param props - Props for each component
|
|
182
|
+
* @param options - Stream options
|
|
183
|
+
* @returns ReadableStream of rendered content
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```ts
|
|
187
|
+
* const stream = await streamMDXWithProps(
|
|
188
|
+
* `<Hero title="Welcome" />`,
|
|
189
|
+
* { Hero: { title: 'Welcome', subtitle: 'To the site' } }
|
|
190
|
+
* )
|
|
191
|
+
*
|
|
192
|
+
* const reader = stream.getReader()
|
|
193
|
+
* while (true) {
|
|
194
|
+
* const { done, value } = await reader.read()
|
|
195
|
+
* if (done) break
|
|
196
|
+
* console.log(new TextDecoder().decode(value))
|
|
197
|
+
* }
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
export declare function streamMDXWithProps(mdx: string, props: Record<string, Record<string, unknown>>, options?: StreamMDXOptions): Promise<ReadableStream<Uint8Array>>;
|
|
201
|
+
/**
|
|
202
|
+
* Compile MDX to an executable function
|
|
203
|
+
*
|
|
204
|
+
* Compilation is lazy - the MDX is parsed once, and the returned function
|
|
205
|
+
* can be called multiple times with different props.
|
|
206
|
+
*
|
|
207
|
+
* @param mdx - MDX content string
|
|
208
|
+
* @param options - Compile options
|
|
209
|
+
* @returns Compiled function that accepts props
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```ts
|
|
213
|
+
* const compiled = await compileMDX(`<Greeting name="World" />`)
|
|
214
|
+
* const result = compiled({ Greeting: { name: 'World' } })
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
export declare function compileMDX(mdx: string, options?: CompileMDXOptions): Promise<CompiledMDXFunction>;
|
|
218
|
+
/**
|
|
219
|
+
* Clear the MDX parse cache
|
|
220
|
+
*
|
|
221
|
+
* Use this when you need to force re-parsing of all MDX content.
|
|
222
|
+
*/
|
|
223
|
+
export declare function clearMDXCache(): void;
|
|
224
|
+
/**
|
|
225
|
+
* Get the current MDX parse cache size
|
|
226
|
+
*
|
|
227
|
+
* @returns Number of cached parse results
|
|
228
|
+
*/
|
|
229
|
+
export declare function getMDXCacheSize(): number;
|
|
230
|
+
//# sourceMappingURL=mdx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
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