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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-props",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "AI-powered props primitives for intelligent component properties",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -9,14 +9,48 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"import": "./dist/index.js",
|
|
11
11
|
"types": "./dist/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"./worker": {
|
|
14
|
+
"import": "./dist/worker.js",
|
|
15
|
+
"types": "./dist/worker.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"./mdx": {
|
|
18
|
+
"import": "./dist/mdx.js",
|
|
19
|
+
"types": "./dist/mdx.d.ts"
|
|
20
|
+
},
|
|
21
|
+
"./streaming": {
|
|
22
|
+
"import": "./dist/streaming.js",
|
|
23
|
+
"types": "./dist/streaming.d.ts"
|
|
24
|
+
},
|
|
25
|
+
"./rpc": {
|
|
26
|
+
"import": "./dist/rpc.js",
|
|
27
|
+
"types": "./dist/rpc.d.ts"
|
|
28
|
+
},
|
|
29
|
+
"./client": {
|
|
30
|
+
"import": "./dist/client.js",
|
|
31
|
+
"types": "./dist/client.d.ts"
|
|
12
32
|
}
|
|
13
33
|
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsc",
|
|
36
|
+
"dev": "tsc --watch",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"test:worker": "vitest --config vitest.workers.config.ts",
|
|
39
|
+
"typecheck": "tsc --noEmit",
|
|
40
|
+
"lint": "eslint .",
|
|
41
|
+
"clean": "rm -rf dist"
|
|
42
|
+
},
|
|
14
43
|
"dependencies": {
|
|
15
|
-
"ai-functions": "2.
|
|
44
|
+
"ai-functions": "2.4.0",
|
|
45
|
+
"ai-providers": "2.4.0",
|
|
46
|
+
"language-models": "2.4.0",
|
|
47
|
+
"hono": "^4.0.0"
|
|
16
48
|
},
|
|
17
49
|
"devDependencies": {
|
|
50
|
+
"@cloudflare/vitest-pool-workers": "^0.8.0",
|
|
51
|
+
"@cloudflare/workers-types": "^4.20250109.0",
|
|
18
52
|
"typescript": "^5.7.2",
|
|
19
|
-
"vitest": "
|
|
53
|
+
"vitest": "3.0.4"
|
|
20
54
|
},
|
|
21
55
|
"keywords": [
|
|
22
56
|
"ai",
|
|
@@ -24,13 +58,5 @@
|
|
|
24
58
|
"react",
|
|
25
59
|
"primitives"
|
|
26
60
|
],
|
|
27
|
-
"license": "MIT"
|
|
28
|
-
|
|
29
|
-
"build": "tsc",
|
|
30
|
-
"dev": "tsc --watch",
|
|
31
|
-
"test": "vitest",
|
|
32
|
-
"typecheck": "tsc --noEmit",
|
|
33
|
-
"lint": "eslint .",
|
|
34
|
-
"clean": "rm -rf dist"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
61
|
+
"license": "MIT"
|
|
62
|
+
}
|
package/src/ai.ts
CHANGED
|
@@ -8,12 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { SimpleSchema } from 'ai-functions'
|
|
11
|
-
import type {
|
|
12
|
-
PropSchema,
|
|
13
|
-
AIComponentOptions,
|
|
14
|
-
AIComponent,
|
|
15
|
-
AIPropsConfig,
|
|
16
|
-
} from './types.js'
|
|
11
|
+
import type { PropSchema, AIComponentOptions, AIComponent, AIPropsConfig } from './types.js'
|
|
17
12
|
import { generateProps, mergeWithGenerated } from './generate.js'
|
|
18
13
|
|
|
19
14
|
/**
|
|
@@ -59,23 +54,17 @@ export function AI<P extends Record<string, unknown>>(
|
|
|
59
54
|
|
|
60
55
|
// Check if all required props are provided
|
|
61
56
|
const missingRequired = (required as string[]).filter(
|
|
62
|
-
key => propsWithDefaults[key as keyof P] === undefined
|
|
57
|
+
(key) => propsWithDefaults[key as keyof P] === undefined
|
|
63
58
|
)
|
|
64
59
|
if (missingRequired.length > 0) {
|
|
65
|
-
throw new Error(
|
|
66
|
-
`Missing required props: ${missingRequired.join(', ')}`
|
|
67
|
-
)
|
|
60
|
+
throw new Error(`Missing required props: ${missingRequired.join(', ')}`)
|
|
68
61
|
}
|
|
69
62
|
|
|
70
63
|
// Generate missing props
|
|
71
|
-
const fullProps = await mergeWithGenerated<P>(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
model: config.model,
|
|
76
|
-
system: config.system,
|
|
77
|
-
}
|
|
78
|
-
)
|
|
64
|
+
const fullProps = await mergeWithGenerated<P>(filteredSchema, propsWithDefaults as Partial<P>, {
|
|
65
|
+
...(config.model !== undefined && { model: config.model }),
|
|
66
|
+
...(config.system !== undefined && { system: config.system }),
|
|
67
|
+
})
|
|
79
68
|
|
|
80
69
|
return fullProps
|
|
81
70
|
}
|
|
@@ -145,9 +134,7 @@ export function createAIComponent<P extends Record<string, unknown>>(
|
|
|
145
134
|
* })
|
|
146
135
|
* ```
|
|
147
136
|
*/
|
|
148
|
-
export function definePropsSchema<T extends Record<string, string | SimpleSchema>>(
|
|
149
|
-
schema: T
|
|
150
|
-
): T {
|
|
137
|
+
export function definePropsSchema<T extends Record<string, string | SimpleSchema>>(schema: T): T {
|
|
151
138
|
return schema
|
|
152
139
|
}
|
|
153
140
|
|
|
@@ -185,16 +172,13 @@ export function createComponentFactory<P extends Record<string, unknown>>(
|
|
|
185
172
|
* Generate multiple instances
|
|
186
173
|
*/
|
|
187
174
|
generateMany: async (contexts: Partial<P>[]): Promise<P[]> => {
|
|
188
|
-
return Promise.all(contexts.map(ctx => component(ctx)))
|
|
175
|
+
return Promise.all(contexts.map((ctx) => component(ctx)))
|
|
189
176
|
},
|
|
190
177
|
|
|
191
178
|
/**
|
|
192
179
|
* Generate with specific overrides
|
|
193
180
|
*/
|
|
194
|
-
generateWith: async (
|
|
195
|
-
context: Partial<P>,
|
|
196
|
-
overrides: Partial<P>
|
|
197
|
-
): Promise<P> => {
|
|
181
|
+
generateWith: async (context: Partial<P>, overrides: Partial<P>): Promise<P> => {
|
|
198
182
|
const generated = await component(context)
|
|
199
183
|
return { ...generated, ...overrides }
|
|
200
184
|
},
|
|
@@ -232,9 +216,7 @@ export function composeAIComponents<
|
|
|
232
216
|
[K in keyof T]: T[K] extends AIComponentOptions<infer P> ? P : never
|
|
233
217
|
}
|
|
234
218
|
|
|
235
|
-
const aiComponent = async (
|
|
236
|
-
partialProps: Partial<ResultProps>
|
|
237
|
-
): Promise<ResultProps> => {
|
|
219
|
+
const aiComponent = async (partialProps: Partial<ResultProps>): Promise<ResultProps> => {
|
|
238
220
|
const results: Record<string, unknown> = {}
|
|
239
221
|
|
|
240
222
|
// Generate each component's props
|
|
@@ -257,8 +239,7 @@ export function composeAIComponents<
|
|
|
257
239
|
|
|
258
240
|
aiComponent.schema = composedSchema as PropSchema
|
|
259
241
|
aiComponent.config = {}
|
|
260
|
-
aiComponent.generateProps = (context?: Partial<ResultProps>) =>
|
|
261
|
-
aiComponent(context || {})
|
|
242
|
+
aiComponent.generateProps = (context?: Partial<ResultProps>) => aiComponent(context || {})
|
|
262
243
|
|
|
263
244
|
return aiComponent as AIComponent<ResultProps>
|
|
264
245
|
}
|