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.
- package/.turbo/turbo-build.log +1 -4
- package/CHANGELOG.md +68 -1
- package/README.md +397 -157
- package/dist/ai-promise.d.ts +50 -3
- package/dist/ai-promise.d.ts.map +1 -1
- package/dist/ai-promise.js +410 -51
- package/dist/ai-promise.js.map +1 -1
- package/dist/ai-schemas.d.ts +56 -0
- package/dist/ai-schemas.d.ts.map +1 -0
- package/dist/ai-schemas.js +53 -0
- package/dist/ai-schemas.js.map +1 -0
- package/dist/ai.d.ts +16 -242
- package/dist/ai.d.ts.map +1 -1
- package/dist/ai.js +54 -837
- package/dist/ai.js.map +1 -1
- package/dist/batch/anthropic.d.ts +6 -4
- package/dist/batch/anthropic.d.ts.map +1 -1
- package/dist/batch/anthropic.js +83 -145
- package/dist/batch/anthropic.js.map +1 -1
- package/dist/batch/bedrock.d.ts +8 -30
- package/dist/batch/bedrock.d.ts.map +1 -1
- package/dist/batch/bedrock.js +155 -338
- package/dist/batch/bedrock.js.map +1 -1
- package/dist/batch/cloudflare.d.ts +8 -20
- package/dist/batch/cloudflare.d.ts.map +1 -1
- package/dist/batch/cloudflare.js +68 -189
- package/dist/batch/cloudflare.js.map +1 -1
- package/dist/batch/google.d.ts +6 -20
- package/dist/batch/google.d.ts.map +1 -1
- package/dist/batch/google.js +70 -238
- package/dist/batch/google.js.map +1 -1
- package/dist/batch/index.d.ts +4 -1
- package/dist/batch/index.d.ts.map +1 -1
- package/dist/batch/index.js +4 -1
- package/dist/batch/index.js.map +1 -1
- package/dist/batch/memory.d.ts +1 -1
- package/dist/batch/memory.d.ts.map +1 -1
- package/dist/batch/memory.js +14 -10
- package/dist/batch/memory.js.map +1 -1
- package/dist/batch/openai.d.ts +11 -14
- package/dist/batch/openai.d.ts.map +1 -1
- package/dist/batch/openai.js +52 -156
- package/dist/batch/openai.js.map +1 -1
- package/dist/batch/provider.d.ts +111 -0
- package/dist/batch/provider.d.ts.map +1 -0
- package/dist/batch/provider.js +233 -0
- package/dist/batch/provider.js.map +1 -0
- package/dist/batch-map.d.ts.map +1 -1
- package/dist/batch-map.js +23 -17
- package/dist/batch-map.js.map +1 -1
- package/dist/batch-queue.d.ts +65 -0
- package/dist/batch-queue.d.ts.map +1 -1
- package/dist/batch-queue.js +169 -14
- package/dist/batch-queue.js.map +1 -1
- package/dist/budget.d.ts +272 -0
- package/dist/budget.d.ts.map +1 -0
- package/dist/budget.js +513 -0
- package/dist/budget.js.map +1 -0
- package/dist/cache.d.ts +295 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +433 -0
- package/dist/cache.js.map +1 -0
- package/dist/context.d.ts +42 -8
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +64 -62
- package/dist/context.js.map +1 -1
- package/dist/digital-objects-registry.d.ts +229 -0
- package/dist/digital-objects-registry.d.ts.map +1 -0
- package/dist/digital-objects-registry.js +617 -0
- package/dist/digital-objects-registry.js.map +1 -0
- package/dist/embeddings.d.ts +2 -2
- package/dist/embeddings.d.ts.map +1 -1
- package/dist/errors.d.ts +22 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +35 -0
- package/dist/errors.js.map +1 -0
- package/dist/eval/runner.d.ts +10 -1
- package/dist/eval/runner.d.ts.map +1 -1
- package/dist/eval/runner.js +41 -35
- package/dist/eval/runner.js.map +1 -1
- package/dist/eval-log/in-memory.d.ts +34 -0
- package/dist/eval-log/in-memory.d.ts.map +1 -0
- package/dist/eval-log/in-memory.js +84 -0
- package/dist/eval-log/in-memory.js.map +1 -0
- package/dist/eval-log/index.d.ts +29 -0
- package/dist/eval-log/index.d.ts.map +1 -0
- package/dist/eval-log/index.js +39 -0
- package/dist/eval-log/index.js.map +1 -0
- package/dist/eval-log/types.d.ts +101 -0
- package/dist/eval-log/types.d.ts.map +1 -0
- package/dist/eval-log/types.js +16 -0
- package/dist/eval-log/types.js.map +1 -0
- package/dist/function-registry.d.ts +116 -0
- package/dist/function-registry.d.ts.map +1 -0
- package/dist/function-registry.js +546 -0
- package/dist/function-registry.js.map +1 -0
- package/dist/generate.d.ts +9 -3
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +18 -22
- package/dist/generate.js.map +1 -1
- package/dist/index.d.ts +35 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +89 -42
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +118 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +187 -0
- package/dist/logger.js.map +1 -0
- package/dist/middleware/budget.d.ts +84 -0
- package/dist/middleware/budget.d.ts.map +1 -0
- package/dist/middleware/budget.js +110 -0
- package/dist/middleware/budget.js.map +1 -0
- package/dist/middleware/cache.d.ts +103 -0
- package/dist/middleware/cache.d.ts.map +1 -0
- package/dist/middleware/cache.js +228 -0
- package/dist/middleware/cache.js.map +1 -0
- package/dist/middleware/embed-cache.d.ts +99 -0
- package/dist/middleware/embed-cache.d.ts.map +1 -0
- package/dist/middleware/embed-cache.js +128 -0
- package/dist/middleware/embed-cache.js.map +1 -0
- package/dist/middleware/index.d.ts +11 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +11 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/trace.d.ts +103 -0
- package/dist/middleware/trace.d.ts.map +1 -0
- package/dist/middleware/trace.js +176 -0
- package/dist/middleware/trace.js.map +1 -0
- package/dist/primitives.d.ts +120 -1
- package/dist/primitives.d.ts.map +1 -1
- package/dist/primitives.js +398 -26
- package/dist/primitives.js.map +1 -1
- package/dist/retry.d.ts +368 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +646 -0
- package/dist/retry.js.map +1 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +2 -10
- package/dist/schema.js.map +1 -1
- package/dist/telemetry.d.ts +128 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +285 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/template.d.ts.map +1 -1
- package/dist/template.js +6 -1
- package/dist/template.js.map +1 -1
- package/dist/tool-orchestration.d.ts +453 -0
- package/dist/tool-orchestration.d.ts.map +1 -0
- package/dist/tool-orchestration.js +763 -0
- package/dist/tool-orchestration.js.map +1 -0
- package/dist/type-guards.d.ts +28 -0
- package/dist/type-guards.d.ts.map +1 -0
- package/dist/type-guards.js +29 -0
- package/dist/type-guards.js.map +1 -0
- package/dist/types.d.ts +135 -17
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +36 -1
- package/dist/types.js.map +1 -1
- package/dist/wrap-for-v3.d.ts +80 -0
- package/dist/wrap-for-v3.d.ts.map +1 -0
- package/dist/wrap-for-v3.js +89 -0
- package/dist/wrap-for-v3.js.map +1 -0
- package/examples/00-quickstart.ts +232 -0
- package/examples/01-rag-chatbot.ts +212 -0
- package/examples/02-multi-agent-research.ts +290 -0
- package/examples/03-email-classification.ts +379 -0
- package/examples/04-content-moderation.ts +400 -0
- package/examples/05-document-extraction.ts +455 -0
- package/examples/06-streaming-chat-nextjs.ts +437 -0
- package/examples/07-cloudflare-worker.ts +483 -0
- package/examples/08-batch-processing.ts +491 -0
- package/examples/09-budget-constrained.ts +527 -0
- package/examples/10-tool-orchestration.ts +565 -0
- package/examples/11-retry-resilience.ts +403 -0
- package/examples/12-caching-strategies.ts +422 -0
- package/examples/README.md +145 -0
- package/package.json +10 -6
- package/src/ai-promise.ts +528 -99
- package/src/ai-schemas.ts +122 -0
- package/src/ai.ts +69 -1153
- package/src/batch/anthropic.ts +96 -161
- package/src/batch/bedrock.ts +203 -454
- package/src/batch/cloudflare.ts +99 -282
- package/src/batch/google.ts +91 -297
- package/src/batch/index.ts +4 -1
- package/src/batch/memory.ts +15 -10
- package/src/batch/openai.ts +65 -193
- package/src/batch/provider.ts +336 -0
- package/src/batch-map.ts +29 -24
- package/src/batch-queue.ts +200 -11
- package/src/budget.ts +740 -0
- package/src/cache.ts +681 -0
- package/src/context.ts +122 -76
- package/src/digital-objects-registry.ts +750 -0
- package/src/errors.ts +37 -0
- package/src/eval/runner.ts +63 -38
- package/src/eval-log/in-memory.ts +90 -0
- package/src/eval-log/index.ts +46 -0
- package/src/eval-log/types.ts +110 -0
- package/src/function-registry.ts +671 -0
- package/src/generate.ts +33 -33
- package/src/index.ts +325 -49
- package/src/logger.ts +232 -0
- package/src/middleware/budget.ts +171 -0
- package/src/middleware/cache.ts +299 -0
- package/src/middleware/embed-cache.ts +195 -0
- package/src/middleware/index.ts +23 -0
- package/src/middleware/trace.ts +248 -0
- package/src/primitives.ts +589 -62
- package/src/retry.ts +902 -0
- package/src/schema.ts +8 -17
- package/src/telemetry.ts +403 -0
- package/src/template.ts +8 -4
- package/src/tool-orchestration.ts +1173 -0
- package/src/type-guards.ts +31 -0
- package/src/types.ts +164 -25
- package/src/wrap-for-v3.ts +105 -0
- package/test/ai-promise.test.ts +1080 -0
- package/test/ai-proxy.test.ts +1 -1
- package/test/backward-compat.test.ts +147 -0
- package/test/batch-autosubmit-errors.test.ts +610 -0
- package/test/batch-blog-posts.test.ts +87 -129
- package/test/budget-tracking.test.ts +800 -0
- package/test/cache.test.ts +712 -0
- package/test/context-isolation.test.ts +687 -0
- package/test/core-functions.test.ts +183 -579
- package/test/decide.test.ts +154 -322
- package/test/define.test.ts +211 -8
- package/test/digital-objects-registry.test.ts +760 -0
- package/test/embedding-cache-middleware.test.ts +140 -0
- package/test/evals/deterministic.eval.test.ts +376 -0
- package/test/generate-core.test.ts +140 -229
- package/test/implicit-batch.test.ts +22 -65
- package/test/json-parse-error-handling.test.ts +463 -0
- package/test/retry-policy-integration.test.ts +117 -0
- package/test/retry.test.ts +1016 -0
- package/test/schema.test.ts +55 -19
- package/test/streaming.test.ts +316 -0
- package/test/template.test.ts +1164 -0
- package/test/tool-orchestration.test.ts +1040 -0
- package/test/wrap-for-v3.test.ts +612 -0
- package/vitest.config.js +6 -0
- package/vitest.config.ts +20 -0
- package/dist/rpc/auth.d.ts +0 -69
- package/dist/rpc/auth.d.ts.map +0 -1
- package/dist/rpc/auth.js +0 -136
- package/dist/rpc/auth.js.map +0 -1
- package/dist/rpc/client.d.ts +0 -62
- package/dist/rpc/client.d.ts.map +0 -1
- package/dist/rpc/client.js +0 -103
- package/dist/rpc/client.js.map +0 -1
- package/dist/rpc/deferred.d.ts +0 -60
- package/dist/rpc/deferred.d.ts.map +0 -1
- package/dist/rpc/deferred.js +0 -96
- package/dist/rpc/deferred.js.map +0 -1
- package/dist/rpc/index.d.ts +0 -22
- package/dist/rpc/index.d.ts.map +0 -1
- package/dist/rpc/index.js +0 -38
- package/dist/rpc/index.js.map +0 -1
- package/dist/rpc/local.d.ts +0 -42
- package/dist/rpc/local.d.ts.map +0 -1
- package/dist/rpc/local.js +0 -50
- package/dist/rpc/local.js.map +0 -1
- package/dist/rpc/server.d.ts +0 -165
- package/dist/rpc/server.d.ts.map +0 -1
- package/dist/rpc/server.js +0 -405
- package/dist/rpc/server.js.map +0 -1
- package/dist/rpc/session.d.ts +0 -32
- package/dist/rpc/session.d.ts.map +0 -1
- package/dist/rpc/session.js +0 -43
- package/dist/rpc/session.js.map +0 -1
- package/dist/rpc/transport.d.ts +0 -306
- package/dist/rpc/transport.d.ts.map +0 -1
- package/dist/rpc/transport.js +0 -731
- package/dist/rpc/transport.js.map +0 -1
- package/src/batch/anthropic.js +0 -256
- package/src/batch/bedrock.js +0 -584
- package/src/batch/cloudflare.js +0 -287
- package/src/batch/google.js +0 -359
- package/src/batch/index.js +0 -30
- package/src/batch/memory.js +0 -187
- package/src/batch/openai.js +0 -402
- package/src/eval/index.js +0 -7
- package/src/eval/models.js +0 -119
- package/src/eval/runner.js +0 -147
- 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
|
-
|
|
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?: {
|
|
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?: {
|
|
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<
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
-
|
|
152
|
-
|
|
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<
|
|
205
|
+
): Promise<{ partialObjectStream: AsyncIterable<T> }> {
|
|
209
206
|
const model = await resolveModel(options.model)
|
|
210
207
|
const schema = resolveSchema(options.schema as SchemaArg)
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
-
|
|
217
|
-
|
|
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 -
|
|
2
|
+
* ai-functions - Full-featured AI primitives for building intelligent applications
|
|
3
3
|
*
|
|
4
|
-
* This
|
|
5
|
-
*
|
|
6
|
-
* -
|
|
7
|
-
* -
|
|
8
|
-
* -
|
|
9
|
-
* -
|
|
10
|
-
* -
|
|
11
|
-
* -
|
|
12
|
-
* -
|
|
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
|
-
//
|
|
18
|
-
// export
|
|
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
|
-
//
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
//
|
|
62
|
+
// Schema exports
|
|
31
63
|
export { schema, type SimpleSchema } from './schema.js'
|
|
32
64
|
|
|
33
|
-
//
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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
|
-
|
|
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'
|