ai-props 0.1.2 → 2.0.2
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/.turbo/turbo-build.log +5 -0
- package/CHANGELOG.md +15 -0
- package/README.md +345 -352
- package/dist/ai.d.ts +125 -0
- package/dist/ai.d.ts.map +1 -0
- package/dist/ai.js +199 -0
- package/dist/ai.js.map +1 -0
- package/dist/cache.d.ts +66 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +183 -0
- package/dist/cache.js.map +1 -0
- package/dist/generate.d.ts +69 -0
- package/dist/generate.d.ts.map +1 -0
- package/dist/generate.js +221 -0
- package/dist/generate.js.map +1 -0
- package/dist/hoc.d.ts +164 -0
- package/dist/hoc.d.ts.map +1 -0
- package/dist/hoc.js +236 -0
- package/dist/hoc.js.map +1 -0
- package/dist/index.d.ts +14 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +152 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/validate.d.ts +58 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +253 -0
- package/dist/validate.js.map +1 -0
- package/package.json +16 -63
- package/src/ai.ts +264 -0
- package/src/cache.ts +216 -0
- package/src/generate.ts +276 -0
- package/src/hoc.ts +309 -0
- package/src/index.ts +66 -0
- package/src/types.ts +167 -0
- package/src/validate.ts +333 -0
- package/test/ai.test.ts +327 -0
- package/test/cache.test.ts +236 -0
- package/test/generate.test.ts +406 -0
- package/test/hoc.test.ts +411 -0
- package/test/validate.test.ts +324 -0
- package/tsconfig.json +9 -0
- package/vitest.config.ts +15 -0
- package/LICENSE +0 -21
- package/dist/AI.d.ts +0 -27
- package/dist/AI.d.ts.map +0 -1
- package/dist/AI.test.d.ts +0 -2
- package/dist/AI.test.d.ts.map +0 -1
- package/dist/ai-props.es.js +0 -3697
- package/dist/ai-props.umd.js +0 -30
- package/dist/components/ErrorBoundary.d.ts +0 -17
- package/dist/components/ErrorBoundary.d.ts.map +0 -1
- package/dist/examples/BlogList.d.ts +0 -2
- package/dist/examples/BlogList.d.ts.map +0 -1
- package/dist/examples/BlogList.fixture.d.ts +0 -5
- package/dist/examples/BlogList.fixture.d.ts.map +0 -1
- package/dist/examples/HeroSection.d.ts +0 -2
- package/dist/examples/HeroSection.d.ts.map +0 -1
- package/dist/examples/HeroSection.fixture.d.ts +0 -5
- package/dist/examples/HeroSection.fixture.d.ts.map +0 -1
- package/dist/test/setup.d.ts +0 -2
- package/dist/test/setup.d.ts.map +0 -1
- package/dist/utils/schema.d.ts +0 -28
- package/dist/utils/schema.d.ts.map +0 -1
- package/dist/utils/styles.d.ts +0 -3
- package/dist/utils/styles.d.ts.map +0 -1
package/dist/generate.js
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Props generation for ai-props
|
|
3
|
+
*
|
|
4
|
+
* Core functionality for generating component props using AI.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
import { generateObject, schema as createSchema } from 'ai-functions';
|
|
9
|
+
import { createCacheKey, getDefaultCache } from './cache.js';
|
|
10
|
+
/**
|
|
11
|
+
* Default configuration
|
|
12
|
+
*/
|
|
13
|
+
const DEFAULT_CONFIG = {
|
|
14
|
+
model: 'sonnet',
|
|
15
|
+
cache: true,
|
|
16
|
+
cacheTTL: 5 * 60 * 1000, // 5 minutes
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Global configuration
|
|
20
|
+
*/
|
|
21
|
+
let globalConfig = { ...DEFAULT_CONFIG };
|
|
22
|
+
/**
|
|
23
|
+
* Configure global AI props settings
|
|
24
|
+
*/
|
|
25
|
+
export function configureAIProps(config) {
|
|
26
|
+
globalConfig = { ...globalConfig, ...config };
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get current configuration
|
|
30
|
+
*/
|
|
31
|
+
export function getConfig() {
|
|
32
|
+
return { ...globalConfig };
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Reset configuration to defaults
|
|
36
|
+
*/
|
|
37
|
+
export function resetConfig() {
|
|
38
|
+
globalConfig = { ...DEFAULT_CONFIG };
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Resolve a prop schema to a SimpleSchema
|
|
42
|
+
*
|
|
43
|
+
* If the schema is a string, it's treated as a named type
|
|
44
|
+
* that generates a single property or description.
|
|
45
|
+
*/
|
|
46
|
+
function resolveSchema(schema) {
|
|
47
|
+
if (typeof schema === 'string') {
|
|
48
|
+
// Named type or description string
|
|
49
|
+
return { value: schema };
|
|
50
|
+
}
|
|
51
|
+
return schema;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Build a prompt from context and schema
|
|
55
|
+
*/
|
|
56
|
+
function buildPrompt(schema, context, additionalPrompt) {
|
|
57
|
+
const parts = [];
|
|
58
|
+
// Add context information
|
|
59
|
+
if (context && Object.keys(context).length > 0) {
|
|
60
|
+
parts.push('Given the following context:');
|
|
61
|
+
parts.push(JSON.stringify(context, null, 2));
|
|
62
|
+
parts.push('');
|
|
63
|
+
}
|
|
64
|
+
// Add schema information
|
|
65
|
+
if (typeof schema === 'string') {
|
|
66
|
+
parts.push(`Generate a value for: ${schema}`);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
parts.push('Generate props matching the schema.');
|
|
70
|
+
}
|
|
71
|
+
// Add additional prompt
|
|
72
|
+
if (additionalPrompt) {
|
|
73
|
+
parts.push('');
|
|
74
|
+
parts.push(additionalPrompt);
|
|
75
|
+
}
|
|
76
|
+
return parts.join('\n');
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Generate props using AI
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* const result = await generateProps({
|
|
84
|
+
* schema: {
|
|
85
|
+
* title: 'A compelling page title',
|
|
86
|
+
* description: 'A brief description',
|
|
87
|
+
* keywords: ['Relevant SEO keywords'],
|
|
88
|
+
* },
|
|
89
|
+
* context: { topic: 'AI-powered applications' },
|
|
90
|
+
* })
|
|
91
|
+
*
|
|
92
|
+
* console.log(result.props)
|
|
93
|
+
* // { title: '...', description: '...', keywords: [...] }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export async function generateProps(options) {
|
|
97
|
+
const { schema, context, prompt, model, system } = options;
|
|
98
|
+
const config = getConfig();
|
|
99
|
+
const startTime = Date.now();
|
|
100
|
+
// Check cache
|
|
101
|
+
if (config.cache) {
|
|
102
|
+
const cache = getDefaultCache();
|
|
103
|
+
const cacheKey = createCacheKey(schema, context);
|
|
104
|
+
const cached = cache.get(cacheKey);
|
|
105
|
+
if (cached) {
|
|
106
|
+
return {
|
|
107
|
+
props: cached.props,
|
|
108
|
+
cached: true,
|
|
109
|
+
metadata: {
|
|
110
|
+
model: config.model || 'cached',
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// Resolve schema
|
|
116
|
+
const resolvedSchema = resolveSchema(schema);
|
|
117
|
+
// Build prompt
|
|
118
|
+
const fullPrompt = buildPrompt(schema, context, prompt);
|
|
119
|
+
// Use custom generator if provided
|
|
120
|
+
if (config.generate) {
|
|
121
|
+
const props = await config.generate(resolvedSchema, context || {});
|
|
122
|
+
return {
|
|
123
|
+
props,
|
|
124
|
+
cached: false,
|
|
125
|
+
metadata: {
|
|
126
|
+
model: 'custom',
|
|
127
|
+
duration: Date.now() - startTime,
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
// Generate using AI
|
|
132
|
+
const result = await generateObject({
|
|
133
|
+
model: model || config.model || 'sonnet',
|
|
134
|
+
schema: resolvedSchema,
|
|
135
|
+
prompt: fullPrompt,
|
|
136
|
+
system: system || config.system,
|
|
137
|
+
});
|
|
138
|
+
const props = result.object;
|
|
139
|
+
// Cache result
|
|
140
|
+
if (config.cache) {
|
|
141
|
+
const cache = getDefaultCache();
|
|
142
|
+
const cacheKey = createCacheKey(schema, context);
|
|
143
|
+
cache.set(cacheKey, props);
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
props,
|
|
147
|
+
cached: false,
|
|
148
|
+
metadata: {
|
|
149
|
+
model: model || config.model || 'sonnet',
|
|
150
|
+
duration: Date.now() - startTime,
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Generate props synchronously from cache or throw
|
|
156
|
+
*
|
|
157
|
+
* Useful for SSR scenarios where async isn't available.
|
|
158
|
+
* Throws if props aren't in cache.
|
|
159
|
+
*/
|
|
160
|
+
export function getPropsSync(schema, context) {
|
|
161
|
+
const cache = getDefaultCache();
|
|
162
|
+
const cacheKey = createCacheKey(schema, context);
|
|
163
|
+
const cached = cache.get(cacheKey);
|
|
164
|
+
if (!cached) {
|
|
165
|
+
throw new Error('Props not in cache. Use generateProps() first or ensure caching is enabled.');
|
|
166
|
+
}
|
|
167
|
+
return cached.props;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Pre-generate props for warming the cache
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* await prefetchProps([
|
|
175
|
+
* { schema: userProfileSchema, context: { userId: '123' } },
|
|
176
|
+
* { schema: productSchema, context: { category: 'electronics' } },
|
|
177
|
+
* ])
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
export async function prefetchProps(requests) {
|
|
181
|
+
await Promise.all(requests.map(generateProps));
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Generate multiple prop sets in parallel
|
|
185
|
+
*/
|
|
186
|
+
export async function generatePropsMany(requests) {
|
|
187
|
+
return Promise.all(requests.map(req => generateProps(req)));
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Merge partial props with generated props
|
|
191
|
+
*
|
|
192
|
+
* Generates only the missing props, keeping provided ones.
|
|
193
|
+
*/
|
|
194
|
+
export async function mergeWithGenerated(schema, partialProps, options) {
|
|
195
|
+
// Get list of missing keys
|
|
196
|
+
const schemaObj = typeof schema === 'string' ? { value: schema } : schema;
|
|
197
|
+
const schemaKeys = Object.keys(schemaObj);
|
|
198
|
+
const providedKeys = Object.keys(partialProps);
|
|
199
|
+
const missingKeys = schemaKeys.filter(k => !providedKeys.includes(k));
|
|
200
|
+
// If all props are provided, return as-is
|
|
201
|
+
if (missingKeys.length === 0) {
|
|
202
|
+
return partialProps;
|
|
203
|
+
}
|
|
204
|
+
// Build partial schema for missing props only
|
|
205
|
+
const partialSchema = {};
|
|
206
|
+
for (const key of missingKeys) {
|
|
207
|
+
partialSchema[key] = schemaObj[key];
|
|
208
|
+
}
|
|
209
|
+
// Generate missing props
|
|
210
|
+
const result = await generateProps({
|
|
211
|
+
schema: partialSchema,
|
|
212
|
+
context: partialProps,
|
|
213
|
+
...options,
|
|
214
|
+
});
|
|
215
|
+
// Merge
|
|
216
|
+
return {
|
|
217
|
+
...result.props,
|
|
218
|
+
...partialProps,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=generate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,IAAI,YAAY,EAAqB,MAAM,cAAc,CAAA;AAOxF,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE5D;;GAEG;AACH,MAAM,cAAc,GAAkB;IACpC,KAAK,EAAE,QAAQ;IACf,KAAK,EAAE,IAAI;IACX,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,YAAY;CACtC,CAAA;AAED;;GAEG;AACH,IAAI,YAAY,G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IACzB,MAAM,MAAM,GAAG,MAAM,aAAa,CAAa;QAC7C,MAAM,EAAE,aAA6B;QACrC,OAAO,EAAE,YAAuC;QAChD,GAAG,OAAO;KACX,CAAC,CAAA;IAEF,QAAQ;IACR,OAAO;QACL,GAAG,MAAM,CAAC,KAAK;QACf,GAAG,YAAY;KACX,CAAA;AACR,CAAC"}
|
package/dist/hoc.d.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Higher-Order Component (HOC) for React components
|
|
3
|
+
*
|
|
4
|
+
* Provides withAIProps HOC for wrapping React components
|
|
5
|
+
* with AI-powered prop generation.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import type { PropSchema, AIComponentOptions, AIPropsConfig } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Options for withAIProps HOC
|
|
12
|
+
*/
|
|
13
|
+
export interface WithAIPropsOptions<P> extends Omit<AIComponentOptions<P>, 'schema'> {
|
|
14
|
+
/** Schema for props to generate */
|
|
15
|
+
schema: PropSchema;
|
|
16
|
+
/** Loading component to show while generating */
|
|
17
|
+
loading?: () => unknown;
|
|
18
|
+
/** Error component to show on generation failure */
|
|
19
|
+
error?: (error: Error) => unknown;
|
|
20
|
+
/** Fallback props to use if generation fails */
|
|
21
|
+
fallback?: Partial<P>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create props wrapper that can be used with any component system
|
|
25
|
+
*
|
|
26
|
+
* This is framework-agnostic and returns the enhanced props.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const enhancer = createPropsEnhancer({
|
|
31
|
+
* schema: {
|
|
32
|
+
* title: 'Page title',
|
|
33
|
+
* description: 'Page description',
|
|
34
|
+
* },
|
|
35
|
+
* defaults: {
|
|
36
|
+
* title: 'Default Title',
|
|
37
|
+
* },
|
|
38
|
+
* })
|
|
39
|
+
*
|
|
40
|
+
* // Use with any component
|
|
41
|
+
* const props = await enhancer({ description: 'My page' })
|
|
42
|
+
* // { title: 'Default Title', description: 'My page' }
|
|
43
|
+
*
|
|
44
|
+
* const generatedProps = await enhancer({})
|
|
45
|
+
* // { title: 'AI-generated title', description: 'AI-generated description' }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare function createPropsEnhancer<P extends Record<string, unknown>>(options: WithAIPropsOptions<P>): (partialProps: Partial<P>) => Promise<P>;
|
|
49
|
+
/**
|
|
50
|
+
* Create an async props provider
|
|
51
|
+
*
|
|
52
|
+
* Returns a function that generates props on each call.
|
|
53
|
+
* Useful for SSR and static generation.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const getPageProps = createAsyncPropsProvider({
|
|
58
|
+
* schema: {
|
|
59
|
+
* title: 'SEO-optimized page title',
|
|
60
|
+
* meta: { description: 'Meta description' },
|
|
61
|
+
* },
|
|
62
|
+
* })
|
|
63
|
+
*
|
|
64
|
+
* // In getStaticProps or getServerSideProps
|
|
65
|
+
* export async function getStaticProps() {
|
|
66
|
+
* const props = await getPageProps({ slug: 'about' })
|
|
67
|
+
* return { props }
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function createAsyncPropsProvider<P extends Record<string, unknown>>(options: WithAIPropsOptions<P>): {
|
|
72
|
+
/**
|
|
73
|
+
* Get props with AI generation
|
|
74
|
+
*/
|
|
75
|
+
getProps: (partialProps: Partial<P>) => Promise<P>;
|
|
76
|
+
/**
|
|
77
|
+
* Get props for multiple items
|
|
78
|
+
*/
|
|
79
|
+
getManyProps: (contexts: Partial<P>[]) => Promise<P[]>;
|
|
80
|
+
/**
|
|
81
|
+
* Get props with caching hint
|
|
82
|
+
*/
|
|
83
|
+
getCachedProps: (context: Partial<P>, revalidate?: number) => Promise<{
|
|
84
|
+
props: P;
|
|
85
|
+
revalidate?: number;
|
|
86
|
+
}>;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Create a props transformer
|
|
90
|
+
*
|
|
91
|
+
* Transforms existing props by filling in missing values.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* const transformUserProps = createPropsTransformer({
|
|
96
|
+
* schema: {
|
|
97
|
+
* displayName: 'Display name for the user',
|
|
98
|
+
* initials: 'User initials (2 letters)',
|
|
99
|
+
* },
|
|
100
|
+
* })
|
|
101
|
+
*
|
|
102
|
+
* const user = await transformUserProps({
|
|
103
|
+
* username: 'johndoe',
|
|
104
|
+
* email: 'john@example.com',
|
|
105
|
+
* })
|
|
106
|
+
* // { username: 'johndoe', email: '...', displayName: 'John Doe', initials: 'JD' }
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export declare function createPropsTransformer<I extends Record<string, unknown>, O extends Record<string, unknown>>(options: {
|
|
110
|
+
schema: PropSchema;
|
|
111
|
+
transform?: (input: I, generated: Record<string, unknown>) => O;
|
|
112
|
+
config?: AIPropsConfig;
|
|
113
|
+
}): (input: I) => Promise<I & O>;
|
|
114
|
+
/**
|
|
115
|
+
* Create a conditional props generator
|
|
116
|
+
*
|
|
117
|
+
* Only generates props when a condition is met.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* const maybeGenerateProps = createConditionalGenerator({
|
|
122
|
+
* schema: { summary: 'Article summary' },
|
|
123
|
+
* condition: (props) => !props.summary && props.content?.length > 100,
|
|
124
|
+
* })
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export declare function createConditionalGenerator<P extends Record<string, unknown>>(options: {
|
|
128
|
+
schema: PropSchema;
|
|
129
|
+
condition: (props: Partial<P>) => boolean;
|
|
130
|
+
config?: AIPropsConfig;
|
|
131
|
+
}): (props: Partial<P>) => Promise<P>;
|
|
132
|
+
/**
|
|
133
|
+
* Batch props generator for list rendering
|
|
134
|
+
*
|
|
135
|
+
* Efficiently generates props for multiple items.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* const batchGenerator = createBatchGenerator({
|
|
140
|
+
* schema: { title: 'Item title', description: 'Item description' },
|
|
141
|
+
* })
|
|
142
|
+
*
|
|
143
|
+
* const items = await batchGenerator.generate([
|
|
144
|
+
* { id: 1, category: 'tech' },
|
|
145
|
+
* { id: 2, category: 'science' },
|
|
146
|
+
* { id: 3, category: 'art' },
|
|
147
|
+
* ])
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
export declare function createBatchGenerator<P extends Record<string, unknown>>(options: {
|
|
151
|
+
schema: PropSchema;
|
|
152
|
+
concurrency?: number;
|
|
153
|
+
config?: AIPropsConfig;
|
|
154
|
+
}): {
|
|
155
|
+
/**
|
|
156
|
+
* Generate props for multiple items
|
|
157
|
+
*/
|
|
158
|
+
generate: (items: Partial<P>[]) => Promise<P[]>;
|
|
159
|
+
/**
|
|
160
|
+
* Generate props one at a time (for rate limiting)
|
|
161
|
+
*/
|
|
162
|
+
generateSequential: (items: Partial<P>[]) => Promise<P[]>;
|
|
163
|
+
};
|
|
164
|
+
//# sourceMappingURL=hoc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hoc.d.ts","sourceRoot":"","sources":["../src/hoc.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAG/E;;GAEG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,CAAE,SAAQ,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC;IAClF,mCAAmC;IACnC,MAAM,EAAE,UAAU,CAAA;IAClB,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,OAAO,CAAA;IACvB,oDAAoD;IACpD,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,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wBAAgB,0BAA0B,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE;IACrF,MAAM,EAAE,UAAU,CAAA;IAClB,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAA;IACzC,MAAM,CAAC,EAAE,aAAa,CAAA;CACvB,IAGe,OAAO,OAAO,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,CAAC,CAU7C;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE;IAC/E,MAAM,EAAE,UAAU,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,aAAa,CAAA;CACvB;IAIG;;OAEG;sBACqB,OAAO,CAAC,CAAC,CAAC,EAAE,KAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAoBnD;;OAEG;gCAC+B,OAAO,CAAC,CAAC,CAAC,EAAE,KAAG,OAAO,CAAC,CAAC,EAAE,CAAC;EAchE"}
|
package/dist/hoc.js
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Higher-Order Component (HOC) for React components
|
|
3
|
+
*
|
|
4
|
+
* Provides withAIProps HOC for wrapping React components
|
|
5
|
+
* with AI-powered prop generation.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import { generateProps, mergeWithGenerated } from './generate.js';
|
|
10
|
+
/**
|
|
11
|
+
* Create props wrapper that can be used with any component system
|
|
12
|
+
*
|
|
13
|
+
* This is framework-agnostic and returns the enhanced props.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const enhancer = createPropsEnhancer({
|
|
18
|
+
* schema: {
|
|
19
|
+
* title: 'Page title',
|
|
20
|
+
* description: 'Page description',
|
|
21
|
+
* },
|
|
22
|
+
* defaults: {
|
|
23
|
+
* title: 'Default Title',
|
|
24
|
+
* },
|
|
25
|
+
* })
|
|
26
|
+
*
|
|
27
|
+
* // Use with any component
|
|
28
|
+
* const props = await enhancer({ description: 'My page' })
|
|
29
|
+
* // { title: 'Default Title', description: 'My page' }
|
|
30
|
+
*
|
|
31
|
+
* const generatedProps = await enhancer({})
|
|
32
|
+
* // { title: 'AI-generated title', description: 'AI-generated description' }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function createPropsEnhancer(options) {
|
|
36
|
+
const { schema, defaults = {}, required = [], exclude = [], config = {}, fallback } = options;
|
|
37
|
+
return async (partialProps) => {
|
|
38
|
+
try {
|
|
39
|
+
// Merge with defaults
|
|
40
|
+
const propsWithDefaults = { ...defaults, ...partialProps };
|
|
41
|
+
// Check required props
|
|
42
|
+
const missingRequired = required.filter(key => propsWithDefaults[key] === undefined);
|
|
43
|
+
if (missingRequired.length > 0) {
|
|
44
|
+
throw new Error(`Missing required props: ${missingRequired.join(', ')}`);
|
|
45
|
+
}
|
|
46
|
+
// Filter out excluded props from schema
|
|
47
|
+
const filteredSchema = filterSchemaKeys(schema, exclude);
|
|
48
|
+
// Generate missing props
|
|
49
|
+
return await mergeWithGenerated(filteredSchema, propsWithDefaults, {
|
|
50
|
+
model: config.model,
|
|
51
|
+
system: config.system,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (fallback) {
|
|
56
|
+
return { ...defaults, ...fallback, ...partialProps };
|
|
57
|
+
}
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Filter schema to exclude certain keys
|
|
64
|
+
*/
|
|
65
|
+
function filterSchemaKeys(schema, exclude) {
|
|
66
|
+
if (typeof schema === 'string' || exclude.length === 0) {
|
|
67
|
+
return schema;
|
|
68
|
+
}
|
|
69
|
+
const filtered = {};
|
|
70
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
71
|
+
if (!exclude.includes(key)) {
|
|
72
|
+
filtered[key] = value;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return filtered;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Create an async props provider
|
|
79
|
+
*
|
|
80
|
+
* Returns a function that generates props on each call.
|
|
81
|
+
* Useful for SSR and static generation.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* const getPageProps = createAsyncPropsProvider({
|
|
86
|
+
* schema: {
|
|
87
|
+
* title: 'SEO-optimized page title',
|
|
88
|
+
* meta: { description: 'Meta description' },
|
|
89
|
+
* },
|
|
90
|
+
* })
|
|
91
|
+
*
|
|
92
|
+
* // In getStaticProps or getServerSideProps
|
|
93
|
+
* export async function getStaticProps() {
|
|
94
|
+
* const props = await getPageProps({ slug: 'about' })
|
|
95
|
+
* return { props }
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export function createAsyncPropsProvider(options) {
|
|
100
|
+
const enhancer = createPropsEnhancer(options);
|
|
101
|
+
return {
|
|
102
|
+
/**
|
|
103
|
+
* Get props with AI generation
|
|
104
|
+
*/
|
|
105
|
+
getProps: enhancer,
|
|
106
|
+
/**
|
|
107
|
+
* Get props for multiple items
|
|
108
|
+
*/
|
|
109
|
+
getManyProps: async (contexts) => {
|
|
110
|
+
return Promise.all(contexts.map(enhancer));
|
|
111
|
+
},
|
|
112
|
+
/**
|
|
113
|
+
* Get props with caching hint
|
|
114
|
+
*/
|
|
115
|
+
getCachedProps: async (context, revalidate) => {
|
|
116
|
+
const props = await enhancer(context);
|
|
117
|
+
return { props, revalidate };
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Create a props transformer
|
|
123
|
+
*
|
|
124
|
+
* Transforms existing props by filling in missing values.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* const transformUserProps = createPropsTransformer({
|
|
129
|
+
* schema: {
|
|
130
|
+
* displayName: 'Display name for the user',
|
|
131
|
+
* initials: 'User initials (2 letters)',
|
|
132
|
+
* },
|
|
133
|
+
* })
|
|
134
|
+
*
|
|
135
|
+
* const user = await transformUserProps({
|
|
136
|
+
* username: 'johndoe',
|
|
137
|
+
* email: 'john@example.com',
|
|
138
|
+
* })
|
|
139
|
+
* // { username: 'johndoe', email: '...', displayName: 'John Doe', initials: 'JD' }
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export function createPropsTransformer(options) {
|
|
143
|
+
const { schema, transform, config = {} } = options;
|
|
144
|
+
return async (input) => {
|
|
145
|
+
const result = await generateProps({
|
|
146
|
+
schema,
|
|
147
|
+
context: input,
|
|
148
|
+
model: config.model,
|
|
149
|
+
system: config.system,
|
|
150
|
+
});
|
|
151
|
+
const generated = result.props;
|
|
152
|
+
if (transform) {
|
|
153
|
+
return { ...input, ...transform(input, generated) };
|
|
154
|
+
}
|
|
155
|
+
return { ...input, ...generated };
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Create a conditional props generator
|
|
160
|
+
*
|
|
161
|
+
* Only generates props when a condition is met.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* const maybeGenerateProps = createConditionalGenerator({
|
|
166
|
+
* schema: { summary: 'Article summary' },
|
|
167
|
+
* condition: (props) => !props.summary && props.content?.length > 100,
|
|
168
|
+
* })
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
export function createConditionalGenerator(options) {
|
|
172
|
+
const { schema, condition, config = {} } = options;
|
|
173
|
+
return async (props) => {
|
|
174
|
+
if (!condition(props)) {
|
|
175
|
+
return props;
|
|
176
|
+
}
|
|
177
|
+
return mergeWithGenerated(schema, props, {
|
|
178
|
+
model: config.model,
|
|
179
|
+
system: config.system,
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Batch props generator for list rendering
|
|
185
|
+
*
|
|
186
|
+
* Efficiently generates props for multiple items.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* const batchGenerator = createBatchGenerator({
|
|
191
|
+
* schema: { title: 'Item title', description: 'Item description' },
|
|
192
|
+
* })
|
|
193
|
+
*
|
|
194
|
+
* const items = await batchGenerator.generate([
|
|
195
|
+
* { id: 1, category: 'tech' },
|
|
196
|
+
* { id: 2, category: 'science' },
|
|
197
|
+
* { id: 3, category: 'art' },
|
|
198
|
+
* ])
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
export function createBatchGenerator(options) {
|
|
202
|
+
const { schema, concurrency = 3, config = {} } = options;
|
|
203
|
+
return {
|
|
204
|
+
/**
|
|
205
|
+
* Generate props for multiple items
|
|
206
|
+
*/
|
|
207
|
+
generate: async (items) => {
|
|
208
|
+
const results = [];
|
|
209
|
+
// Process in batches based on concurrency
|
|
210
|
+
for (let i = 0; i < items.length; i += concurrency) {
|
|
211
|
+
const batch = items.slice(i, i + concurrency);
|
|
212
|
+
const batchResults = await Promise.all(batch.map(item => mergeWithGenerated(schema, item, {
|
|
213
|
+
model: config.model,
|
|
214
|
+
system: config.system,
|
|
215
|
+
})));
|
|
216
|
+
results.push(...batchResults);
|
|
217
|
+
}
|
|
218
|
+
return results;
|
|
219
|
+
},
|
|
220
|
+
/**
|
|
221
|
+
* Generate props one at a time (for rate limiting)
|
|
222
|
+
*/
|
|
223
|
+
generateSequential: async (items) => {
|
|
224
|
+
const results = [];
|
|
225
|
+
for (const item of items) {
|
|
226
|
+
const result = await mergeWithGenerated(schema, item, {
|
|
227
|
+
model: config.model,
|
|
228
|
+
system: config.system,
|
|
229
|
+
});
|
|
230
|
+
results.push(result);
|
|
231
|
+
}
|
|
232
|
+
return results;
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=hoc.js.map
|
package/dist/hoc.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hoc.js","sourceRoot":"","sources":["../src/hoc.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAgBjE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,mBAAmB,CACjC,OAA8B;IAE9B,MAAM,EAAE,MAAM,EAAE,QAAQ,GAAG,EAAE,EAAE,QAAQ,GAAG,EAAE,EAAE,OAAO,GAAG,EAAE,EAAE,MAAM,GAAG,EAAE,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAA;IAE7F,OAAO,KAAK,EAAE,YAAwB,EAAc,EAAE;QACpD,IAAI,CAAC;YACH,sBAAsB;YACtB,MAAM,iBAAiB,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,YAAY,EAAE,CAAA;YAE1D,uBAAuB;YACvB,MAAM,eAAe,GAAI,QAAqB,CAAC,MAAM,CACnD,GAAG,CAAC,EAAE,CAAC,iBAAiB,CAAC,GAAc,CAAC,KAAK,SAAS,CACvD,CAAA;YACD,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC/B,MAAM,IAAI,KAAK,CAAC,2BAA2B,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YAC1E,CAAC;YAED,wCAAwC;YACxC,MAAM,cAAc,GAAG,gBAAgB,CAAC,MAAM,EAAE,OAAmB,CAAC,CAAA;YAEpE,yBAAyB;YACzB,OAAO,MAAM,kBAAkB,CAC7B,cAAc,EACd,iBAA+B,EAC/B;gBACE,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,MAAM,EAAE,MAAM,CAAC,MAAM;aACtB,CACF,CA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15 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* ai-props - AI-powered props for intelligent component properties
|
|
3
|
+
*
|
|
4
|
+
* This package provides utilities for automatically generating
|
|
5
|
+
* component props using AI based on schema definitions.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
export * from './types.js';
|
|
10
|
+
export { AI, createAIComponent, definePropsSchema, createComponentFactory, composeAIComponents, } from './ai.js';
|
|
11
|
+
export { generateProps, getPropsSync, prefetchProps, generatePropsMany, mergeWithGenerated, configureAIProps, getConfig, resetConfig, } from './generate.js';
|
|
12
|
+
export { MemoryPropsCache, LRUPropsCache, createCacheKey, getDefaultCache, configureCache, clearCache, DEFAULT_CACHE_TTL, } from './cache.js';
|
|
13
|
+
export { createPropsEnhancer, createAsyncPropsProvider, createPropsTransformer, createConditionalGenerator, createBatchGenerator, type WithAIPropsOptions, } from './hoc.js';
|
|
14
|
+
export { validateProps, hasRequiredProps, getMissingProps, isComplete, getMissingFromSchema, sanitizeProps, mergeWithDefaults, createValidator, assertValidProps, } from './validate.js';
|
|
2
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,cAAc,YAAY,CAAA;AAG1B,OAAO,EACL,EAAE,EACF,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,SAAS,CAAA;AAGhB,OAAO,EACL,aAAa,EACb,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,SAAS,EACT,WAAW,GACZ,MAAM,eAAe,CAAA;AAGtB,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,eAAe,EACf,cAAc,EACd,UAAU,EACV,iBAAiB,GAClB,MAAM,YAAY,CAAA;AAGnB,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,sBAAsB,EACtB,0BAA0B,EAC1B,oBAAoB,EACpB,KAAK,kBAAkB,GACxB,MAAM,UAAU,CAAA;AAGjB,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,gBAAgB,GACjB,MAAM,eAAe,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ai-props - AI-powered props for intelligent component properties
|
|
3
|
+
*
|
|
4
|
+
* This package provides utilities for automatically generating
|
|
5
|
+
* component props using AI based on schema definitions.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
// Export types
|
|
10
|
+
export * from './types.js';
|
|
11
|
+
// Export core functionality
|
|
12
|
+
export { AI, createAIComponent, definePropsSchema, createComponentFactory, composeAIComponents, } from './ai.js';
|
|
13
|
+
// Export generation functions
|
|
14
|
+
export { generateProps, getPropsSync, prefetchProps, generatePropsMany, mergeWithGenerated, configureAIProps, getConfig, resetConfig, } from './generate.js';
|
|
15
|
+
// Export cache utilities
|
|
16
|
+
export { MemoryPropsCache, LRUPropsCache, createCacheKey, getDefaultCache, configureCache, clearCache, DEFAULT_CACHE_TTL, } from './cache.js';
|
|
17
|
+
// Export HOC and enhancers
|
|
18
|
+
export { createPropsEnhancer, createAsyncPropsProvider, createPropsTransformer, createConditionalGenerator, createBatchGenerator, } from './hoc.js';
|
|
19
|
+
// Export validation utilities
|
|
20
|
+
export { validateProps, hasRequiredProps, getMissingProps, isComplete, getMissingFromSchema, sanitizeProps, mergeWithDefaults, createValidator, assertValidProps, } from './validate.js';
|
|
21
|
+
//# sourceMappingURL=index.js.map
|