ai-functions 0.3.0 → 0.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 (400) hide show
  1. package/.turbo/turbo-build.log +5 -0
  2. package/.turbo/turbo-test.log +105 -0
  3. package/README.md +190 -86
  4. package/TODO.md +138 -0
  5. package/dist/ai-promise.d.ts +219 -0
  6. package/dist/ai-promise.d.ts.map +1 -0
  7. package/dist/ai-promise.js +610 -0
  8. package/dist/ai-promise.js.map +1 -0
  9. package/dist/ai.d.ts +285 -0
  10. package/dist/ai.d.ts.map +1 -0
  11. package/dist/ai.js +842 -0
  12. package/dist/ai.js.map +1 -0
  13. package/dist/batch/anthropic.d.ts +23 -0
  14. package/dist/batch/anthropic.d.ts.map +1 -0
  15. package/dist/batch/anthropic.js +257 -0
  16. package/dist/batch/anthropic.js.map +1 -0
  17. package/dist/batch/bedrock.d.ts +64 -0
  18. package/dist/batch/bedrock.d.ts.map +1 -0
  19. package/dist/batch/bedrock.js +586 -0
  20. package/dist/batch/bedrock.js.map +1 -0
  21. package/dist/batch/cloudflare.d.ts +37 -0
  22. package/dist/batch/cloudflare.d.ts.map +1 -0
  23. package/dist/batch/cloudflare.js +289 -0
  24. package/dist/batch/cloudflare.js.map +1 -0
  25. package/dist/batch/google.d.ts +41 -0
  26. package/dist/batch/google.d.ts.map +1 -0
  27. package/dist/batch/google.js +360 -0
  28. package/dist/batch/google.js.map +1 -0
  29. package/dist/batch/index.d.ts +31 -0
  30. package/dist/batch/index.d.ts.map +1 -0
  31. package/dist/batch/index.js +31 -0
  32. package/dist/batch/index.js.map +1 -0
  33. package/dist/batch/memory.d.ts +44 -0
  34. package/dist/batch/memory.d.ts.map +1 -0
  35. package/dist/batch/memory.js +188 -0
  36. package/dist/batch/memory.js.map +1 -0
  37. package/dist/batch/openai.d.ts +37 -0
  38. package/dist/batch/openai.d.ts.map +1 -0
  39. package/dist/batch/openai.js +403 -0
  40. package/dist/batch/openai.js.map +1 -0
  41. package/dist/batch-map.d.ts +125 -0
  42. package/dist/batch-map.d.ts.map +1 -0
  43. package/dist/batch-map.js +406 -0
  44. package/dist/batch-map.js.map +1 -0
  45. package/dist/batch-queue.d.ts +273 -0
  46. package/dist/batch-queue.d.ts.map +1 -0
  47. package/dist/batch-queue.js +271 -0
  48. package/dist/batch-queue.js.map +1 -0
  49. package/dist/context.d.ts +133 -0
  50. package/dist/context.d.ts.map +1 -0
  51. package/dist/context.js +267 -0
  52. package/dist/context.js.map +1 -0
  53. package/dist/embeddings.d.ts +123 -0
  54. package/dist/embeddings.d.ts.map +1 -0
  55. package/dist/embeddings.js +170 -0
  56. package/dist/embeddings.js.map +1 -0
  57. package/dist/eval/index.d.ts +8 -0
  58. package/dist/eval/index.d.ts.map +1 -0
  59. package/dist/eval/index.js +8 -0
  60. package/dist/eval/index.js.map +1 -0
  61. package/dist/eval/models.d.ts +66 -0
  62. package/dist/eval/models.d.ts.map +1 -0
  63. package/dist/eval/models.js +120 -0
  64. package/dist/eval/models.js.map +1 -0
  65. package/dist/eval/runner.d.ts +64 -0
  66. package/dist/eval/runner.d.ts.map +1 -0
  67. package/dist/eval/runner.js +148 -0
  68. package/dist/eval/runner.js.map +1 -0
  69. package/dist/generate.d.ts +168 -0
  70. package/dist/generate.d.ts.map +1 -0
  71. package/dist/generate.js +174 -0
  72. package/dist/generate.js.map +1 -0
  73. package/dist/index.d.ts +29 -4
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +53 -52
  76. package/dist/index.js.map +1 -1
  77. package/dist/primitives.d.ts +292 -0
  78. package/dist/primitives.d.ts.map +1 -0
  79. package/dist/primitives.js +471 -0
  80. package/dist/primitives.js.map +1 -0
  81. package/dist/providers/cloudflare.d.ts +9 -0
  82. package/dist/providers/cloudflare.d.ts.map +1 -0
  83. package/dist/providers/cloudflare.js +9 -0
  84. package/dist/providers/cloudflare.js.map +1 -0
  85. package/dist/providers/index.d.ts +9 -0
  86. package/dist/providers/index.d.ts.map +1 -0
  87. package/dist/providers/index.js +9 -0
  88. package/dist/providers/index.js.map +1 -0
  89. package/dist/schema.d.ts +54 -0
  90. package/dist/schema.d.ts.map +1 -0
  91. package/dist/schema.js +109 -0
  92. package/dist/schema.js.map +1 -0
  93. package/dist/template.d.ts +73 -0
  94. package/dist/template.d.ts.map +1 -0
  95. package/dist/template.js +129 -0
  96. package/dist/template.js.map +1 -0
  97. package/dist/types.d.ts +474 -106
  98. package/dist/types.d.ts.map +1 -1
  99. package/dist/types.js +4 -8
  100. package/dist/types.js.map +1 -1
  101. package/evalite.config.ts +19 -0
  102. package/evals/README.md +212 -0
  103. package/evals/classification.eval.ts +108 -0
  104. package/evals/marketing.eval.ts +370 -0
  105. package/evals/math.eval.ts +94 -0
  106. package/evals/run-evals.ts +166 -0
  107. package/evals/structured-output.eval.ts +143 -0
  108. package/evals/writing.eval.ts +117 -0
  109. package/examples/batch-blog-posts.ts +160 -0
  110. package/package.json +57 -57
  111. package/src/ai-promise.ts +784 -0
  112. package/src/ai.ts +1183 -0
  113. package/src/batch/anthropic.ts +375 -0
  114. package/src/batch/bedrock.ts +801 -0
  115. package/src/batch/cloudflare.ts +421 -0
  116. package/src/batch/google.ts +491 -0
  117. package/src/batch/index.ts +31 -0
  118. package/src/batch/memory.ts +253 -0
  119. package/src/batch/openai.ts +557 -0
  120. package/src/batch-map.ts +534 -0
  121. package/src/batch-queue.ts +493 -0
  122. package/src/context.ts +332 -0
  123. package/src/embeddings.ts +244 -0
  124. package/src/eval/index.ts +8 -0
  125. package/src/eval/models.ts +158 -0
  126. package/src/eval/runner.ts +217 -0
  127. package/src/generate.ts +245 -0
  128. package/src/index.ts +154 -0
  129. package/src/primitives.ts +612 -0
  130. package/src/providers/cloudflare.ts +15 -0
  131. package/src/providers/index.ts +14 -0
  132. package/src/schema.ts +147 -0
  133. package/src/template.ts +209 -0
  134. package/src/types.ts +540 -0
  135. package/test/README.md +105 -0
  136. package/test/ai-proxy.test.ts +192 -0
  137. package/test/async-iterators.test.ts +327 -0
  138. package/test/batch-background.test.ts +482 -0
  139. package/test/batch-blog-posts.test.ts +387 -0
  140. package/test/blog-generation.test.ts +510 -0
  141. package/test/browse-read.test.ts +611 -0
  142. package/test/core-functions.test.ts +694 -0
  143. package/test/decide.test.ts +393 -0
  144. package/test/define.test.ts +274 -0
  145. package/test/e2e-bedrock-manual.ts +163 -0
  146. package/test/e2e-bedrock.test.ts +191 -0
  147. package/test/e2e-flex-gateway.ts +157 -0
  148. package/test/e2e-flex-manual.ts +183 -0
  149. package/test/e2e-flex.test.ts +209 -0
  150. package/test/e2e-google-manual.ts +178 -0
  151. package/test/e2e-google.test.ts +216 -0
  152. package/test/embeddings.test.ts +284 -0
  153. package/test/evals/define-function.eval.test.ts +379 -0
  154. package/test/evals/primitives.eval.test.ts +384 -0
  155. package/test/function-types.test.ts +492 -0
  156. package/test/generate-core.test.ts +319 -0
  157. package/test/generate.test.ts +163 -0
  158. package/test/implicit-batch.test.ts +422 -0
  159. package/test/schema.test.ts +109 -0
  160. package/test/tagged-templates.test.ts +302 -0
  161. package/tsconfig.json +10 -0
  162. package/vitest.config.ts +42 -0
  163. package/LICENSE +0 -21
  164. package/bin/cli.js +0 -5
  165. package/dist/cli/index.d.ts +0 -10
  166. package/dist/cli/index.d.ts.map +0 -1
  167. package/dist/cli/index.js +0 -38
  168. package/dist/cli/index.js.map +0 -1
  169. package/dist/cli/index.test.d.ts +0 -2
  170. package/dist/cli/index.test.d.ts.map +0 -1
  171. package/dist/cli/index.test.js +0 -35
  172. package/dist/cli/index.test.js.map +0 -1
  173. package/dist/constants/models.d.ts +0 -10
  174. package/dist/constants/models.d.ts.map +0 -1
  175. package/dist/constants/models.js +0 -12
  176. package/dist/constants/models.js.map +0 -1
  177. package/dist/converters/index.d.ts +0 -3
  178. package/dist/converters/index.d.ts.map +0 -1
  179. package/dist/converters/index.js +0 -3
  180. package/dist/converters/index.js.map +0 -1
  181. package/dist/converters/model.d.ts +0 -4
  182. package/dist/converters/model.d.ts.map +0 -1
  183. package/dist/converters/model.js +0 -19
  184. package/dist/converters/model.js.map +0 -1
  185. package/dist/converters/schema.d.ts +0 -4
  186. package/dist/converters/schema.d.ts.map +0 -1
  187. package/dist/converters/schema.js +0 -25
  188. package/dist/converters/schema.js.map +0 -1
  189. package/dist/core/responses.d.ts +0 -5
  190. package/dist/core/responses.d.ts.map +0 -1
  191. package/dist/core/responses.js +0 -16
  192. package/dist/core/responses.js.map +0 -1
  193. package/dist/core/responses.test.d.ts +0 -2
  194. package/dist/core/responses.test.d.ts.map +0 -1
  195. package/dist/core/responses.test.js +0 -31
  196. package/dist/core/responses.test.js.map +0 -1
  197. package/dist/errors.d.ts +0 -6
  198. package/dist/errors.d.ts.map +0 -1
  199. package/dist/errors.js +0 -9
  200. package/dist/errors.js.map +0 -1
  201. package/dist/examples/streaming.test.d.ts +0 -2
  202. package/dist/examples/streaming.test.d.ts.map +0 -1
  203. package/dist/examples/streaming.test.js +0 -176
  204. package/dist/examples/streaming.test.js.map +0 -1
  205. package/dist/factory/__tests__/index.test.d.ts +0 -2
  206. package/dist/factory/__tests__/index.test.d.ts.map +0 -1
  207. package/dist/factory/__tests__/index.test.js +0 -430
  208. package/dist/factory/__tests__/index.test.js.map +0 -1
  209. package/dist/factory/__tests__/list.test.d.ts +0 -2
  210. package/dist/factory/__tests__/list.test.d.ts.map +0 -1
  211. package/dist/factory/__tests__/list.test.js +0 -92
  212. package/dist/factory/__tests__/list.test.js.map +0 -1
  213. package/dist/factory/index.d.ts +0 -20
  214. package/dist/factory/index.d.ts.map +0 -1
  215. package/dist/factory/index.js +0 -287
  216. package/dist/factory/index.js.map +0 -1
  217. package/dist/factory/index.test.d.ts +0 -2
  218. package/dist/factory/index.test.d.ts.map +0 -1
  219. package/dist/factory/index.test.js +0 -287
  220. package/dist/factory/index.test.js.map +0 -1
  221. package/dist/factory/list.d.ts +0 -3
  222. package/dist/factory/list.d.ts.map +0 -1
  223. package/dist/factory/list.js +0 -221
  224. package/dist/factory/list.js.map +0 -1
  225. package/dist/factory/list.test.d.ts +0 -2
  226. package/dist/factory/list.test.d.ts.map +0 -1
  227. package/dist/factory/list.test.js +0 -84
  228. package/dist/factory/list.test.js.map +0 -1
  229. package/dist/generate/index.d.ts +0 -5
  230. package/dist/generate/index.d.ts.map +0 -1
  231. package/dist/generate/index.js +0 -17
  232. package/dist/generate/index.js.map +0 -1
  233. package/dist/index.test.d.ts +0 -2
  234. package/dist/index.test.d.ts.map +0 -1
  235. package/dist/index.test.js +0 -59
  236. package/dist/index.test.js.map +0 -1
  237. package/dist/list/await.d.ts +0 -3
  238. package/dist/list/await.d.ts.map +0 -1
  239. package/dist/list/await.js +0 -28
  240. package/dist/list/await.js.map +0 -1
  241. package/dist/list/constants.d.ts +0 -4
  242. package/dist/list/constants.d.ts.map +0 -1
  243. package/dist/list/constants.js +0 -5
  244. package/dist/list/constants.js.map +0 -1
  245. package/dist/list/create-function.d.ts +0 -3
  246. package/dist/list/create-function.d.ts.map +0 -1
  247. package/dist/list/create-function.js +0 -11
  248. package/dist/list/create-function.js.map +0 -1
  249. package/dist/list/index.d.ts +0 -4
  250. package/dist/list/index.d.ts.map +0 -1
  251. package/dist/list/index.js +0 -5
  252. package/dist/list/index.js.map +0 -1
  253. package/dist/list/prompt.d.ts +0 -3
  254. package/dist/list/prompt.d.ts.map +0 -1
  255. package/dist/list/prompt.js +0 -6
  256. package/dist/list/prompt.js.map +0 -1
  257. package/dist/list/schemas.d.ts +0 -4
  258. package/dist/list/schemas.d.ts.map +0 -1
  259. package/dist/list/schemas.js +0 -8
  260. package/dist/list/schemas.js.map +0 -1
  261. package/dist/list/stream.d.ts +0 -3
  262. package/dist/list/stream.d.ts.map +0 -1
  263. package/dist/list/stream.js +0 -33
  264. package/dist/list/stream.js.map +0 -1
  265. package/dist/list/types.d.ts +0 -11
  266. package/dist/list/types.d.ts.map +0 -1
  267. package/dist/list/types.js +0 -2
  268. package/dist/list/types.js.map +0 -1
  269. package/dist/list/validation.d.ts +0 -3
  270. package/dist/list/validation.d.ts.map +0 -1
  271. package/dist/list/validation.js +0 -12
  272. package/dist/list/validation.js.map +0 -1
  273. package/dist/providers/config.d.ts +0 -4
  274. package/dist/providers/config.d.ts.map +0 -1
  275. package/dist/providers/config.js +0 -21
  276. package/dist/providers/config.js.map +0 -1
  277. package/dist/providers/config.test.d.ts +0 -2
  278. package/dist/providers/config.test.d.ts.map +0 -1
  279. package/dist/providers/config.test.js +0 -37
  280. package/dist/providers/config.test.js.map +0 -1
  281. package/dist/proxy/constants.d.ts +0 -4
  282. package/dist/proxy/constants.d.ts.map +0 -1
  283. package/dist/proxy/constants.js +0 -5
  284. package/dist/proxy/constants.js.map +0 -1
  285. package/dist/proxy/create-function.d.ts +0 -4
  286. package/dist/proxy/create-function.d.ts.map +0 -1
  287. package/dist/proxy/create-function.js +0 -24
  288. package/dist/proxy/create-function.js.map +0 -1
  289. package/dist/proxy/create-proxy.d.ts +0 -2
  290. package/dist/proxy/create-proxy.d.ts.map +0 -1
  291. package/dist/proxy/create-proxy.js +0 -11
  292. package/dist/proxy/create-proxy.js.map +0 -1
  293. package/dist/proxy/function-generator.d.ts +0 -9
  294. package/dist/proxy/function-generator.d.ts.map +0 -1
  295. package/dist/proxy/function-generator.js +0 -29
  296. package/dist/proxy/function-generator.js.map +0 -1
  297. package/dist/proxy/index.d.ts +0 -4
  298. package/dist/proxy/index.d.ts.map +0 -1
  299. package/dist/proxy/index.js +0 -4
  300. package/dist/proxy/index.js.map +0 -1
  301. package/dist/proxy/prompt.d.ts +0 -2
  302. package/dist/proxy/prompt.d.ts.map +0 -1
  303. package/dist/proxy/prompt.js +0 -6
  304. package/dist/proxy/prompt.js.map +0 -1
  305. package/dist/proxy/types.d.ts +0 -7
  306. package/dist/proxy/types.d.ts.map +0 -1
  307. package/dist/proxy/types.js +0 -2
  308. package/dist/proxy/types.js.map +0 -1
  309. package/dist/queue/manager.d.ts +0 -5
  310. package/dist/queue/manager.d.ts.map +0 -1
  311. package/dist/queue/manager.js +0 -37
  312. package/dist/queue/manager.js.map +0 -1
  313. package/dist/queue/manager.test.d.ts +0 -2
  314. package/dist/queue/manager.test.d.ts.map +0 -1
  315. package/dist/queue/manager.test.js +0 -52
  316. package/dist/queue/manager.test.js.map +0 -1
  317. package/dist/schema-converter.d.ts +0 -4
  318. package/dist/schema-converter.d.ts.map +0 -1
  319. package/dist/schema-converter.js +0 -30
  320. package/dist/schema-converter.js.map +0 -1
  321. package/dist/stream/index.d.ts +0 -7
  322. package/dist/stream/index.d.ts.map +0 -1
  323. package/dist/stream/index.js +0 -23
  324. package/dist/stream/index.js.map +0 -1
  325. package/dist/streaming/utils.d.ts +0 -4
  326. package/dist/streaming/utils.d.ts.map +0 -1
  327. package/dist/streaming/utils.js +0 -131
  328. package/dist/streaming/utils.js.map +0 -1
  329. package/dist/streaming/utils.test.d.ts +0 -2
  330. package/dist/streaming/utils.test.d.ts.map +0 -1
  331. package/dist/streaming/utils.test.js +0 -84
  332. package/dist/streaming/utils.test.js.map +0 -1
  333. package/dist/templates/result.d.ts +0 -7
  334. package/dist/templates/result.d.ts.map +0 -1
  335. package/dist/templates/result.js +0 -40
  336. package/dist/templates/result.js.map +0 -1
  337. package/dist/templates/result.test.d.ts +0 -2
  338. package/dist/templates/result.test.d.ts.map +0 -1
  339. package/dist/templates/result.test.js +0 -75
  340. package/dist/templates/result.test.js.map +0 -1
  341. package/dist/test/setup.d.ts +0 -2
  342. package/dist/test/setup.d.ts.map +0 -1
  343. package/dist/test/setup.js +0 -21
  344. package/dist/test/setup.js.map +0 -1
  345. package/dist/test-types.d.ts +0 -13
  346. package/dist/test-types.d.ts.map +0 -1
  347. package/dist/test-types.js +0 -55
  348. package/dist/test-types.js.map +0 -1
  349. package/dist/types/index.d.ts +0 -4
  350. package/dist/types/index.d.ts.map +0 -1
  351. package/dist/types/index.js +0 -4
  352. package/dist/types/index.js.map +0 -1
  353. package/dist/types/list.d.ts +0 -10
  354. package/dist/types/list.d.ts.map +0 -1
  355. package/dist/types/list.js +0 -2
  356. package/dist/types/list.js.map +0 -1
  357. package/dist/types/model.d.ts +0 -7
  358. package/dist/types/model.d.ts.map +0 -1
  359. package/dist/types/model.js +0 -2
  360. package/dist/types/model.js.map +0 -1
  361. package/dist/types/options.d.ts +0 -25
  362. package/dist/types/options.d.ts.map +0 -1
  363. package/dist/types/options.js +0 -2
  364. package/dist/types/options.js.map +0 -1
  365. package/dist/types/schema.d.ts +0 -5
  366. package/dist/types/schema.d.ts.map +0 -1
  367. package/dist/types/schema.js +0 -2
  368. package/dist/types/schema.js.map +0 -1
  369. package/dist/utils/__tests__/request-handler.test.d.ts +0 -2
  370. package/dist/utils/__tests__/request-handler.test.d.ts.map +0 -1
  371. package/dist/utils/__tests__/request-handler.test.js +0 -134
  372. package/dist/utils/__tests__/request-handler.test.js.map +0 -1
  373. package/dist/utils/__tests__/schema.test.d.ts +0 -2
  374. package/dist/utils/__tests__/schema.test.d.ts.map +0 -1
  375. package/dist/utils/__tests__/schema.test.js +0 -49
  376. package/dist/utils/__tests__/schema.test.js.map +0 -1
  377. package/dist/utils/__tests__/stream-progress.test.d.ts +0 -2
  378. package/dist/utils/__tests__/stream-progress.test.d.ts.map +0 -1
  379. package/dist/utils/__tests__/stream-progress.test.js +0 -85
  380. package/dist/utils/__tests__/stream-progress.test.js.map +0 -1
  381. package/dist/utils/index.d.ts +0 -2
  382. package/dist/utils/index.d.ts.map +0 -1
  383. package/dist/utils/index.js +0 -2
  384. package/dist/utils/index.js.map +0 -1
  385. package/dist/utils/request-handler.d.ts +0 -17
  386. package/dist/utils/request-handler.d.ts.map +0 -1
  387. package/dist/utils/request-handler.js +0 -105
  388. package/dist/utils/request-handler.js.map +0 -1
  389. package/dist/utils/schema.d.ts +0 -11
  390. package/dist/utils/schema.d.ts.map +0 -1
  391. package/dist/utils/schema.js +0 -51
  392. package/dist/utils/schema.js.map +0 -1
  393. package/dist/utils/stream-progress.d.ts +0 -17
  394. package/dist/utils/stream-progress.d.ts.map +0 -1
  395. package/dist/utils/stream-progress.js +0 -86
  396. package/dist/utils/stream-progress.js.map +0 -1
  397. package/dist/utils/validation.d.ts +0 -3
  398. package/dist/utils/validation.d.ts.map +0 -1
  399. package/dist/utils/validation.js +0 -30
  400. package/dist/utils/validation.js.map +0 -1
@@ -0,0 +1,5 @@
1
+
2
+ 
3
+ > ai-functions@0.4.0 build /Users/nathanclevenger/projects/mdx.org.ai/primitives/packages/ai-functions
4
+ > tsc -p tsconfig.json
5
+
@@ -0,0 +1,105 @@
1
+
2
+ > ai-functions@0.0.1 test /Users/nathanclevenger/projects/mdx.org.ai/primitives/packages/ai-functions
3
+ > vitest
4
+
5
+ [dotenv@17.2.3] injecting env (2) from ../../../.env -- tip: 📡 add observability to secrets: https://dotenvx.com/ops
6
+
7
+ DEV v2.1.9 /Users/nathanclevenger/projects/mdx.org.ai/primitives/packages/ai-functions
8
+
9
+ ✓ test/core-functions.test.ts (38 tests) 11ms
10
+ ✓ test/function-types.test.ts (35 tests) 4ms
11
+ ✓ test/browse-read.test.ts (31 tests) 5ms
12
+ ✓ test/batch-background.test.ts (20 tests) 2ms
13
+ ✓ test/decide.test.ts (15 tests) 2ms
14
+ ✓ test/async-iterators.test.ts (13 tests) 336ms
15
+ ✓ test/generate-core.test.ts (18 tests) 2ms
16
+ ✓ test/tagged-templates.test.ts (19 tests) 3ms
17
+ ✓ test/define.test.ts (18 tests) 955ms
18
+ ✓ generative function execution > executes a generative string function 456ms
19
+ ✓ test/embeddings.test.ts (24 tests | 2 skipped) 36ms
20
+ ✓ test/ai-proxy.test.ts (14 tests) 1585ms
21
+ ✓ ai proxy auto-define > uses cached definition on second call 524ms
22
+ ✓ AI() schema functions > generates nested objects 339ms
23
+ ✓ test/generate.test.ts (9 tests) 1702ms
24
+ ✓ generateText > generates simple text response 323ms
25
+ ✓ test/schema.test.ts (12 tests) 2ms
26
+
27
+ Test Files 13 passed (13)
28
+ Tests 264 passed | 2 skipped (266)
29
+ Start at 14:14:37
30
+ Duration 5.46s (transform 171ms, setup 0ms, collect 351ms, tests 4.65s, environment 0ms, prepare 84ms)
31
+
32
+ PASS Waiting for file changes...
33
+ press h to show help, press q to quit
34
+ c RERUN ../language-models/dist/aliases.js
35
+
36
+ ✓ test/generate.test.ts (9 tests) 1916ms
37
+ ✓ generateObject > generates a simple object with string fields 622ms
38
+ ✓ test/ai-proxy.test.ts (14 tests) 1361ms
39
+ ✓ ai proxy auto-define > uses cached definition on second call 540ms
40
+ ✓ test/define.test.ts (18 tests) 349ms
41
+ ✓ test/embeddings.test.ts (24 tests | 2 skipped) 32ms
42
+ ✓ test/schema.test.ts (12 tests) 1ms
43
+
44
+ Test Files 5 passed (5)
45
+ Tests 75 passed | 2 skipped (77)
46
+ Start at 14:22:55
47
+ Duration 3.99s
48
+
49
+ PASS Waiting for file changes...
50
+ press h to show help, press q to quit
51
+ c RERUN ../language-models/dist/aliases.js
52
+
53
+ ✓ test/generate.test.ts (9 tests) 948ms
54
+ ✓ test/ai-proxy.test.ts (14 tests) 610ms
55
+ ✓ test/define.test.ts (18 tests) 289ms
56
+ ✓ test/embeddings.test.ts (24 tests | 2 skipped) 30ms
57
+ ✓ test/schema.test.ts (12 tests) 1ms
58
+
59
+ Test Files 5 passed (5)
60
+ Tests 75 passed | 2 skipped (77)
61
+ Start at 14:31:30
62
+ Duration 2.00s
63
+
64
+ PASS Waiting for file changes...
65
+ press h to show help, press q to quit
66
+ c RERUN src/index.ts
67
+
68
+ ✓ test/generate.test.ts (9 tests) 2001ms
69
+ ✓ generateObject > generates a simple object with string fields 481ms
70
+ ✓ test/ai-proxy.test.ts (14 tests) 1395ms
71
+ ✓ ai proxy auto-define > auto-defines a function on first call 320ms
72
+ ✓ ai proxy auto-define > uses cached definition on second call 541ms
73
+ ✓ test/define.test.ts (18 tests) 844ms
74
+ ✓ test/embeddings.test.ts (24 tests | 2 skipped) 47ms
75
+ ✓ test/schema.test.ts (12 tests) 1ms
76
+
77
+ Test Files 5 passed (5)
78
+ Tests 75 passed | 2 skipped (77)
79
+ Start at 01:20:37
80
+ Duration 4.50s
81
+
82
+ PASS Waiting for file changes...
83
+ press h to show help, press q to quit
84
+ c RERUN test/implicit-batch.test.ts
85
+
86
+ ✓ test/batch-blog-posts.test.ts (15 tests) 411ms
87
+ ✓ test/implicit-batch.test.ts (26 tests) 4ms
88
+ ✓ test/generate.test.ts (9 tests) 1676ms
89
+ ✓ generateObject > generates a simple object with string fields 498ms
90
+ ✓ test/ai-proxy.test.ts (14 tests) 1328ms
91
+ ✓ ai proxy auto-define > auto-defines a function on first call 380ms
92
+ ✓ ai proxy auto-define > uses cached definition on second call 525ms
93
+ ✓ test/define.test.ts (18 tests) 869ms
94
+ ✓ generative function execution > executes a generative string function 315ms
95
+ ✓ test/embeddings.test.ts (24 tests | 2 skipped) 36ms
96
+ ✓ test/schema.test.ts (12 tests) 1ms
97
+
98
+ Test Files 7 passed (7)
99
+ Tests 116 passed | 2 skipped (118)
100
+ Start at 03:35:28
101
+ Duration 4.48s
102
+
103
+ PASS Waiting for file changes...
104
+ press h to show help, press q to quit
105
+  ELIFECYCLE  Test failed. See above for more details.
package/README.md CHANGED
@@ -1,18 +1,15 @@
1
1
  # ai-functions
2
2
 
3
- [![npm version](https://badge.fury.io/js/ai-functions.svg)](https://www.npmjs.com/package/ai-functions)
4
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
3
+ Call AI like you'd talk to a colleague. No prompts. No configuration. Just say what you need.
5
4
 
6
- A powerful TypeScript library for building AI-powered applications with template literals and structured outputs. Uses `ai` SDK with OpenAI `gpt-4o` by default.
7
-
8
- ## Features
5
+ ```typescript
6
+ import { ai, list, is } from 'ai-functions'
9
7
 
10
- - 🚀 Template literal API for natural AI prompts
11
- - 🔄 Async iterator support for streaming responses
12
- - 📝 Structured output generation with Zod schemas
13
- - 🎯 Type-safe API with full TypeScript support
14
- - ⚡️ Built on `ai` SDK for streaming & object generation
15
- - 🔍 Support for various output formats (objects, arrays, enums)
8
+ // Ask for anything - it reads like English
9
+ const qualified = is`${lead} a good fit for our enterprise plan?`
10
+ const ideas = list`blog posts that would resonate with ${persona}`
11
+ const { summary, nextSteps } = ai`analyze this sales call: ${transcript}`
12
+ ```
16
13
 
17
14
  ## Installation
18
15
 
@@ -20,131 +17,238 @@ A powerful TypeScript library for building AI-powered applications with template
20
17
  pnpm add ai-functions
21
18
  ```
22
19
 
23
- ## Usage
20
+ ## The Magic: Promise Pipelining
24
21
 
25
- ### Basic Template Literals
22
+ Chain operations naturally—no `await` needed until you actually need the result:
26
23
 
27
24
  ```typescript
28
- import { ai, list } from 'ai-functions'
25
+ // Destructure to get exactly what you need
26
+ const { qualified, score, reason } = ai`qualify this lead: ${lead}`
27
+
28
+ // Chain functions together—dependencies resolve automatically
29
+ const followUp = ai`write follow-up email based on: ${reason}`
30
+ const subject = ai`subject line for: ${followUp}`
31
+
32
+ // Only await when you need the actual value
33
+ if (await qualified) {
34
+ await sendEmail({ to: lead.email, subject: await subject, body: await followUp })
35
+ }
36
+ ```
29
37
 
30
- // Simple text generation
31
- const text = ai`write a blog post in markdown starting with '# ${title}'`
38
+ ## Real-World Examples
32
39
 
33
- // Complex objects/arrays dumped to YAML
34
- const summary = ai`Summarize the itinerary: ${itinerary}`
40
+ ### Lead Qualification
35
41
 
36
- // Basic list generation
37
- const things = await list`fun things to do in Miami`
38
- console.log(things)
42
+ ```typescript
43
+ const { score, qualified, reasoning } = ai`
44
+ qualify ${lead} for our product
45
+ considering: ${idealCustomerProfile}
46
+ `
39
47
 
40
- // Using async iterator
41
- for await (const thing of list`fun things to do in Miami`) {
42
- console.log(thing)
48
+ if (await qualified) {
49
+ await assignToSales(lead)
43
50
  }
51
+ ```
44
52
 
45
- // Structured output
46
- const categorizeProduct = ai.categorizeProduct({
47
- productType: 'App | API | Marketplace | Platform | Packaged Service | Professional Service | Website',
48
- customer: 'ideal customer profile in 3-5 words',
49
- solution: 'describe the offer in 4-10 words',
50
- description: 'website meta description',
51
- })
53
+ ### Content Marketing
52
54
 
53
- const product = await categorizeProduct({ domain: name })
55
+ ```typescript
56
+ // Generate topic ideas for your audience
57
+ const topics = list`content ideas for ${persona} in ${industry}`
58
+
59
+ // Evaluate each in parallel—single LLM call!
60
+ const evaluated = await topics.map(topic => ({
61
+ topic,
62
+ potential: is`${topic} would drive signups?`,
63
+ difficulty: ai`content difficulty for: ${topic}`,
64
+ }))
65
+
66
+ // Pick the best
67
+ const winner = evaluated.find(t => t.potential && t.difficulty === 'easy')
54
68
  ```
55
69
 
56
- ### Configuration
70
+ ### Sales Intelligence
57
71
 
58
- #### Specifying the model
72
+ ```typescript
73
+ const { pros, cons, objections } = lists`
74
+ competitive analysis: ${ourProduct} vs ${competitor}
75
+ `
76
+
77
+ const battleCard = ai`
78
+ sales battlecard addressing: ${objections}
79
+ highlighting: ${pros}
80
+ `
81
+ ```
59
82
 
60
- By default `ai-functions` uses the `openai` provider from the `ai` SDK. You can specify any openai model name as a string.
83
+ ### Customer Success
61
84
 
62
85
  ```typescript
63
- const text = ai`write a blog post in markdown starting with "# ${title}"`({ model: 'gpt-4o' })
86
+ // Analyze customer health
87
+ const { healthy, churnRisk, opportunities } = ai`
88
+ analyze customer health for ${customer}
89
+ based on: ${usageData}
90
+ `
91
+
92
+ if (await churnRisk) {
93
+ const outreach = ai`retention outreach for ${customer} addressing ${churnRisk}`
94
+ await scheduleCall(customer, await outreach)
95
+ }
64
96
  ```
65
97
 
66
- Or you can pass in any other provider compatible with the `ai` SDK.
98
+ ### Recruiting
67
99
 
68
100
  ```typescript
69
- import { anthropic } from '@ai-sdk/anthropic'
101
+ const candidates = list`source ${role} candidates from ${jobBoards}`
102
+
103
+ const evaluated = await candidates.map(candidate => ({
104
+ candidate,
105
+ fit: is`${candidate} matches ${requirements}?`,
106
+ summary: ai`one-line summary of ${candidate}`,
107
+ }))
70
108
 
71
- const text = ai`write a function in TypeScript called ${name}`({ model: anthropic('claude-3-5-sonnet-20241022') })
109
+ const shortlist = evaluated.filter(c => c.fit)
72
110
  ```
73
111
 
74
- #### Specifying other options
112
+ ## API Reference
75
113
 
76
- You can pass in any other options supported by the `ai` SDK, like `system`, `temperature`, `maxTokens`, etc.
114
+ ### Generation
77
115
 
78
116
  ```typescript
79
- const things = await list`fun things to do in ${city}`({ system: 'You are an expert tour guide', temperature: 0.2 })
117
+ ai`anything you need` // flexible object/text
118
+ write`blog post about ${topic}` // long-form content
119
+ summarize`${document}` // condense to key points
120
+ list`ideas for ${topic}` // array of items
121
+ lists`pros and cons of ${topic}` // named lists
122
+ extract`emails from ${text}` // structured extraction
80
123
  ```
81
124
 
82
- ### Composable Functions & Workflows
125
+ ### Classification
83
126
 
84
127
  ```typescript
85
- const listBlogPosts = (count, topic) => list`${count} blog post titles about ${topic}`
86
- const writeBlogPost = (title) => ai`write a blog post in markdown starting with '# ${title}'`
128
+ is`${email} spam?` // boolean
129
+ decide`which converts better?`(optionA, optionB) // pick best
130
+ ```
87
131
 
88
- async function* writeBlog(count, topic) {
89
- for await (const title of listBlogPosts(count, topic)) {
90
- const content = await writeBlogPost(title)
91
- yield { title, content }
92
- }
93
- }
132
+ ### Code & Visuals
94
133
 
95
- for await (const post of writeBlog(25, 'future of car sales')) {
96
- console.log({ post })
97
- }
134
+ ```typescript
135
+ code`email validation function` // generate code
136
+ diagram`user flow for ${feature}` // mermaid diagrams
137
+ slides`pitch deck for ${startup}` // presentations
138
+ image`hero image for ${brand}` // image generation
139
+ ```
140
+
141
+ ### Research & Web
142
+
143
+ ```typescript
144
+ research`${competitor} market position` // web research
145
+ read`${url}` // url to markdown
146
+ browse`${url}` // browser automation
147
+ ```
148
+
149
+ ### Human-in-the-Loop
150
+
151
+ ```typescript
152
+ ask`what's the priority for ${feature}?` // free-form input
153
+ approve`deploy ${version} to production?` // yes/no approval
154
+ review`${document}` // detailed feedback
98
155
  ```
99
156
 
100
- ### Concurrency
157
+ ## The `lists` Function
101
158
 
102
- you can specify the `concurrency` option to limit the number of concurrent requests.
159
+ Get exactly what you ask for through destructuring:
103
160
 
104
161
  ```typescript
105
- activities.map(async (activity) => {
106
- const result = await ai`write a paragraph overview of ${activity}`({ concurrency: 5 })
107
- })
162
+ // Just name what you want—the schema is inferred!
163
+ const { pros, cons } = lists`pros and cons of ${decision}`
164
+ const { strengths, weaknesses, opportunities, threats } = lists`SWOT for ${company}`
165
+ const { mustHave, niceToHave, outOfScope } = lists`requirements for ${feature}`
108
166
  ```
109
167
 
110
- ## Development
168
+ ## Batch Processing with `.map()`
111
169
 
112
- ```bash
113
- # Install dependencies
114
- pnpm install
170
+ Process arrays in a single LLM call:
115
171
 
116
- # Run tests
117
- pnpm test
172
+ ```typescript
173
+ const leads = await list`leads from ${campaign}`
174
+
175
+ // Each field evaluated for each lead—all in ONE call
176
+ const qualified = await leads.map(lead => ({
177
+ lead,
178
+ score: ai`score 1-100: ${lead}`,
179
+ qualified: is`${lead} matches ${icp}?`,
180
+ nextStep: ai`recommended action for ${lead}`,
181
+ }))
182
+
183
+ // Filter and act
184
+ qualified
185
+ .filter(l => l.qualified)
186
+ .forEach(l => createTask(l.nextStep))
187
+ ```
118
188
 
119
- # Run tests in watch mode
120
- pnpm test:watch
189
+ ## Typed Schemas with `AI()`
121
190
 
122
- # Build the package
123
- pnpm build
191
+ For reusable, typed functions:
124
192
 
125
- # Lint the code
126
- pnpm lint
193
+ ```typescript
194
+ const ai = AI({
195
+ qualifyLead: {
196
+ score: 'Lead score 1-100 (number)',
197
+ qualified: 'Whether to pursue (boolean)',
198
+ reasoning: 'Explanation of score',
199
+ nextSteps: ['Recommended actions'],
200
+ },
201
+
202
+ analyzeCompetitor: {
203
+ positioning: 'How they position themselves',
204
+ strengths: ['Their advantages'],
205
+ weaknesses: ['Their disadvantages'],
206
+ battleCard: 'Key talking points for sales',
207
+ },
208
+ })
127
209
 
128
- # Format the code
129
- pnpm format
210
+ // Fully typed!
211
+ const result = await ai.qualifyLead('Enterprise CTO interested in AI automation')
212
+ result.score // number
213
+ result.qualified // boolean
214
+ result.nextSteps // string[]
130
215
  ```
131
216
 
132
- ## Contributing
217
+ ## Schema Syntax
218
+
219
+ | Syntax | Type | Example |
220
+ |--------|------|---------|
221
+ | `'description'` | string | `name: 'Company name'` |
222
+ | `'desc (number)'` | number | `score: 'Score 1-100 (number)'` |
223
+ | `'desc (boolean)'` | boolean | `qualified: 'Pursue? (boolean)'` |
224
+ | `'opt1 \| opt2'` | enum | `priority: 'high \| medium \| low'` |
225
+ | `['description']` | array | `steps: ['Action items']` |
226
+ | `{ nested }` | object | `contact: { name, email }` |
227
+
228
+ ## Philosophy
133
229
 
134
- Please read our [Contributing Guide](./CONTRIBUTING.md) to learn about our development process and how to propose bugfixes and improvements.
230
+ **Code should read like conversation.**
135
231
 
136
- ## License
232
+ Compare:
233
+ ```typescript
234
+ // Traditional AI code
235
+ const response = await openai.chat.completions.create({
236
+ model: "gpt-4",
237
+ messages: [{ role: "user", content: `Analyze this lead: ${JSON.stringify(lead)}` }],
238
+ response_format: { type: "json_object" },
239
+ })
240
+ const result = JSON.parse(response.choices[0].message.content)
241
+ ```
137
242
 
138
- MIT © [Drivly](https://driv.ly)
243
+ ```typescript
244
+ // ai-functions
245
+ const { qualified, score, nextStep } = ai`analyze lead: ${lead}`
246
+ ```
139
247
 
140
- ## Dependencies
248
+ The second version is what you'd say to a colleague. That's the goal.
141
249
 
142
- This package uses the following key dependencies:
250
+ ## Related Packages
143
251
 
144
- - `ai` SDK for AI model integration
145
- - Defaults to `@ai-sdk/openai` provider
146
- - TypeScript for static typing
147
- - Zod for schema validation
148
- - Vitest for testing
149
- - ESLint for linting
150
- - Prettier for code formatting
252
+ - [`ai-database`](../ai-database) AI-powered database operations
253
+ - [`ai-providers`](../ai-providers) — Model provider abstraction
254
+ - [`language-models`](../language-models) Model definitions
package/TODO.md ADDED
@@ -0,0 +1,138 @@
1
+ # ai-functions TODO
2
+
3
+ Changes from README that need implementation in tests/code.
4
+
5
+ ## Function Types System
6
+
7
+ - [ ] Implement 4 function types: `Generative`, `Code`, `Agentic`, `Human`
8
+ - [ ] Type inference from function name + argument names + argument values
9
+ - [ ] Subjective judgment (e.g., `processRefund({ amount: 12.99 })` vs `amount: 50000`)
10
+
11
+ ## Core Architecture
12
+
13
+ - [ ] `generate(type, prompt, opts?)` as the core primitive
14
+ - [ ] Types: `json`, `text`, `code`, `list`, `extract`, `summary`, `diagram`, `slides`, `markdown`, `yaml`, `xml`
15
+ - [ ] Schema support for `json` type
16
+ - [ ] All other functions call `generate` under the hood
17
+ - [ ] `define(name, schema)` - foundation function
18
+ - [ ] Infers function type from name + args
19
+ - [ ] Creates appropriate function (Generative, Code, Agentic, Human)
20
+ - [ ] Caches definition for subsequent calls
21
+ - [ ] `AI({ schemas })` factory for typed instances
22
+
23
+ ## Tagged Template Support
24
+
25
+ - [ ] Every function supports tagged template syntax
26
+ - [ ] Objects/arrays in templates auto-stringify to YAML
27
+ - [ ] Template + options chaining: ``fn`prompt`({ model: '...' })``
28
+
29
+ ## Standalone Exports
30
+
31
+ All functions exported directly (not just on `ai` object):
32
+
33
+ - [ ] `ai` - text generation
34
+ - [ ] `summarize` - condense text
35
+ - [ ] `do` - single-pass task executor with tools (not agentic loop)
36
+ - [ ] `is` - boolean classification
37
+ - [ ] `list` - generate list
38
+ - [ ] `lists` - multiple named lists
39
+ - [ ] `extract` - extract from text
40
+ - [ ] `write` - generate content
41
+ - [ ] `generate` - core primitive
42
+ - [ ] `decide` - LLM as judge, picks from options
43
+ - [ ] `code` - generate code
44
+ - [ ] `diagram` - generate diagrams (mermaid, etc.)
45
+ - [ ] `slides` - generate presentations (slidev, marp, reveal.js)
46
+ - [ ] `image` - generate images
47
+ - [ ] `video` - generate videos
48
+ - [ ] `research` - agentic research
49
+ - [ ] `read` - URL to markdown (Firecrawl)
50
+ - [ ] `browse` - browser automation (Stagehand/Browserbase)
51
+ - [ ] `page.extract` - extract data from page
52
+ - [ ] `page.do` - perform action on page
53
+
54
+ ## Magic Proxy (`ai.*`)
55
+
56
+ - [ ] `ai.anyFunctionName(args)` auto-defines on first call
57
+ - [ ] Infers function type from name + args
58
+ - [ ] Examples:
59
+ - [ ] `ai.fizzBuzz()` → CodeFunction
60
+ - [ ] `ai.storyBrand()` → GenerativeFunction with schema
61
+ - [ ] `ai.launchProductHunt()` → AgenticFunction
62
+ - [ ] `ai.approveExpense()` → HumanFunction
63
+
64
+ ## Human Functions
65
+
66
+ - [ ] `ask` - ask human a question
67
+ - [ ] `approve` - request human approval
68
+ - [ ] `review` - request human review
69
+ - [ ] Integration with `human-in-the-loop`, `digital-workers`, `autonomous-agents` packages
70
+
71
+ ## Async Iterators
72
+
73
+ - [ ] `list` returns `AsyncIterable` for streaming
74
+ - [ ] `extract` returns `AsyncIterable` for streaming
75
+ - [ ] `for await (const item of list`...`)` pattern
76
+ - [ ] Early termination with `break`
77
+
78
+ ## `decide` - LLM as Judge
79
+
80
+ - [ ] Syntax: ``decide`criteria`(optionA, optionB, ...)``
81
+ - [ ] Returns the winning option (same type as inputs)
82
+ - [ ] Type-safe: passing `Product` objects returns `Product`
83
+
84
+ ## Options Parameter
85
+
86
+ Every function accepts options as last parameter:
87
+
88
+ - [ ] `model` - model selection
89
+ - [ ] `thinking` - `'low' | 'medium' | 'high' | number` (token budget)
90
+ - [ ] `temperature`
91
+ - [ ] `maxTokens`
92
+
93
+ ## Batch & Background Processing
94
+
95
+ - [ ] Background mode: `{ mode: 'background' }` returns job immediately
96
+ - [ ] `job.result()` to get result later
97
+ - [ ] `job.status` for status
98
+ - [ ] Batch mode: `fn.batch([contexts])`
99
+ - [ ] Better pricing (50% off on OpenAI)
100
+ - [ ] Processes all at once
101
+ - [ ] Batch streaming: `fn.batch.stream([contexts])`
102
+ - [ ] `for await` as results complete
103
+
104
+ ## Integration with Other Packages
105
+
106
+ - [ ] `ai-sandbox` - `evaluate({ code, tests, module, script })` for CodeFunctions
107
+ - [ ] `ai-database` - `embed` moved there, used by `db.search()`
108
+ - [ ] `ai-providers` / `language-models` - model resolution
109
+ - [ ] `human-in-the-loop` - Human function implementation
110
+ - [ ] `autonomous-agents` - Agent loop (vs single-pass `do`)
111
+
112
+ ## Type System
113
+
114
+ - [ ] `AIFunction<TArgs, TReturn>` - callable + tagged template
115
+ - [ ] Schema syntax parsing:
116
+ - [ ] `'description'` → string
117
+ - [ ] `'desc (number)'` → number
118
+ - [ ] `'desc (boolean)'` → boolean
119
+ - [ ] `'opt1 | opt2'` → enum
120
+ - [ ] `['description']` → array
121
+ - [ ] `{ nested }` → object
122
+ - [ ] Type inference for `AI()` factory schemas
123
+
124
+ ## Tests to Write
125
+
126
+ - [ ] Tagged template parsing and YAML conversion
127
+ - [ ] Each function type (Generative, Code, Agentic, Human)
128
+ - [ ] Function type inference from name + args
129
+ - [ ] `generate` with all type options
130
+ - [ ] `define` creating correct function types
131
+ - [ ] Magic proxy auto-definition
132
+ - [ ] Async iterators on `list` and `extract`
133
+ - [ ] `decide` returning correct option
134
+ - [ ] Batch and background modes
135
+ - [ ] Options parameter (model, thinking, etc.)
136
+ - [ ] `browse` with `page.extract` and `page.do`
137
+ - [ ] `read` URL fetching
138
+ - [ ] `research` agentic flow