ai-functions 2.1.1 → 2.3.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 (286) hide show
  1. package/.turbo/turbo-build.log +1 -4
  2. package/CHANGELOG.md +68 -1
  3. package/README.md +397 -157
  4. package/dist/ai-promise.d.ts +50 -3
  5. package/dist/ai-promise.d.ts.map +1 -1
  6. package/dist/ai-promise.js +410 -51
  7. package/dist/ai-promise.js.map +1 -1
  8. package/dist/ai-schemas.d.ts +56 -0
  9. package/dist/ai-schemas.d.ts.map +1 -0
  10. package/dist/ai-schemas.js +53 -0
  11. package/dist/ai-schemas.js.map +1 -0
  12. package/dist/ai.d.ts +16 -242
  13. package/dist/ai.d.ts.map +1 -1
  14. package/dist/ai.js +54 -837
  15. package/dist/ai.js.map +1 -1
  16. package/dist/batch/anthropic.d.ts +6 -4
  17. package/dist/batch/anthropic.d.ts.map +1 -1
  18. package/dist/batch/anthropic.js +83 -145
  19. package/dist/batch/anthropic.js.map +1 -1
  20. package/dist/batch/bedrock.d.ts +8 -30
  21. package/dist/batch/bedrock.d.ts.map +1 -1
  22. package/dist/batch/bedrock.js +155 -338
  23. package/dist/batch/bedrock.js.map +1 -1
  24. package/dist/batch/cloudflare.d.ts +8 -20
  25. package/dist/batch/cloudflare.d.ts.map +1 -1
  26. package/dist/batch/cloudflare.js +68 -189
  27. package/dist/batch/cloudflare.js.map +1 -1
  28. package/dist/batch/google.d.ts +6 -20
  29. package/dist/batch/google.d.ts.map +1 -1
  30. package/dist/batch/google.js +70 -238
  31. package/dist/batch/google.js.map +1 -1
  32. package/dist/batch/index.d.ts +4 -1
  33. package/dist/batch/index.d.ts.map +1 -1
  34. package/dist/batch/index.js +4 -1
  35. package/dist/batch/index.js.map +1 -1
  36. package/dist/batch/memory.d.ts +1 -1
  37. package/dist/batch/memory.d.ts.map +1 -1
  38. package/dist/batch/memory.js +14 -10
  39. package/dist/batch/memory.js.map +1 -1
  40. package/dist/batch/openai.d.ts +11 -14
  41. package/dist/batch/openai.d.ts.map +1 -1
  42. package/dist/batch/openai.js +52 -156
  43. package/dist/batch/openai.js.map +1 -1
  44. package/dist/batch/provider.d.ts +111 -0
  45. package/dist/batch/provider.d.ts.map +1 -0
  46. package/dist/batch/provider.js +233 -0
  47. package/dist/batch/provider.js.map +1 -0
  48. package/dist/batch-map.d.ts.map +1 -1
  49. package/dist/batch-map.js +23 -17
  50. package/dist/batch-map.js.map +1 -1
  51. package/dist/batch-queue.d.ts +65 -0
  52. package/dist/batch-queue.d.ts.map +1 -1
  53. package/dist/batch-queue.js +169 -14
  54. package/dist/batch-queue.js.map +1 -1
  55. package/dist/budget.d.ts +272 -0
  56. package/dist/budget.d.ts.map +1 -0
  57. package/dist/budget.js +513 -0
  58. package/dist/budget.js.map +1 -0
  59. package/dist/cache.d.ts +295 -0
  60. package/dist/cache.d.ts.map +1 -0
  61. package/dist/cache.js +433 -0
  62. package/dist/cache.js.map +1 -0
  63. package/dist/context.d.ts +42 -8
  64. package/dist/context.d.ts.map +1 -1
  65. package/dist/context.js +64 -62
  66. package/dist/context.js.map +1 -1
  67. package/dist/digital-objects-registry.d.ts +229 -0
  68. package/dist/digital-objects-registry.d.ts.map +1 -0
  69. package/dist/digital-objects-registry.js +617 -0
  70. package/dist/digital-objects-registry.js.map +1 -0
  71. package/dist/embeddings.d.ts +2 -2
  72. package/dist/embeddings.d.ts.map +1 -1
  73. package/dist/errors.d.ts +22 -0
  74. package/dist/errors.d.ts.map +1 -0
  75. package/dist/errors.js +35 -0
  76. package/dist/errors.js.map +1 -0
  77. package/dist/eval/runner.d.ts +10 -1
  78. package/dist/eval/runner.d.ts.map +1 -1
  79. package/dist/eval/runner.js +41 -35
  80. package/dist/eval/runner.js.map +1 -1
  81. package/dist/eval-log/in-memory.d.ts +34 -0
  82. package/dist/eval-log/in-memory.d.ts.map +1 -0
  83. package/dist/eval-log/in-memory.js +84 -0
  84. package/dist/eval-log/in-memory.js.map +1 -0
  85. package/dist/eval-log/index.d.ts +29 -0
  86. package/dist/eval-log/index.d.ts.map +1 -0
  87. package/dist/eval-log/index.js +39 -0
  88. package/dist/eval-log/index.js.map +1 -0
  89. package/dist/eval-log/types.d.ts +101 -0
  90. package/dist/eval-log/types.d.ts.map +1 -0
  91. package/dist/eval-log/types.js +16 -0
  92. package/dist/eval-log/types.js.map +1 -0
  93. package/dist/function-registry.d.ts +116 -0
  94. package/dist/function-registry.d.ts.map +1 -0
  95. package/dist/function-registry.js +546 -0
  96. package/dist/function-registry.js.map +1 -0
  97. package/dist/generate.d.ts +9 -3
  98. package/dist/generate.d.ts.map +1 -1
  99. package/dist/generate.js +18 -22
  100. package/dist/generate.js.map +1 -1
  101. package/dist/index.d.ts +35 -20
  102. package/dist/index.d.ts.map +1 -1
  103. package/dist/index.js +89 -42
  104. package/dist/index.js.map +1 -1
  105. package/dist/logger.d.ts +118 -0
  106. package/dist/logger.d.ts.map +1 -0
  107. package/dist/logger.js +187 -0
  108. package/dist/logger.js.map +1 -0
  109. package/dist/middleware/budget.d.ts +84 -0
  110. package/dist/middleware/budget.d.ts.map +1 -0
  111. package/dist/middleware/budget.js +110 -0
  112. package/dist/middleware/budget.js.map +1 -0
  113. package/dist/middleware/cache.d.ts +103 -0
  114. package/dist/middleware/cache.d.ts.map +1 -0
  115. package/dist/middleware/cache.js +228 -0
  116. package/dist/middleware/cache.js.map +1 -0
  117. package/dist/middleware/embed-cache.d.ts +99 -0
  118. package/dist/middleware/embed-cache.d.ts.map +1 -0
  119. package/dist/middleware/embed-cache.js +128 -0
  120. package/dist/middleware/embed-cache.js.map +1 -0
  121. package/dist/middleware/index.d.ts +11 -0
  122. package/dist/middleware/index.d.ts.map +1 -0
  123. package/dist/middleware/index.js +11 -0
  124. package/dist/middleware/index.js.map +1 -0
  125. package/dist/middleware/trace.d.ts +103 -0
  126. package/dist/middleware/trace.d.ts.map +1 -0
  127. package/dist/middleware/trace.js +176 -0
  128. package/dist/middleware/trace.js.map +1 -0
  129. package/dist/primitives.d.ts +120 -1
  130. package/dist/primitives.d.ts.map +1 -1
  131. package/dist/primitives.js +398 -26
  132. package/dist/primitives.js.map +1 -1
  133. package/dist/retry.d.ts +368 -0
  134. package/dist/retry.d.ts.map +1 -0
  135. package/dist/retry.js +646 -0
  136. package/dist/retry.js.map +1 -0
  137. package/dist/schema.d.ts.map +1 -1
  138. package/dist/schema.js +2 -10
  139. package/dist/schema.js.map +1 -1
  140. package/dist/telemetry.d.ts +128 -0
  141. package/dist/telemetry.d.ts.map +1 -0
  142. package/dist/telemetry.js +285 -0
  143. package/dist/telemetry.js.map +1 -0
  144. package/dist/template.d.ts.map +1 -1
  145. package/dist/template.js +6 -1
  146. package/dist/template.js.map +1 -1
  147. package/dist/tool-orchestration.d.ts +453 -0
  148. package/dist/tool-orchestration.d.ts.map +1 -0
  149. package/dist/tool-orchestration.js +763 -0
  150. package/dist/tool-orchestration.js.map +1 -0
  151. package/dist/type-guards.d.ts +28 -0
  152. package/dist/type-guards.d.ts.map +1 -0
  153. package/dist/type-guards.js +29 -0
  154. package/dist/type-guards.js.map +1 -0
  155. package/dist/types.d.ts +135 -17
  156. package/dist/types.d.ts.map +1 -1
  157. package/dist/types.js +36 -1
  158. package/dist/types.js.map +1 -1
  159. package/dist/wrap-for-v3.d.ts +80 -0
  160. package/dist/wrap-for-v3.d.ts.map +1 -0
  161. package/dist/wrap-for-v3.js +89 -0
  162. package/dist/wrap-for-v3.js.map +1 -0
  163. package/examples/00-quickstart.ts +232 -0
  164. package/examples/01-rag-chatbot.ts +212 -0
  165. package/examples/02-multi-agent-research.ts +290 -0
  166. package/examples/03-email-classification.ts +379 -0
  167. package/examples/04-content-moderation.ts +400 -0
  168. package/examples/05-document-extraction.ts +455 -0
  169. package/examples/06-streaming-chat-nextjs.ts +437 -0
  170. package/examples/07-cloudflare-worker.ts +483 -0
  171. package/examples/08-batch-processing.ts +491 -0
  172. package/examples/09-budget-constrained.ts +527 -0
  173. package/examples/10-tool-orchestration.ts +565 -0
  174. package/examples/11-retry-resilience.ts +403 -0
  175. package/examples/12-caching-strategies.ts +422 -0
  176. package/examples/README.md +145 -0
  177. package/package.json +10 -6
  178. package/src/ai-promise.ts +528 -99
  179. package/src/ai-schemas.ts +122 -0
  180. package/src/ai.ts +69 -1153
  181. package/src/batch/anthropic.ts +96 -161
  182. package/src/batch/bedrock.ts +203 -454
  183. package/src/batch/cloudflare.ts +99 -282
  184. package/src/batch/google.ts +91 -297
  185. package/src/batch/index.ts +4 -1
  186. package/src/batch/memory.ts +15 -10
  187. package/src/batch/openai.ts +65 -193
  188. package/src/batch/provider.ts +336 -0
  189. package/src/batch-map.ts +29 -24
  190. package/src/batch-queue.ts +200 -11
  191. package/src/budget.ts +740 -0
  192. package/src/cache.ts +681 -0
  193. package/src/context.ts +122 -76
  194. package/src/digital-objects-registry.ts +750 -0
  195. package/src/errors.ts +37 -0
  196. package/src/eval/runner.ts +63 -38
  197. package/src/eval-log/in-memory.ts +90 -0
  198. package/src/eval-log/index.ts +46 -0
  199. package/src/eval-log/types.ts +110 -0
  200. package/src/function-registry.ts +671 -0
  201. package/src/generate.ts +33 -33
  202. package/src/index.ts +325 -49
  203. package/src/logger.ts +232 -0
  204. package/src/middleware/budget.ts +171 -0
  205. package/src/middleware/cache.ts +299 -0
  206. package/src/middleware/embed-cache.ts +195 -0
  207. package/src/middleware/index.ts +23 -0
  208. package/src/middleware/trace.ts +248 -0
  209. package/src/primitives.ts +589 -62
  210. package/src/retry.ts +902 -0
  211. package/src/schema.ts +8 -17
  212. package/src/telemetry.ts +403 -0
  213. package/src/template.ts +8 -4
  214. package/src/tool-orchestration.ts +1173 -0
  215. package/src/type-guards.ts +31 -0
  216. package/src/types.ts +164 -25
  217. package/src/wrap-for-v3.ts +105 -0
  218. package/test/ai-promise.test.ts +1080 -0
  219. package/test/ai-proxy.test.ts +1 -1
  220. package/test/backward-compat.test.ts +147 -0
  221. package/test/batch-autosubmit-errors.test.ts +610 -0
  222. package/test/batch-blog-posts.test.ts +87 -129
  223. package/test/budget-tracking.test.ts +800 -0
  224. package/test/cache.test.ts +712 -0
  225. package/test/context-isolation.test.ts +687 -0
  226. package/test/core-functions.test.ts +183 -579
  227. package/test/decide.test.ts +154 -322
  228. package/test/define.test.ts +211 -8
  229. package/test/digital-objects-registry.test.ts +760 -0
  230. package/test/embedding-cache-middleware.test.ts +140 -0
  231. package/test/evals/deterministic.eval.test.ts +376 -0
  232. package/test/generate-core.test.ts +140 -229
  233. package/test/implicit-batch.test.ts +22 -65
  234. package/test/json-parse-error-handling.test.ts +463 -0
  235. package/test/retry-policy-integration.test.ts +117 -0
  236. package/test/retry.test.ts +1016 -0
  237. package/test/schema.test.ts +55 -19
  238. package/test/streaming.test.ts +316 -0
  239. package/test/template.test.ts +1164 -0
  240. package/test/tool-orchestration.test.ts +1040 -0
  241. package/test/wrap-for-v3.test.ts +612 -0
  242. package/vitest.config.js +6 -0
  243. package/vitest.config.ts +20 -0
  244. package/dist/rpc/auth.d.ts +0 -69
  245. package/dist/rpc/auth.d.ts.map +0 -1
  246. package/dist/rpc/auth.js +0 -136
  247. package/dist/rpc/auth.js.map +0 -1
  248. package/dist/rpc/client.d.ts +0 -62
  249. package/dist/rpc/client.d.ts.map +0 -1
  250. package/dist/rpc/client.js +0 -103
  251. package/dist/rpc/client.js.map +0 -1
  252. package/dist/rpc/deferred.d.ts +0 -60
  253. package/dist/rpc/deferred.d.ts.map +0 -1
  254. package/dist/rpc/deferred.js +0 -96
  255. package/dist/rpc/deferred.js.map +0 -1
  256. package/dist/rpc/index.d.ts +0 -22
  257. package/dist/rpc/index.d.ts.map +0 -1
  258. package/dist/rpc/index.js +0 -38
  259. package/dist/rpc/index.js.map +0 -1
  260. package/dist/rpc/local.d.ts +0 -42
  261. package/dist/rpc/local.d.ts.map +0 -1
  262. package/dist/rpc/local.js +0 -50
  263. package/dist/rpc/local.js.map +0 -1
  264. package/dist/rpc/server.d.ts +0 -165
  265. package/dist/rpc/server.d.ts.map +0 -1
  266. package/dist/rpc/server.js +0 -405
  267. package/dist/rpc/server.js.map +0 -1
  268. package/dist/rpc/session.d.ts +0 -32
  269. package/dist/rpc/session.d.ts.map +0 -1
  270. package/dist/rpc/session.js +0 -43
  271. package/dist/rpc/session.js.map +0 -1
  272. package/dist/rpc/transport.d.ts +0 -306
  273. package/dist/rpc/transport.d.ts.map +0 -1
  274. package/dist/rpc/transport.js +0 -731
  275. package/dist/rpc/transport.js.map +0 -1
  276. package/src/batch/anthropic.js +0 -256
  277. package/src/batch/bedrock.js +0 -584
  278. package/src/batch/cloudflare.js +0 -287
  279. package/src/batch/google.js +0 -359
  280. package/src/batch/index.js +0 -30
  281. package/src/batch/memory.js +0 -187
  282. package/src/batch/openai.js +0 -402
  283. package/src/eval/index.js +0 -7
  284. package/src/eval/models.js +0 -119
  285. package/src/eval/runner.js +0 -147
  286. package/test/schema.test.js +0 -96
package/src/generate.ts CHANGED
@@ -10,17 +10,15 @@
10
10
  */
11
11
 
12
12
  import {
13
- generateObject as sdkGenerateObject,
14
13
  generateText as sdkGenerateText,
15
- streamObject as sdkStreamObject,
16
14
  streamText as sdkStreamText,
17
- type GenerateObjectResult,
15
+ Output,
18
16
  type GenerateTextResult,
19
- type StreamObjectResult,
20
17
  type StreamTextResult,
21
- type LanguageModel
18
+ type LanguageModel,
22
19
  } from 'ai'
23
20
  import { schema as convertSchema, type SimpleSchema } from './schema.js'
21
+ import { isZodSchema } from './type-guards.js'
24
22
  import type { ZodTypeAny } from 'zod'
25
23
 
26
24
  type ModelArg = string | LanguageModel
@@ -43,7 +41,11 @@ interface GenerateObjectOptions<T> {
43
41
  maxRetries?: number
44
42
  abortSignal?: AbortSignal
45
43
  headers?: Record<string, string>
46
- experimental_telemetry?: { isEnabled?: boolean; functionId?: string; metadata?: Record<string, string> }
44
+ experimental_telemetry?: {
45
+ isEnabled?: boolean
46
+ functionId?: string
47
+ metadata?: Record<string, string>
48
+ }
47
49
  }
48
50
 
49
51
  interface GenerateTextOptions {
@@ -64,7 +66,11 @@ interface GenerateTextOptions {
64
66
  tools?: Record<string, unknown>
65
67
  toolChoice?: 'auto' | 'none' | 'required' | { type: 'tool'; toolName: string }
66
68
  maxSteps?: number
67
- experimental_telemetry?: { isEnabled?: boolean; functionId?: string; metadata?: Record<string, string> }
69
+ experimental_telemetry?: {
70
+ isEnabled?: boolean
71
+ functionId?: string
72
+ metadata?: Record<string, string>
73
+ }
68
74
  }
69
75
 
70
76
  /**
@@ -82,16 +88,6 @@ async function resolveModel(modelArg: ModelArg): Promise<LanguageModel> {
82
88
  return model(modelArg)
83
89
  }
84
90
 
85
- /**
86
- * Check if value is a Zod schema
87
- */
88
- function isZodSchema(value: unknown): value is ZodTypeAny {
89
- return value !== null &&
90
- typeof value === 'object' &&
91
- '_def' in value &&
92
- 'parse' in value
93
- }
94
-
95
91
  /**
96
92
  * Convert schema to Zod if needed
97
93
  */
@@ -140,16 +136,17 @@ function resolveSchema(schemaArg: SchemaArg): ZodTypeAny {
140
136
  */
141
137
  export async function generateObject<T>(
142
138
  options: GenerateObjectOptions<T>
143
- ): Promise<GenerateObjectResult<T>> {
139
+ ): Promise<{ object: T; usage?: unknown; warnings?: unknown[] | undefined }> {
144
140
  const model = await resolveModel(options.model)
145
141
  const schema = resolveSchema(options.schema as SchemaArg)
146
- // Use 'as any' to handle AI SDK v4 API variance
147
- return sdkGenerateObject({
148
- ...options,
142
+ const { schema: _schema, mode: _mode, ...rest } = options
143
+ // Using unknown cast for SDK compatibility - the AI SDK has complex type unions
144
+ const result = await sdkGenerateText({
145
+ ...rest,
149
146
  model,
150
- schema,
151
- output: 'object'
152
- } as any) as Promise<GenerateObjectResult<T>>
147
+ output: Output.object({ schema }),
148
+ } as unknown as Parameters<typeof sdkGenerateText>[0])
149
+ return { object: result.output as T, usage: result.usage, warnings: result.warnings }
153
150
  }
154
151
 
155
152
  /**
@@ -181,7 +178,7 @@ export async function generateText(
181
178
  const model = await resolveModel(options.model)
182
179
  return sdkGenerateText({
183
180
  ...options,
184
- model
181
+ model,
185
182
  } as Parameters<typeof sdkGenerateText>[0])
186
183
  }
187
184
 
@@ -205,16 +202,19 @@ export async function generateText(
205
202
  */
206
203
  export async function streamObject<T>(
207
204
  options: GenerateObjectOptions<T>
208
- ): Promise<StreamObjectResult<T, T, never>> {
205
+ ): Promise<{ partialObjectStream: AsyncIterable<T> }> {
209
206
  const model = await resolveModel(options.model)
210
207
  const schema = resolveSchema(options.schema as SchemaArg)
211
- // Use 'as any' to handle AI SDK API variance
212
- return sdkStreamObject({
213
- ...options,
208
+ const { schema: _schema, mode: _mode, ...rest } = options
209
+ // Using unknown cast for SDK compatibility - the AI SDK has complex type unions
210
+ const result = await sdkStreamText({
211
+ ...rest,
214
212
  model,
215
- schema,
216
- output: 'object'
217
- } as any) as unknown as StreamObjectResult<T, T, never>
213
+ output: Output.object({ schema }),
214
+ } as unknown as Parameters<typeof sdkStreamText>[0])
215
+ return {
216
+ partialObjectStream: result.partialOutputStream as AsyncIterable<T>,
217
+ }
218
218
  }
219
219
 
220
220
  /**
@@ -240,6 +240,6 @@ export async function streamText(
240
240
  const model = await resolveModel(options.model)
241
241
  return sdkStreamText({
242
242
  ...options,
243
- model
243
+ model,
244
244
  } as Parameters<typeof sdkStreamText>[0])
245
245
  }
package/src/index.ts CHANGED
@@ -1,39 +1,68 @@
1
1
  /**
2
- * ai-functions - Core AI primitives for building intelligent applications
2
+ * ai-functions - Full-featured AI primitives for building intelligent applications
3
3
  *
4
- * This is the foundational package that all other primitives depend on.
5
- * It provides:
6
- * - RPC primitives via rpc.do
7
- * - AI function types and interfaces
8
- * - Core AI() and ai() constructors
9
- * - Embedding utilities from AI SDK
10
- * - Cloudflare Workers AI provider (default for embeddings)
11
- * - Tagged template literal support for all functions
12
- * - Async iterator support for list/extract
4
+ * This package provides the complete feature set including:
5
+ * - Core primitives from ai-core (generate, AIPromise, templates, context)
6
+ * - Batch processing (BatchQueue, BatchMapPromise)
7
+ * - Retry/resilience patterns (RetryPolicy, CircuitBreaker, FallbackChain)
8
+ * - Budget tracking (BudgetTracker, TokenCounter)
9
+ * - Caching (MemoryCache, EmbeddingCache, GenerationCache)
10
+ * - Tool orchestration (AgenticLoop, ToolRouter)
11
+ * - Embeddings
12
+ * - Provider integrations
13
+ *
14
+ * For lightweight usage with just core primitives, use ai-core directly.
13
15
  *
14
16
  * @packageDocumentation
15
17
  */
16
18
 
17
- // TODO: Re-enable RPC exports when rpc.do is published
18
- // export * from 'rpc.do'
19
-
20
- // Export AI function types and interfaces
21
- export * from './types.js'
22
- export * from './ai.js'
19
+ // ============================================================================
20
+ // Re-export core primitives for backward compatibility
21
+ // ============================================================================
23
22
 
24
- // Export embedding utilities
25
- export * from './embeddings.js'
26
-
27
- // Export generation functions with smart model routing
28
- export { generateObject, generateText, streamObject, streamText } from './generate.js'
23
+ // Types
24
+ export type {
25
+ AIFunctionDefinition,
26
+ JSONSchema,
27
+ AIGenerateOptions,
28
+ AIGenerateResult,
29
+ AIFunctionCall,
30
+ AIClient,
31
+ ImageOptions,
32
+ ImageResult,
33
+ VideoOptions,
34
+ VideoResult,
35
+ WriteOptions,
36
+ TemplateFunction as CoreTemplateFunction,
37
+ ListItem,
38
+ ListResult,
39
+ NamedList,
40
+ ListsResult,
41
+ CodeLanguage,
42
+ GenerativeOutputType,
43
+ HumanChannel,
44
+ LegacyHumanChannel,
45
+ SchemaLimitations,
46
+ BaseFunctionDefinition,
47
+ CodeFunctionDefinition,
48
+ CodeFunctionResult,
49
+ CodeGenerationDefinition,
50
+ GenerativeFunctionDefinition,
51
+ GenerativeFunctionResult,
52
+ AgenticFunctionDefinition,
53
+ AgenticExecutionState,
54
+ HumanFunctionDefinition,
55
+ HumanFunctionResult,
56
+ FunctionDefinition,
57
+ DefinedFunction,
58
+ FunctionRegistry,
59
+ AutoDefineResult,
60
+ } from './types.js'
29
61
 
30
- // Export simplified schema helper
62
+ // Schema exports
31
63
  export { schema, type SimpleSchema } from './schema.js'
32
64
 
33
- // Export providers
34
- export * from './providers/index.js'
35
-
36
- // Export template utilities
65
+ // Template exports
37
66
  export {
38
67
  parseTemplate,
39
68
  createTemplateFunction,
@@ -47,7 +76,7 @@ export {
47
76
  type ChainablePromise,
48
77
  } from './template.js'
49
78
 
50
- // Export AIPromise utilities for promise pipelining
79
+ // AIPromise exports
51
80
  export {
52
81
  AIPromise,
53
82
  isAIPromise,
@@ -63,17 +92,19 @@ export {
63
92
  AI_PROMISE_SYMBOL,
64
93
  RAW_PROMISE_SYMBOL,
65
94
  type AIPromiseOptions,
95
+ type StreamingAIPromise,
96
+ type StreamOptions,
66
97
  } from './ai-promise.js'
67
98
 
68
- // Export AI primitives
99
+ // Generation exports
100
+ export { generateObject, generateText, streamObject, streamText } from './generate.js'
101
+
102
+ // Primitives
69
103
  export {
70
- // Core generate primitive
71
104
  generate,
72
105
  type GenerateType,
73
106
  type GenerateOptions,
74
-
75
- // Generative functions
76
- ai as aiPrompt, // Renamed to avoid conflict with AIProxy from ai.ts
107
+ ai,
77
108
  write,
78
109
  code,
79
110
  list,
@@ -85,19 +116,11 @@ export {
85
116
  slides,
86
117
  image,
87
118
  video,
88
-
89
- // Agentic functions
90
119
  do,
91
120
  research,
92
-
93
- // Web functions
94
121
  read,
95
122
  browse,
96
-
97
- // Decision functions
98
123
  decide,
99
-
100
- // Human-in-the-loop functions
101
124
  ask,
102
125
  approve,
103
126
  review,
@@ -105,6 +128,60 @@ export {
105
128
  type HumanResult,
106
129
  } from './primitives.js'
107
130
 
131
+ // Context exports
132
+ export {
133
+ configure,
134
+ getContext,
135
+ withContext,
136
+ getGlobalContext,
137
+ resetContext,
138
+ getModel,
139
+ getProvider,
140
+ type ExecutionContext,
141
+ } from './context.js'
142
+
143
+ // Type guards
144
+ export { isZodSchema } from './type-guards.js'
145
+
146
+ // ============================================================================
147
+ // Export AI Proxy (the AI class/proxy from ai.ts)
148
+ // This is separate from the core 'ai' template function
149
+ // ============================================================================
150
+
151
+ export {
152
+ AI,
153
+ ai as aiProxy,
154
+ define,
155
+ defineFunction,
156
+ functions,
157
+ createFunctionRegistry,
158
+ resetGlobalRegistry,
159
+ withTemplate,
160
+ type AIProxy,
161
+ // Also export from new split modules
162
+ createSchemaFunctions,
163
+ type AISchemaOptions,
164
+ type SchemaFunctions,
165
+ type InferSimpleSchemaResult,
166
+ createDefinedFunction,
167
+ convertArgsToJSONSchema,
168
+ fillTemplate,
169
+ generateCode,
170
+ } from './ai.js'
171
+
172
+ // Also export 'ai' primitive as 'aiPrompt' for convenience
173
+ export { ai as aiPrompt } from './primitives.js'
174
+
175
+ // Export embedding utilities (not in ai-core)
176
+ export * from './embeddings.js'
177
+
178
+ // Export providers (not in ai-core)
179
+ export * from './providers/index.js'
180
+
181
+ // ============================================================================
182
+ // Extended exports (NOT in ai-core)
183
+ // ============================================================================
184
+
108
185
  // Export batch processing
109
186
  export {
110
187
  BatchQueue,
@@ -112,6 +189,11 @@ export {
112
189
  withBatch as withBatchQueue,
113
190
  registerBatchAdapter,
114
191
  getBatchAdapter,
192
+ registerFlexAdapter,
193
+ getFlexAdapter,
194
+ hasFlexAdapter,
195
+ tiersForModel,
196
+ modelSupportsTier,
115
197
  isBatchMode,
116
198
  deferToBatch,
117
199
  BATCH_MODE_SYMBOL,
@@ -123,10 +205,21 @@ export {
123
205
  type BatchResult,
124
206
  type BatchSubmitResult,
125
207
  type BatchAdapter,
208
+ type FlexAdapter,
126
209
  type BatchQueueOptions,
127
210
  type DeferredOptions,
128
211
  } from './batch-queue.js'
129
212
 
213
+ // Export per-model policy data (sourced from language-models)
214
+ export {
215
+ policyFor as modelPolicyFor,
216
+ type ModelPolicy,
217
+ type BatchTier,
218
+ type RetryPolicyData,
219
+ type CircuitBreakerPolicyData,
220
+ type ErrorCategoryName,
221
+ } from 'language-models'
222
+
130
223
  // Export batch map for automatic batching
131
224
  export {
132
225
  BatchMapPromise,
@@ -137,18 +230,201 @@ export {
137
230
  type BatchMapOptions,
138
231
  } from './batch-map.js'
139
232
 
140
- // Export execution context
233
+ // Export additional execution context features (full version with batch/budget)
141
234
  export {
142
- configure,
143
- getContext,
144
- withContext,
145
- getGlobalContext,
146
- resetContext,
147
- getModel,
148
- getProvider,
149
235
  getBatchMode,
150
236
  getBatchThreshold,
151
237
  shouldUseBatchAPI,
152
- type ExecutionContext,
238
+ getFlexThreshold,
239
+ getExecutionTier,
240
+ isFlexAvailable,
153
241
  type BatchMode,
242
+ type ContextBudgetConfig,
243
+ type ExecutionTier,
154
244
  } from './context.js'
245
+
246
+ // Export budget tracking and request tracing
247
+ export {
248
+ BudgetTracker,
249
+ TokenCounter,
250
+ RequestContext,
251
+ BudgetExceededError,
252
+ createRequestContext,
253
+ withBudget,
254
+ type BudgetConfig,
255
+ type BudgetAlert,
256
+ type BudgetSnapshot,
257
+ type TokenUsage,
258
+ type RequestInfo,
259
+ type RequestContextOptions,
260
+ type ModelPricing,
261
+ type WithBudgetOptions,
262
+ type RemainingBudget,
263
+ type CheckBudgetOptions,
264
+ } from './budget.js'
265
+
266
+ // Export agentic tool orchestration
267
+ export {
268
+ // Core classes
269
+ AgenticLoop,
270
+ ToolRouter,
271
+ ToolValidator,
272
+
273
+ // Tool composition utilities
274
+ createTool,
275
+ createToolset,
276
+ wrapTool,
277
+ cachedTool,
278
+ rateLimitedTool,
279
+ timeoutTool,
280
+ createAgenticLoop,
281
+
282
+ // Types
283
+ type Tool,
284
+ type ToolCall,
285
+ type ToolResult,
286
+ type FormattedToolResult,
287
+ type ValidationResult,
288
+ type ModelResponse,
289
+ type Message,
290
+ type StepInfo,
291
+ type LoopOptions,
292
+ type RunOptions,
293
+ type ToolCallResult,
294
+ type SDKToolResult,
295
+ type LoopResult,
296
+ type LoopStreamEvent,
297
+ } from './tool-orchestration.js'
298
+
299
+ // Export caching layer for embeddings and generations
300
+ export {
301
+ // Core cache storage
302
+ MemoryCache,
303
+
304
+ // Specialized caches
305
+ EmbeddingCache,
306
+ GenerationCache,
307
+
308
+ // Cache wrapper
309
+ withCache,
310
+
311
+ // Utilities
312
+ hashKey,
313
+ createCacheKey,
314
+
315
+ // Types
316
+ type CacheStorage,
317
+ type CacheEntry,
318
+ type CacheOptions,
319
+ type CacheStats,
320
+ type MemoryCacheOptions,
321
+ type CacheKeyType,
322
+ type EmbeddingCacheOptions,
323
+ type BatchEmbeddingResult,
324
+ type GenerationParams,
325
+ type GenerationCacheGetOptions,
326
+ type WithCacheOptions,
327
+ type CachedFunction,
328
+ } from './cache.js'
329
+
330
+ // Export retry/fallback patterns with exponential backoff
331
+ export {
332
+ // Error types and classification
333
+ RetryableError,
334
+ NonRetryableError,
335
+ NetworkError,
336
+ RateLimitError,
337
+ CircuitOpenError,
338
+ ErrorCategory,
339
+ classifyError,
340
+
341
+ // Backoff calculation
342
+ calculateBackoff,
343
+
344
+ // Retry policy
345
+ RetryPolicy,
346
+
347
+ // Circuit breaker
348
+ CircuitBreaker,
349
+
350
+ // Fallback chain
351
+ FallbackChain,
352
+
353
+ // Convenience helper
354
+ withRetry,
355
+
356
+ // Types
357
+ type JitterStrategy,
358
+ type BackoffOptions,
359
+ type RetryOptions,
360
+ type RetryInfo,
361
+ type BatchItemResult,
362
+ type CircuitState,
363
+ type CircuitBreakerOptions,
364
+ type CircuitBreakerMetrics,
365
+ type FallbackModel,
366
+ type FallbackOptions,
367
+ type FallbackMetrics,
368
+ } from './retry.js'
369
+
370
+ // Export digital-objects function registry
371
+ export {
372
+ DigitalObjectsFunctionRegistry,
373
+ createDigitalObjectsRegistry,
374
+ FUNCTION_NOUNS,
375
+ FUNCTION_VERBS,
376
+ type StoredFunctionDefinition,
377
+ type FunctionCallData,
378
+ type DigitalObjectsRegistryOptions,
379
+ } from './digital-objects-registry.js'
380
+
381
+ // Export configurable logger
382
+ export {
383
+ configureLogger,
384
+ getLogger,
385
+ resetLogger,
386
+ getLogLevel,
387
+ setLogLevel,
388
+ type Logger,
389
+ type LoggerConfig,
390
+ } from './logger.js'
391
+
392
+ // ============================================================================
393
+ // V3 middleware stack — cache / budget / trace via wrapLanguageModel
394
+ // ============================================================================
395
+
396
+ // Composable middleware primitives
397
+ export {
398
+ cacheMiddleware,
399
+ embeddingCacheMiddleware,
400
+ budgetMiddleware,
401
+ traceMiddleware,
402
+ type CacheMiddlewareOptions,
403
+ type CacheMiddlewareStore,
404
+ type EmbedCacheMiddlewareOptions,
405
+ type EmbedCacheMiddlewareStore,
406
+ type BudgetMiddlewareOptions,
407
+ type PricingOverlay,
408
+ type TraceEvent,
409
+ type TraceEventKind,
410
+ type TraceMiddlewareOptions,
411
+ } from './middleware/index.js'
412
+
413
+ // Convenience composer
414
+ export { wrapForV3, type WrapForV3Options } from './wrap-for-v3.js'
415
+
416
+ // Type re-export — downstream packages (services-as-software EvaluatorPanel
417
+ // model-injection point, etc.) need `LanguageModelV3` for typing wrapped-model
418
+ // arguments. Re-exporting from ai-functions avoids forcing every consumer to
419
+ // depend on `@ai-sdk/provider` directly.
420
+ export type { LanguageModelV3 } from '@ai-sdk/provider'
421
+
422
+ // Pluggable persistence primitive for trace/eval entries
423
+ export {
424
+ InMemoryEvalLogStore,
425
+ getEvalLogStore,
426
+ configureEvalLogStore,
427
+ type EvalLogEntry,
428
+ type EvalLogListOptions,
429
+ type EvalLogStore,
430
+ } from './eval-log/index.js'