@ax-llm/ax 12.0.25 → 13.0.4

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 (7) hide show
  1. package/index.cjs +147 -19956
  2. package/index.cjs.map +1 -1
  3. package/index.d.cts +1753 -1755
  4. package/index.d.ts +1753 -1755
  5. package/index.js +147 -19771
  6. package/index.js.map +1 -1
  7. package/package.json +2 -3
package/index.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- import { ReadableStream as ReadableStream$1 } from 'node:stream/web';
2
1
  import { Span, Context, Tracer, Meter, Histogram, Counter, Gauge } from '@opentelemetry/api';
3
- import { ReadableStream } from 'stream/web';
4
2
 
5
3
  interface RetryConfig {
6
4
  maxRetries: number;
@@ -75,98 +73,6 @@ declare class AxAIRefusalError extends Error {
75
73
  toString(): string;
76
74
  }
77
75
 
78
- interface AxAIFeatures {
79
- functions: boolean;
80
- streaming: boolean;
81
- functionCot?: boolean;
82
- hasThinkingBudget?: boolean;
83
- hasShowThoughts?: boolean;
84
- }
85
- interface AxBaseAIArgs<TModel, TEmbedModel> {
86
- name: string;
87
- apiURL: string;
88
- headers: () => Promise<Record<string, string>>;
89
- modelInfo: Readonly<AxModelInfo[]>;
90
- defaults: Readonly<{
91
- model: TModel;
92
- embedModel?: TEmbedModel;
93
- }>;
94
- options?: Readonly<AxAIServiceOptions>;
95
- supportFor: AxAIFeatures | ((model: TModel) => AxAIFeatures);
96
- models?: AxAIInputModelList<TModel, TEmbedModel>;
97
- }
98
- declare const axBaseAIDefaultConfig: () => AxModelConfig;
99
- declare const axBaseAIDefaultCreativeConfig: () => AxModelConfig;
100
- declare class AxBaseAI<TModel, TEmbedModel, TChatRequest, TEmbedRequest, TChatResponse, TChatResponseDelta, TEmbedResponse> implements AxAIService<TModel, TEmbedModel> {
101
- private readonly aiImpl;
102
- private debug;
103
- private rt?;
104
- private fetch?;
105
- private tracer?;
106
- private meter?;
107
- private timeout?;
108
- private excludeContentFromTrace?;
109
- private models?;
110
- private abortSignal?;
111
- private logger;
112
- private modelInfo;
113
- private modelUsage?;
114
- private embedModelUsage?;
115
- private defaults;
116
- private lastUsedModelConfig?;
117
- private lastUsedChatModel?;
118
- private lastUsedEmbedModel?;
119
- protected apiURL: string;
120
- protected name: string;
121
- protected id: string;
122
- protected headers: () => Promise<Record<string, string>>;
123
- protected supportFor: AxAIFeatures | ((model: TModel) => AxAIFeatures);
124
- private metrics;
125
- constructor(aiImpl: Readonly<AxAIServiceImpl<TModel, TEmbedModel, TChatRequest, TEmbedRequest, TChatResponse, TChatResponseDelta, TEmbedResponse>>, { name, apiURL, headers, modelInfo, defaults, options, supportFor, models, }: Readonly<AxBaseAIArgs<TModel, TEmbedModel>>);
126
- private getMetricsInstruments;
127
- setName(name: string): void;
128
- getId(): string;
129
- setAPIURL(apiURL: string): void;
130
- setHeaders(headers: () => Promise<Record<string, string>>): void;
131
- setOptions(options: Readonly<AxAIServiceOptions>): void;
132
- getOptions(): Readonly<AxAIServiceOptions>;
133
- getLogger(): AxLoggerFunction;
134
- getModelList(): AxAIModelList | undefined;
135
- getName(): string;
136
- getFeatures(model?: TModel): AxAIFeatures;
137
- getLastUsedChatModel(): TModel | undefined;
138
- getLastUsedEmbedModel(): TEmbedModel | undefined;
139
- getLastUsedModelConfig(): AxModelConfig | undefined;
140
- private calculatePercentile;
141
- private updateLatencyMetrics;
142
- private updateErrorMetrics;
143
- private recordTokenUsage;
144
- private calculateRequestSize;
145
- private calculateResponseSize;
146
- private detectMultimodalContent;
147
- private calculatePromptLength;
148
- private calculateContextWindowUsage;
149
- private estimateCost;
150
- private estimateCostByName;
151
- private recordFunctionCallMetrics;
152
- private recordTimeoutMetric;
153
- private recordAbortMetric;
154
- private recordChatMetrics;
155
- private recordEmbedMetrics;
156
- getMetrics(): AxAIServiceMetrics;
157
- chat(req: Readonly<AxChatRequest<TModel>>, options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions<TModel, TEmbedModel>>): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
158
- private _chat1;
159
- private cleanupFunctionSchema;
160
- private _chat2;
161
- embed(req: Readonly<AxEmbedRequest<TEmbedModel>>, options?: Readonly<AxAIServiceActionOptions<TModel, TEmbedModel>>): Promise<AxEmbedResponse>;
162
- private _embed1;
163
- private _embed2;
164
- private buildHeaders;
165
- private getModelByKey;
166
- private getModel;
167
- private getEmbedModel;
168
- }
169
-
170
76
  type AxAIInputModelList<TModel, TEmbedModel> = (AxAIModelListBase & {
171
77
  isInternal?: boolean;
172
78
  } & ({
@@ -376,10 +282,10 @@ type AxEmbedRequest<TEmbedModel = string> = {
376
282
  embedModel?: TEmbedModel;
377
283
  };
378
284
  type AxInternalEmbedRequest<TEmbedModel> = Omit<AxEmbedRequest, 'embedModel'> & Required<Pick<AxEmbedRequest<TEmbedModel>, 'embedModel'>>;
379
- type AxRateLimiterFunction = <T = unknown>(reqFunc: () => Promise<T | ReadableStream$1<T>>, info: Readonly<{
285
+ type AxRateLimiterFunction = <T = unknown>(reqFunc: () => Promise<T | ReadableStream<T>>, info: Readonly<{
380
286
  modelUsage?: AxModelUsage;
381
- }>) => Promise<T | ReadableStream$1<T>>;
382
- type AxLoggerTag = 'error' | 'warning' | 'success' | 'functionName' | 'functionArg' | 'functionEnd' | 'functionResult' | 'functionError' | 'firstFunction' | 'multipleFunctions' | 'responseStart' | 'responseContent' | 'responseDelta' | 'responseEnd' | 'requestStart' | 'requestContent' | 'requestEnd' | 'systemStart' | 'systemContent' | 'systemEnd' | 'userStart' | 'userContent' | 'userEnd' | 'assistantStart' | 'assistantContent' | 'assistantEnd' | 'discovery' | 'optimizer' | 'start' | 'config' | 'phase' | 'progress' | 'result' | 'complete' | 'checkpoint';
287
+ }>) => Promise<T | ReadableStream<T>>;
288
+ type AxLoggerTag = 'error' | 'warning' | 'functionName' | 'functionArg' | 'functionResult' | 'functionError' | 'firstFunction' | 'multipleFunctions' | 'responseContent' | 'responseDelta' | 'responseEnd' | 'requestStart' | 'requestContent' | 'systemContent' | 'userStart' | 'userContent' | 'assistantStart' | 'assistantContent' | 'assistantEnd' | 'discovery' | 'optimizer' | 'start' | 'end' | 'config' | 'phase' | 'progress' | 'result' | 'complete' | 'checkpoint';
383
289
  type AxLoggerFunction = (message: string, options?: {
384
290
  tags?: AxLoggerTag[];
385
291
  }) => void;
@@ -411,6 +317,7 @@ type AxAIServiceActionOptions<TModel = unknown, TEmbedModel = unknown> = {
411
317
  traceContext?: Context;
412
318
  abortSignal?: AbortSignal;
413
319
  logger?: AxLoggerFunction;
320
+ functionResultFormatter?: (result: unknown) => string;
414
321
  };
415
322
  interface AxAIService<TModel = unknown, TEmbedModel = unknown> {
416
323
  getId(): string;
@@ -422,21 +329,113 @@ interface AxAIService<TModel = unknown, TEmbedModel = unknown> {
422
329
  getLastUsedChatModel(): TModel | undefined;
423
330
  getLastUsedEmbedModel(): TEmbedModel | undefined;
424
331
  getLastUsedModelConfig(): AxModelConfig | undefined;
425
- chat(req: Readonly<AxChatRequest<TModel>>, options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions<TModel, TEmbedModel>>): Promise<AxChatResponse | ReadableStream$1<AxChatResponse>>;
332
+ chat(req: Readonly<AxChatRequest<TModel>>, options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions<TModel, TEmbedModel>>): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
426
333
  embed(req: Readonly<AxEmbedRequest<TEmbedModel>>, options?: Readonly<AxAIServiceActionOptions<TModel, TEmbedModel>>): Promise<AxEmbedResponse>;
427
334
  setOptions(options: Readonly<AxAIServiceOptions>): void;
428
335
  getOptions(): Readonly<AxAIServiceOptions>;
429
336
  }
430
337
  interface AxAIServiceImpl<TModel, TEmbedModel, TChatRequest, TEmbedRequest, TChatResponse, TChatResponseDelta, TEmbedResponse> {
431
- createChatReq(req: Readonly<AxInternalChatRequest<TModel>>, config: Readonly<AxAIPromptConfig>): [AxAPI, TChatRequest];
338
+ createChatReq(req: Readonly<AxInternalChatRequest<TModel>>, config: Readonly<AxAIPromptConfig>): Promise<[AxAPI, TChatRequest]> | [AxAPI, TChatRequest];
432
339
  createChatResp(resp: Readonly<TChatResponse>): AxChatResponse;
433
340
  createChatStreamResp?(resp: Readonly<TChatResponseDelta>, state: object): AxChatResponse;
434
- createEmbedReq?(req: Readonly<AxInternalEmbedRequest<TEmbedModel>>): [AxAPI, TEmbedRequest];
341
+ createEmbedReq?(req: Readonly<AxInternalEmbedRequest<TEmbedModel>>): Promise<[AxAPI, TEmbedRequest]> | [AxAPI, TEmbedRequest];
435
342
  createEmbedResp?(resp: Readonly<TEmbedResponse>): AxEmbedResponse;
436
343
  getModelConfig(): AxModelConfig;
437
344
  getTokenUsage(): AxTokenUsage | undefined;
438
345
  }
439
346
 
347
+ interface AxAIFeatures {
348
+ functions: boolean;
349
+ streaming: boolean;
350
+ functionCot?: boolean;
351
+ hasThinkingBudget?: boolean;
352
+ hasShowThoughts?: boolean;
353
+ }
354
+ interface AxBaseAIArgs<TModel, TEmbedModel> {
355
+ name: string;
356
+ apiURL: string;
357
+ headers: () => Promise<Record<string, string>>;
358
+ modelInfo: Readonly<AxModelInfo[]>;
359
+ defaults: Readonly<{
360
+ model: TModel;
361
+ embedModel?: TEmbedModel;
362
+ }>;
363
+ options?: Readonly<AxAIServiceOptions>;
364
+ supportFor: AxAIFeatures | ((model: TModel) => AxAIFeatures);
365
+ models?: AxAIInputModelList<TModel, TEmbedModel>;
366
+ }
367
+ declare const axBaseAIDefaultConfig: () => AxModelConfig;
368
+ declare const axBaseAIDefaultCreativeConfig: () => AxModelConfig;
369
+ declare class AxBaseAI<TModel, TEmbedModel, TChatRequest, TEmbedRequest, TChatResponse, TChatResponseDelta, TEmbedResponse> implements AxAIService<TModel, TEmbedModel> {
370
+ private readonly aiImpl;
371
+ private debug;
372
+ private rt?;
373
+ private fetch?;
374
+ private tracer?;
375
+ private meter?;
376
+ private timeout?;
377
+ private excludeContentFromTrace?;
378
+ private models?;
379
+ private abortSignal?;
380
+ private logger;
381
+ private modelInfo;
382
+ private modelUsage?;
383
+ private embedModelUsage?;
384
+ private defaults;
385
+ private lastUsedModelConfig?;
386
+ private lastUsedChatModel?;
387
+ private lastUsedEmbedModel?;
388
+ protected apiURL: string;
389
+ protected name: string;
390
+ protected id: string;
391
+ protected headers: () => Promise<Record<string, string>>;
392
+ protected supportFor: AxAIFeatures | ((model: TModel) => AxAIFeatures);
393
+ private metrics;
394
+ constructor(aiImpl: Readonly<AxAIServiceImpl<TModel, TEmbedModel, TChatRequest, TEmbedRequest, TChatResponse, TChatResponseDelta, TEmbedResponse>>, { name, apiURL, headers, modelInfo, defaults, options, supportFor, models, }: Readonly<AxBaseAIArgs<TModel, TEmbedModel>>);
395
+ private getMetricsInstruments;
396
+ setName(name: string): void;
397
+ getId(): string;
398
+ setAPIURL(apiURL: string): void;
399
+ setHeaders(headers: () => Promise<Record<string, string>>): void;
400
+ setOptions(options: Readonly<AxAIServiceOptions>): void;
401
+ getOptions(): Readonly<AxAIServiceOptions>;
402
+ getLogger(): AxLoggerFunction;
403
+ getModelList(): AxAIModelList | undefined;
404
+ getName(): string;
405
+ getFeatures(model?: TModel): AxAIFeatures;
406
+ getLastUsedChatModel(): TModel | undefined;
407
+ getLastUsedEmbedModel(): TEmbedModel | undefined;
408
+ getLastUsedModelConfig(): AxModelConfig | undefined;
409
+ private calculatePercentile;
410
+ private updateLatencyMetrics;
411
+ private updateErrorMetrics;
412
+ private recordTokenUsage;
413
+ private calculateRequestSize;
414
+ private calculateResponseSize;
415
+ private detectMultimodalContent;
416
+ private calculatePromptLength;
417
+ private calculateContextWindowUsage;
418
+ private estimateCost;
419
+ private estimateCostByName;
420
+ private recordFunctionCallMetrics;
421
+ private recordTimeoutMetric;
422
+ private recordAbortMetric;
423
+ private recordChatMetrics;
424
+ private recordEmbedMetrics;
425
+ getMetrics(): AxAIServiceMetrics;
426
+ chat(req: Readonly<AxChatRequest<TModel>>, options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions<TModel, TEmbedModel>>): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
427
+ private _chat1;
428
+ private cleanupFunctionSchema;
429
+ private _chat2;
430
+ embed(req: Readonly<AxEmbedRequest<TEmbedModel>>, options?: Readonly<AxAIServiceActionOptions<TModel, TEmbedModel>>): Promise<AxEmbedResponse>;
431
+ private _embed1;
432
+ private _embed2;
433
+ private buildHeaders;
434
+ private getModelByKey;
435
+ private getModel;
436
+ private getEmbedModel;
437
+ }
438
+
440
439
  declare enum AxAIAnthropicModel {
441
440
  Claude4Opus = "claude-opus-4-20250514",
442
441
  Claude4Sonnet = "claude-sonnet-4-20250514",
@@ -673,7 +672,7 @@ declare const axAIAnthropicDefaultConfig: () => AxAIAnthropicConfig;
673
672
  declare const axAIAnthropicVertexDefaultConfig: () => AxAIAnthropicConfig;
674
673
  interface AxAIAnthropicArgs {
675
674
  name: 'anthropic';
676
- apiKey?: string;
675
+ apiKey?: string | (() => Promise<string>);
677
676
  projectId?: string;
678
677
  region?: string;
679
678
  config?: Readonly<Partial<AxAIAnthropicConfig>>;
@@ -684,6 +683,8 @@ declare class AxAIAnthropic extends AxBaseAI<AxAIAnthropicModel | AxAIAnthropicV
684
683
  constructor({ apiKey, projectId, region, config, options, models, }: Readonly<Omit<AxAIAnthropicArgs, 'name'>>);
685
684
  }
686
685
 
686
+ declare const axModelInfoAnthropic: AxModelInfo[];
687
+
687
688
  declare enum AxAIOpenAIModel {
688
689
  GPT4 = "gpt-4",
689
690
  GPT41 = "gpt-4.1",
@@ -969,6 +970,57 @@ declare class AxAIAzureOpenAI extends AxAIOpenAIBase<AxAIOpenAIModel, AxAIOpenAI
969
970
  constructor({ apiKey, resourceName, deploymentName, version, config, options, models, modelInfo, }: Readonly<Omit<AxAIAzureOpenAIArgs, 'name'>>);
970
971
  }
971
972
 
973
+ /**
974
+ * Options for the balancer.
975
+ */
976
+ type AxBalancerOptions = {
977
+ comparator?: (a: AxAIService, b: AxAIService) => number;
978
+ debug?: boolean;
979
+ initialBackoffMs?: number;
980
+ maxBackoffMs?: number;
981
+ maxRetries?: number;
982
+ };
983
+ /**
984
+ * Balancer that rotates through services.
985
+ */
986
+ declare class AxBalancer implements AxAIService<unknown, unknown> {
987
+ private services;
988
+ private currentServiceIndex;
989
+ private currentService;
990
+ private debug;
991
+ private initialBackoffMs;
992
+ private maxBackoffMs;
993
+ private maxRetries;
994
+ private serviceFailures;
995
+ constructor(services: readonly AxAIService[], options?: AxBalancerOptions);
996
+ getLastUsedChatModel(): unknown;
997
+ getLastUsedEmbedModel(): unknown;
998
+ getLastUsedModelConfig(): AxModelConfig | undefined;
999
+ /**
1000
+ * Service comparator that respects the input order of services.
1001
+ */
1002
+ static inputOrderComparator: () => number;
1003
+ /**
1004
+ * Service comparator that sorts services by cost.
1005
+ */
1006
+ static metricComparator: (a: AxAIService, b: AxAIService) => number;
1007
+ getModelList(): AxAIModelList | undefined;
1008
+ private getNextService;
1009
+ private reset;
1010
+ getName(): string;
1011
+ getId(): string;
1012
+ getFeatures(model?: string): AxAIFeatures;
1013
+ getMetrics(): AxAIServiceMetrics;
1014
+ private canRetryService;
1015
+ private handleFailure;
1016
+ private handleSuccess;
1017
+ chat(req: Readonly<AxChatRequest>, options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions> | undefined): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
1018
+ embed(req: Readonly<AxEmbedRequest>, options?: Readonly<AxAIServiceActionOptions> | undefined): Promise<AxEmbedResponse>;
1019
+ setOptions(options: Readonly<AxAIServiceOptions>): void;
1020
+ getOptions(): Readonly<AxAIServiceOptions>;
1021
+ getLogger(): AxLoggerFunction;
1022
+ }
1023
+
972
1024
  /**
973
1025
  * Cohere: Models for text generation
974
1026
  */
@@ -1081,6 +1133,8 @@ declare class AxAICohere extends AxBaseAI<AxAICohereModel, AxAICohereEmbedModel,
1081
1133
  constructor({ apiKey, config, options, models, }: Readonly<Omit<AxAICohereArgs, 'name'>>);
1082
1134
  }
1083
1135
 
1136
+ declare const axModelInfoCohere: AxModelInfo[];
1137
+
1084
1138
  /**
1085
1139
  * DeepSeek: Models for text generation
1086
1140
  */
@@ -1098,6 +1152,8 @@ declare class AxAIDeepSeek extends AxAIOpenAIBase<AxAIDeepSeekModel, undefined>
1098
1152
  constructor({ apiKey, config, options, models, modelInfo, }: Readonly<Omit<AxAIDeepSeekArgs, 'name'>>);
1099
1153
  }
1100
1154
 
1155
+ declare const axModelInfoDeepSeek: AxModelInfo[];
1156
+
1101
1157
  declare enum AxAIGoogleGeminiModel {
1102
1158
  Gemini25Pro = "gemini-2.5-pro",
1103
1159
  Gemini25Flash = "gemini-2.5-flash",
@@ -1338,7 +1394,7 @@ interface AxAIGoogleGeminiOptionsTools {
1338
1394
  }
1339
1395
  interface AxAIGoogleGeminiArgs {
1340
1396
  name: 'google-gemini';
1341
- apiKey?: string;
1397
+ apiKey?: string | (() => Promise<string>);
1342
1398
  projectId?: string;
1343
1399
  region?: string;
1344
1400
  endpointId?: string;
@@ -1354,6 +1410,11 @@ declare class AxAIGoogleGemini extends AxBaseAI<AxAIGoogleGeminiModel, AxAIGoogl
1354
1410
  constructor({ apiKey, projectId, region, endpointId, config, options, models, modelInfo, }: Readonly<Omit<AxAIGoogleGeminiArgs, 'name'>>);
1355
1411
  }
1356
1412
 
1413
+ /**
1414
+ * AxAIGoogleGemini: Model information
1415
+ */
1416
+ declare const axModelInfoGoogleGemini: AxModelInfo[];
1417
+
1357
1418
  declare enum AxAIGroqModel {
1358
1419
  Llama3_8B = "llama3-8b-8192",
1359
1420
  Llama33_70B = "llama-3.3-70b-versatile",
@@ -1373,6 +1434,11 @@ declare class AxAIGroq extends AxAIOpenAIBase<AxAIGroqModel, undefined> {
1373
1434
  private newRateLimiter;
1374
1435
  }
1375
1436
 
1437
+ /**
1438
+ * AxAIGroq: Model information
1439
+ */
1440
+ declare const axModelInfoGroq: AxModelInfo[];
1441
+
1376
1442
  declare enum AxAIHuggingFaceModel {
1377
1443
  MetaLlama270BChatHF = "meta-llama/Llama-2-70b-chat-hf"
1378
1444
  }
@@ -1420,10 +1486,42 @@ declare class AxAIHuggingFace extends AxBaseAI<AxAIHuggingFaceModel, unknown, Ax
1420
1486
  constructor({ apiKey, config, options, models, }: Readonly<Omit<AxAIHuggingFaceArgs, 'name'>>);
1421
1487
  }
1422
1488
 
1423
- declare enum AxAIMistralModel {
1424
- Mistral7B = "open-mistral-7b",
1425
- Mistral8x7B = "open-mixtral-8x7b",
1426
- MistralSmall = "mistral-small-latest",
1489
+ /**
1490
+ * HuggingFace: Model information
1491
+ */
1492
+ declare const axModelInfoHuggingFace: AxModelInfo[];
1493
+
1494
+ interface AxAIMetricsInstruments {
1495
+ latencyHistogram?: Histogram;
1496
+ errorCounter?: Counter;
1497
+ requestCounter?: Counter;
1498
+ tokenCounter?: Counter;
1499
+ inputTokenCounter?: Counter;
1500
+ outputTokenCounter?: Counter;
1501
+ errorRateGauge?: Gauge;
1502
+ meanLatencyGauge?: Gauge;
1503
+ p95LatencyGauge?: Gauge;
1504
+ p99LatencyGauge?: Gauge;
1505
+ streamingRequestsCounter?: Counter;
1506
+ functionCallsCounter?: Counter;
1507
+ functionCallLatencyHistogram?: Histogram;
1508
+ requestSizeHistogram?: Histogram;
1509
+ responseSizeHistogram?: Histogram;
1510
+ temperatureGauge?: Gauge;
1511
+ maxTokensGauge?: Gauge;
1512
+ estimatedCostCounter?: Counter;
1513
+ promptLengthHistogram?: Histogram;
1514
+ contextWindowUsageGauge?: Gauge;
1515
+ timeoutsCounter?: Counter;
1516
+ abortsCounter?: Counter;
1517
+ thinkingBudgetUsageCounter?: Counter;
1518
+ multimodalRequestsCounter?: Counter;
1519
+ }
1520
+
1521
+ declare enum AxAIMistralModel {
1522
+ Mistral7B = "open-mistral-7b",
1523
+ Mistral8x7B = "open-mixtral-8x7b",
1524
+ MistralSmall = "mistral-small-latest",
1427
1525
  MistralNemo = "mistral-nemo-latest",
1428
1526
  MistralLarge = "mistral-large-latest",
1429
1527
  Codestral = "codestral-latest",
@@ -1480,6 +1578,130 @@ declare class AxAIMistral extends AxAIOpenAIBase<AxAIMistralModel, AxAIMistralEm
1480
1578
  private updateMessages;
1481
1579
  }
1482
1580
 
1581
+ declare const axModelInfoMistral: AxModelInfo[];
1582
+
1583
+ type AxMockAIServiceConfig = {
1584
+ name?: string;
1585
+ id?: string;
1586
+ modelInfo?: Partial<AxModelInfoWithProvider>;
1587
+ embedModelInfo?: AxModelInfoWithProvider;
1588
+ features?: {
1589
+ functions?: boolean;
1590
+ streaming?: boolean;
1591
+ };
1592
+ models?: AxAIModelList;
1593
+ options?: AxAIServiceOptions;
1594
+ chatResponse?: AxChatResponse | ReadableStream<AxChatResponse> | (() => Promise<AxChatResponse | ReadableStream<AxChatResponse>>) | ((req: Readonly<AxChatRequest<unknown>>, options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions<unknown, unknown>>) => Promise<AxChatResponse | ReadableStream<AxChatResponse>>);
1595
+ embedResponse?: AxEmbedResponse | ((req: Readonly<AxEmbedRequest>) => AxEmbedResponse | Promise<AxEmbedResponse>);
1596
+ shouldError?: boolean;
1597
+ errorMessage?: string;
1598
+ latencyMs?: number;
1599
+ };
1600
+ declare class AxMockAIService implements AxAIService {
1601
+ private readonly config;
1602
+ private metrics;
1603
+ constructor(config?: AxMockAIServiceConfig);
1604
+ getLastUsedChatModel(): unknown;
1605
+ getLastUsedEmbedModel(): unknown;
1606
+ getLastUsedModelConfig(): AxModelConfig | undefined;
1607
+ getName(): string;
1608
+ getId(): string;
1609
+ getFeatures(_model?: string): {
1610
+ functions: boolean;
1611
+ streaming: boolean;
1612
+ };
1613
+ getModelList(): AxAIModelList | undefined;
1614
+ getMetrics(): AxAIServiceMetrics;
1615
+ chat(req: Readonly<AxChatRequest<unknown>>, _options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions<unknown, unknown>>): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
1616
+ embed(req: Readonly<AxEmbedRequest>, _options?: Readonly<AxAIServiceActionOptions>): Promise<AxEmbedResponse>;
1617
+ setOptions(options: Readonly<AxAIServiceOptions>): void;
1618
+ getOptions(): Readonly<AxAIServiceOptions>;
1619
+ getLogger(): AxLoggerFunction;
1620
+ private updateMetrics;
1621
+ }
1622
+
1623
+ type AxAIServiceListItem<TModel = unknown, TEmbedModel = unknown> = {
1624
+ key: string;
1625
+ service: AxAIService<TModel, TEmbedModel>;
1626
+ description: string;
1627
+ isInternal?: boolean;
1628
+ };
1629
+ declare class AxMultiServiceRouter implements AxAIService<string, string> {
1630
+ private options?;
1631
+ private lastUsedService?;
1632
+ private services;
1633
+ /**
1634
+ * Constructs a new multi-service router.
1635
+ * It validates that each service provides a unique set of model keys,
1636
+ * then builds a lookup (map) for routing the chat/embed requests.
1637
+ */
1638
+ constructor(services: (AxAIServiceListItem<string, string> | AxAIService<string, string>)[]);
1639
+ getLastUsedChatModel(): string | undefined;
1640
+ getLastUsedEmbedModel(): string | undefined;
1641
+ getLastUsedModelConfig(): AxModelConfig | undefined;
1642
+ /**
1643
+ * Delegates the chat call to the service matching the provided model key.
1644
+ */
1645
+ chat(req: Readonly<AxChatRequest<string>>, options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions<string, string>>): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
1646
+ /**
1647
+ * Delegates the embed call to the service matching the provided embed model key.
1648
+ */
1649
+ embed(req: Readonly<AxEmbedRequest<string>>, options?: Readonly<AxAIServiceActionOptions<string, string>>): Promise<AxEmbedResponse>;
1650
+ /**
1651
+ * Returns a composite ID built from the IDs of the underlying services.
1652
+ */
1653
+ getId(): string;
1654
+ /**
1655
+ * Returns the name of this router.
1656
+ */
1657
+ getName(): string;
1658
+ /**
1659
+ * Aggregates all available models across the underlying services.
1660
+ */
1661
+ getModelList(): AxAIModelList;
1662
+ /**
1663
+ * If a model key is provided, delegate to the corresponding service's features.
1664
+ * Otherwise, returns a default feature set.
1665
+ */
1666
+ getFeatures(model?: string): {
1667
+ functions: boolean;
1668
+ streaming: boolean;
1669
+ functionCot?: boolean;
1670
+ };
1671
+ /**
1672
+ * Returns aggregated metrics from the underlying service.
1673
+ * Uses the metrics from the last service that was used,
1674
+ * or falls back to the first service if none has been used.
1675
+ */
1676
+ getMetrics(): AxAIServiceMetrics;
1677
+ /**
1678
+ * Sets options on all underlying services.
1679
+ */
1680
+ setOptions(options: Readonly<AxAIServiceOptions>): void;
1681
+ /**
1682
+ * Returns the options from the last used service,
1683
+ * or falls back to the first service if none has been used.
1684
+ */
1685
+ getOptions(): Readonly<AxAIServiceOptions>;
1686
+ /**
1687
+ * Returns the logger from the last used service,
1688
+ * or falls back to the first service if none has been used.
1689
+ */
1690
+ getLogger(): AxLoggerFunction;
1691
+ /**
1692
+ * Sets a service entry for a given key. This method is intended for testing purposes.
1693
+ * @param key - The model key
1694
+ * @param entry - The service entry to set
1695
+ */
1696
+ setServiceEntry(key: string, entry: {
1697
+ isInternal?: boolean;
1698
+ description: string;
1699
+ model?: string;
1700
+ embedModel?: string;
1701
+ service: AxAIService<string, string>;
1702
+ }): void;
1703
+ }
1704
+
1483
1705
  type AxAIOllamaAIConfig = AxAIOpenAIConfig<string, string>;
1484
1706
  declare const axAIOllamaDefaultConfig: () => AxAIOllamaAIConfig;
1485
1707
  declare const axAIOllamaDefaultCreativeConfig: () => AxAIOllamaAIConfig;
@@ -1495,6 +1717,15 @@ declare class AxAIOllama extends AxAIOpenAIBase<string, string> {
1495
1717
  constructor({ apiKey, url, config, options, models, }: Readonly<Omit<AxAIOllamaArgs, 'name'>>);
1496
1718
  }
1497
1719
 
1720
+ /**
1721
+ * OpenAI: Model information
1722
+ */
1723
+ declare const axModelInfoOpenAI: AxModelInfo[];
1724
+ /**
1725
+ * OpenAI: Model information
1726
+ */
1727
+ declare const axModelInfoOpenAIResponses: AxModelInfo[];
1728
+
1498
1729
  declare enum AxAIOpenAIResponsesModel {
1499
1730
  GPT4 = "gpt-4",
1500
1731
  GPT41 = "gpt-4.1",
@@ -1987,6 +2218,28 @@ interface AxAIOpenAIResponsesMCPToolCall extends AxAIOpenAIResponsesToolCallBase
1987
2218
  }
1988
2219
  type AxAIOpenAIResponsesToolCall = AxAIOpenAIResponsesFunctionCallItem | AxAIOpenAIResponsesFileSearchToolCall | AxAIOpenAIResponsesWebSearchToolCall | AxAIOpenAIResponsesComputerToolCall | AxAIOpenAIResponsesCodeInterpreterToolCall | AxAIOpenAIResponsesImageGenerationToolCall | AxAIOpenAIResponsesLocalShellToolCall | AxAIOpenAIResponsesMCPToolCall;
1989
2220
 
2221
+ declare class AxAIOpenAIResponsesImpl<TModel, TEmbedModel, // Kept for interface compatibility, but not used by this impl.
2222
+ TResponsesReq extends AxAIOpenAIResponsesRequest<TModel>> implements AxAIServiceImpl<TModel, TEmbedModel, Readonly<AxAIOpenAIResponsesRequest<TModel>>, // ChatReq (now ResponsesReq)
2223
+ Readonly<AxAIOpenAIEmbedRequest<TEmbedModel>>, // EmbedReq
2224
+ Readonly<AxAIOpenAIResponsesResponse>, // ChatResp (now ResponsesResp)
2225
+ Readonly<AxAIOpenAIResponsesResponseDelta>, // ChatRespDelta (now ResponsesRespDelta)
2226
+ Readonly<AxAIOpenAIEmbedResponse>> {
2227
+ private readonly config;
2228
+ private readonly streamingUsage;
2229
+ private readonly responsesReqUpdater?;
2230
+ private tokensUsed;
2231
+ constructor(config: Readonly<AxAIOpenAIResponsesConfig<TModel, TEmbedModel>>, streamingUsage: boolean, // If /v1/responses supports include_usage for streams
2232
+ responsesReqUpdater?: ResponsesReqUpdater<TModel, TResponsesReq> | undefined);
2233
+ getTokenUsage(): Readonly<AxTokenUsage> | undefined;
2234
+ getModelConfig(): Readonly<AxModelConfig>;
2235
+ private mapInternalContentToResponsesInput;
2236
+ private createResponsesReqInternalInput;
2237
+ createChatReq(req: Readonly<AxInternalChatRequest<TModel>>, config: Readonly<AxAIPromptConfig>): [Readonly<AxAPI>, Readonly<AxAIOpenAIResponsesRequest<TModel>>];
2238
+ createChatResp(resp: Readonly<AxAIOpenAIResponsesResponse>): Readonly<AxChatResponse>;
2239
+ createChatStreamResp(streamEvent: Readonly<AxAIOpenAIResponsesResponseDelta>): Readonly<AxChatResponse>;
2240
+ createEmbedReq(req: Readonly<AxInternalEmbedRequest<TEmbedModel>>): [AxAPI, AxAIOpenAIEmbedRequest<TEmbedModel>];
2241
+ }
2242
+
1990
2243
  declare const axAIOpenAIResponsesDefaultConfig: () => AxAIOpenAIResponsesConfig<AxAIOpenAIResponsesModel, AxAIOpenAIEmbedModel>;
1991
2244
  declare const axAIOpenAIResponsesBestConfig: () => AxAIOpenAIResponsesConfig<AxAIOpenAIResponsesModel, AxAIOpenAIEmbedModel>;
1992
2245
  declare const axAIOpenAIResponsesCreativeConfig: () => AxAIOpenAIResponsesConfig<AxAIOpenAIResponsesModel, AxAIOpenAIEmbedModel>;
@@ -2107,6 +2360,11 @@ declare class AxAIReka extends AxBaseAI<AxAIRekaModel, undefined, AxAIRekaChatRe
2107
2360
  constructor({ apiKey, config, options, apiURL, modelInfo, models, }: Readonly<Omit<AxAIRekaArgs, 'name'>>);
2108
2361
  }
2109
2362
 
2363
+ /**
2364
+ * OpenAI: Model information
2365
+ */
2366
+ declare const axModelInfoReka: AxModelInfo[];
2367
+
2110
2368
  type TogetherAIConfig = AxAIOpenAIConfig<string, unknown>;
2111
2369
  declare const axAITogetherDefaultConfig: () => TogetherAIConfig;
2112
2370
  type AxAITogetherArgs = AxAIOpenAIArgs<'together', string, unknown>;
@@ -2114,6 +2372,22 @@ declare class AxAITogether extends AxAIOpenAIBase<string, unknown> {
2114
2372
  constructor({ apiKey, config, options, models, modelInfo, }: Readonly<Omit<AxAITogetherArgs, 'name'>>);
2115
2373
  }
2116
2374
 
2375
+ declare const axModelInfoTogether: AxModelInfo[];
2376
+
2377
+ type AxChatRequestMessage = AxChatRequest['chatPrompt'][number];
2378
+ /**
2379
+ * Validates a chat request message item to ensure it meets the required criteria
2380
+ * @param item - The chat request message to validate
2381
+ * @throws {Error} When validation fails with a descriptive error message
2382
+ */
2383
+ declare function axValidateChatRequestMessage(item: AxChatRequestMessage): void;
2384
+ /**
2385
+ * Validates a chat response result to ensure it meets the required criteria
2386
+ * @param results - The chat response results to validate (single result or array)
2387
+ * @throws {Error} When validation fails with a descriptive error message
2388
+ */
2389
+ declare function axValidateChatResponseResult(results: Readonly<AxChatResponseResult[]> | Readonly<AxChatResponseResult>): void;
2390
+
2117
2391
  type AxAIArgs = AxAIOpenAIArgs | AxAIOpenAIResponsesArgs | AxAIAzureOpenAIArgs | AxAITogetherArgs | AxAIAnthropicArgs | AxAIGroqArgs | AxAIGoogleGeminiArgs | AxAICohereArgs | AxAIHuggingFaceArgs | AxAIMistralArgs | AxAIDeepSeekArgs | AxAIOllamaArgs | AxAIRekaArgs;
2118
2392
  type AxAIModels = AxAIOpenAIModel | AxAIAnthropicModel | AxAIGroqModel | AxAIGoogleGeminiModel | AxAICohereModel | AxAIHuggingFaceModel | AxAIMistralModel | AxAIDeepSeekModel;
2119
2393
  type AxAIEmbedModels = AxAIOpenAIEmbedModel | AxAIGoogleGeminiEmbedModel | AxAICohereEmbedModel;
@@ -2189,54 +2463,199 @@ declare class AxAIGrok extends AxAIOpenAIBase<AxAIGrokModel, AxAIGrokEmbedModels
2189
2463
  constructor({ apiKey, config, options, models, modelInfo, }: Readonly<Omit<AxAIGrokArgs, 'name'>>);
2190
2464
  }
2191
2465
 
2192
- type AxMemoryData = {
2193
- tags?: string[];
2194
- role: AxChatRequest['chatPrompt'][number]['role'];
2195
- updatable?: boolean;
2196
- chat: {
2197
- index: number;
2198
- value: Omit<AxChatRequest['chatPrompt'][number], 'role'>;
2199
- }[];
2200
- }[];
2201
- interface AxAIMemory {
2202
- addRequest(result: AxChatRequest['chatPrompt'], sessionId?: string): void;
2203
- addResponse(results: Readonly<AxChatResponseResult[]>, sessionId?: string): void;
2204
- updateResult(results: Readonly<AxChatResponseResult> & {
2205
- delta?: string;
2206
- }, sessionId?: string): void;
2207
- addFunctionResults(results: Readonly<AxFunctionResult[]>, sessionId?: string): void;
2208
- history(index: number, sessionId?: string): AxChatRequest['chatPrompt'];
2209
- reset(sessionId?: string): void;
2210
- getLast(sessionId?: string): AxMemoryData[number] | undefined;
2211
- addTag(name: string, sessionId?: string): void;
2212
- rewindToTag(name: string, sessionId?: string): AxMemoryData;
2213
- }
2466
+ declare const axModelInfoGrok: AxModelInfo[];
2214
2467
 
2215
- interface AxField {
2216
- name: string;
2217
- title?: string;
2218
- description?: string;
2219
- type?: {
2220
- name: 'string' | 'number' | 'boolean' | 'json' | 'image' | 'audio' | 'date' | 'datetime' | 'class' | 'code';
2221
- isArray?: boolean;
2222
- options?: string[];
2223
- };
2224
- isOptional?: boolean;
2225
- isInternal?: boolean;
2226
- }
2227
- type AxIField = Omit<AxField, 'title'> & {
2228
- title: string;
2468
+ type AxDBUpsertRequest = {
2469
+ id: string;
2470
+ text?: string;
2471
+ values?: readonly number[];
2472
+ metadata?: Record<string, string>;
2473
+ table: string;
2474
+ namespace?: string;
2229
2475
  };
2230
- interface AxSignatureConfig {
2231
- description?: string;
2232
- inputs: readonly AxField[];
2233
- outputs: readonly AxField[];
2234
- }
2235
- declare class AxSignature {
2236
- private description?;
2237
- private inputFields;
2238
- private outputFields;
2239
- private sigHash;
2476
+ type AxDBUpsertResponse = {
2477
+ ids: string[];
2478
+ };
2479
+ type AxDBQueryRequest = {
2480
+ id?: string;
2481
+ text?: string;
2482
+ values?: readonly number[];
2483
+ table: string;
2484
+ columns?: string[];
2485
+ limit?: number;
2486
+ namespace?: string;
2487
+ };
2488
+ type AxDBQueryResponse = {
2489
+ matches: {
2490
+ id: string;
2491
+ score: number;
2492
+ metadata?: Record<string, string>;
2493
+ table?: string;
2494
+ }[];
2495
+ };
2496
+ interface AxDBService extends AxDBQueryService {
2497
+ upsert(req: Readonly<AxDBUpsertRequest>, update?: boolean): Promise<AxDBUpsertResponse>;
2498
+ batchUpsert(batchReq: Readonly<AxDBUpsertRequest[]>, update?: boolean): Promise<AxDBUpsertResponse>;
2499
+ }
2500
+ interface AxDBQueryService {
2501
+ query(req: Readonly<AxDBQueryRequest>): Promise<AxDBQueryResponse>;
2502
+ }
2503
+
2504
+ interface AxDBBaseArgs {
2505
+ fetch?: typeof fetch;
2506
+ tracer?: Tracer;
2507
+ }
2508
+ interface AxDBBaseOpOptions {
2509
+ span?: Span;
2510
+ }
2511
+ declare class AxDBBase implements AxDBService {
2512
+ protected name: string;
2513
+ protected fetch?: typeof fetch;
2514
+ private tracer?;
2515
+ _upsert?: (req: Readonly<AxDBUpsertRequest>, update?: boolean, options?: Readonly<AxDBBaseOpOptions>) => Promise<AxDBUpsertResponse>;
2516
+ _batchUpsert?: (batchReq: Readonly<AxDBUpsertRequest[]>, update?: boolean, options?: Readonly<AxDBBaseOpOptions>) => Promise<AxDBUpsertResponse>;
2517
+ _query?: (req: Readonly<AxDBQueryRequest>, options?: Readonly<AxDBBaseOpOptions>) => Promise<AxDBQueryResponse>;
2518
+ constructor({ name, fetch, tracer, }: Readonly<AxDBBaseArgs & {
2519
+ name: string;
2520
+ }>);
2521
+ upsert(req: Readonly<AxDBUpsertRequest>, update?: boolean): Promise<AxDBUpsertResponse>;
2522
+ batchUpsert(req: Readonly<AxDBUpsertRequest[]>, update?: boolean): Promise<AxDBUpsertResponse>;
2523
+ query(req: Readonly<AxDBQueryRequest>): Promise<AxDBQueryResponse>;
2524
+ }
2525
+
2526
+ type AxDBCloudflareOpOptions = AxDBBaseOpOptions;
2527
+ interface AxDBCloudflareArgs extends AxDBBaseArgs {
2528
+ name: 'cloudflare';
2529
+ apiKey: string;
2530
+ accountId: string;
2531
+ fetch?: typeof fetch;
2532
+ }
2533
+ /**
2534
+ * Cloudflare: DB Service
2535
+ */
2536
+ declare class AxDBCloudflare extends AxDBBase {
2537
+ private apiKey;
2538
+ private accountId;
2539
+ constructor({ apiKey, accountId, fetch, tracer, }: Readonly<Omit<AxDBCloudflareArgs, 'name'>>);
2540
+ _upsert: (req: Readonly<AxDBUpsertRequest>, _update?: boolean, options?: Readonly<AxDBCloudflareOpOptions>) => Promise<AxDBUpsertResponse>;
2541
+ batchUpsert: (batchReq: Readonly<AxDBUpsertRequest[]>, update?: boolean, options?: Readonly<AxDBCloudflareOpOptions>) => Promise<AxDBUpsertResponse>;
2542
+ query: (req: Readonly<AxDBQueryRequest>, options?: Readonly<AxDBCloudflareOpOptions>) => Promise<AxDBQueryResponse>;
2543
+ }
2544
+
2545
+ type AxDBMemoryOpOptions = AxDBBaseOpOptions;
2546
+ interface AxDBMemoryArgs extends AxDBBaseArgs {
2547
+ name: 'memory';
2548
+ }
2549
+ type AxDBState = Record<string, Record<string, AxDBUpsertRequest>>;
2550
+ /**
2551
+ * MemoryDB: DB Service
2552
+ */
2553
+ declare class AxDBMemory extends AxDBBase {
2554
+ private state;
2555
+ constructor({ tracer }?: Readonly<Omit<AxDBMemoryArgs, 'name'>>);
2556
+ _upsert: (req: Readonly<AxDBUpsertRequest>, _update?: boolean, _options?: Readonly<AxDBMemoryOpOptions>) => Promise<AxDBUpsertResponse>;
2557
+ _batchUpsert: (batchReq: Readonly<AxDBUpsertRequest[]>, update?: boolean, _options?: Readonly<AxDBMemoryOpOptions>) => Promise<AxDBUpsertResponse>;
2558
+ _query: (req: Readonly<AxDBQueryRequest>, _options?: Readonly<AxDBMemoryOpOptions>) => Promise<AxDBQueryResponse>;
2559
+ getDB: () => AxDBState;
2560
+ setDB: (state: AxDBState) => void;
2561
+ clearDB: () => void;
2562
+ }
2563
+
2564
+ type AxDBPineconeOpOptions = AxDBBaseOpOptions;
2565
+ interface AxDBPineconeArgs extends AxDBBaseArgs {
2566
+ name: 'pinecone';
2567
+ apiKey: string;
2568
+ host: string;
2569
+ fetch?: typeof fetch;
2570
+ }
2571
+ /**
2572
+ * Pinecone: DB Service
2573
+ */
2574
+ declare class AxDBPinecone extends AxDBBase {
2575
+ private apiKey;
2576
+ private apiURL;
2577
+ constructor({ apiKey, host, fetch, tracer, }: Readonly<Omit<AxDBPineconeArgs, 'name'>>);
2578
+ _upsert: (req: Readonly<AxDBUpsertRequest>, update?: boolean, options?: Readonly<AxDBPineconeOpOptions>) => Promise<AxDBUpsertResponse>;
2579
+ _batchUpsert: (batchReq: Readonly<AxDBUpsertRequest[]>, _update?: boolean, options?: Readonly<AxDBPineconeOpOptions>) => Promise<AxDBUpsertResponse>;
2580
+ query: (req: Readonly<AxDBQueryRequest>, options?: Readonly<AxDBPineconeOpOptions>) => Promise<AxDBQueryResponse>;
2581
+ }
2582
+
2583
+ type AxDBWeaviateOpOptions = AxDBBaseOpOptions;
2584
+ interface AxDBWeaviateArgs extends AxDBBaseArgs {
2585
+ name: 'weaviate';
2586
+ apiKey: string;
2587
+ host: string;
2588
+ fetch?: typeof fetch;
2589
+ }
2590
+ /**
2591
+ * Weaviate: DB Service
2592
+ */
2593
+ declare class AxDBWeaviate extends AxDBBase {
2594
+ private apiKey;
2595
+ private apiURL;
2596
+ constructor({ apiKey, host, fetch, tracer, }: Readonly<Omit<AxDBWeaviateArgs, 'name'>>);
2597
+ _upsert: (req: Readonly<AxDBUpsertRequest>, update?: boolean, options?: Readonly<AxDBWeaviateOpOptions>) => Promise<AxDBUpsertResponse>;
2598
+ _batchUpsert: (batchReq: Readonly<AxDBUpsertRequest[]>, update?: boolean, options?: Readonly<AxDBWeaviateOpOptions>) => Promise<AxDBUpsertResponse>;
2599
+ _query: (req: Readonly<AxDBQueryRequest>, options?: Readonly<AxDBWeaviateOpOptions>) => Promise<AxDBQueryResponse>;
2600
+ }
2601
+
2602
+ type AxDBArgs = AxDBCloudflareArgs | AxDBPineconeArgs | AxDBWeaviateArgs | AxDBMemoryArgs;
2603
+ declare class AxDB implements AxDBService {
2604
+ private db;
2605
+ constructor(args: Readonly<AxDBArgs>);
2606
+ upsert(req: Readonly<AxDBUpsertRequest>, update?: boolean): Promise<AxDBUpsertResponse>;
2607
+ batchUpsert(batchReq: Readonly<AxDBUpsertRequest[]>, update?: boolean): Promise<AxDBUpsertResponse>;
2608
+ query(req: Readonly<AxDBQueryRequest>): Promise<AxDBQueryResponse>;
2609
+ }
2610
+
2611
+ type AxMemoryData = {
2612
+ tags?: string[];
2613
+ role: AxChatRequest['chatPrompt'][number]['role'];
2614
+ updatable?: boolean;
2615
+ chat: {
2616
+ index: number;
2617
+ value: Omit<AxChatRequest['chatPrompt'][number], 'role'>;
2618
+ }[];
2619
+ }[];
2620
+ interface AxAIMemory {
2621
+ addRequest(result: AxChatRequest['chatPrompt'], sessionId?: string): void;
2622
+ addResponse(results: Readonly<AxChatResponseResult[]>, sessionId?: string): void;
2623
+ updateResult(results: Readonly<AxChatResponseResult> & {
2624
+ delta?: string;
2625
+ }, sessionId?: string): void;
2626
+ addFunctionResults(results: Readonly<AxFunctionResult[]>, sessionId?: string): void;
2627
+ history(index: number, sessionId?: string): AxChatRequest['chatPrompt'];
2628
+ reset(sessionId?: string): void;
2629
+ getLast(sessionId?: string): AxMemoryData[number] | undefined;
2630
+ addTag(name: string, sessionId?: string): void;
2631
+ rewindToTag(name: string, sessionId?: string): AxMemoryData;
2632
+ }
2633
+
2634
+ interface AxField {
2635
+ name: string;
2636
+ title?: string;
2637
+ description?: string;
2638
+ type?: {
2639
+ name: 'string' | 'number' | 'boolean' | 'json' | 'image' | 'audio' | 'date' | 'datetime' | 'class' | 'code';
2640
+ isArray?: boolean;
2641
+ options?: string[];
2642
+ };
2643
+ isOptional?: boolean;
2644
+ isInternal?: boolean;
2645
+ }
2646
+ type AxIField = Omit<AxField, 'title'> & {
2647
+ title: string;
2648
+ };
2649
+ interface AxSignatureConfig {
2650
+ description?: string;
2651
+ inputs: readonly AxField[];
2652
+ outputs: readonly AxField[];
2653
+ }
2654
+ declare class AxSignature {
2655
+ private description?;
2656
+ private inputFields;
2657
+ private outputFields;
2658
+ private sigHash;
2240
2659
  private sigString;
2241
2660
  private validatedAtHash?;
2242
2661
  constructor(signature?: Readonly<AxSignature | string | AxSignatureConfig>);
@@ -2510,6 +2929,7 @@ type AxProgramForwardOptions = {
2510
2929
  functions?: AxInputFunctionType;
2511
2930
  functionCall?: AxChatRequest['functionCall'];
2512
2931
  stopFunction?: string;
2932
+ functionResultFormatter?: (result: unknown) => string;
2513
2933
  fastFail?: boolean;
2514
2934
  debug?: boolean;
2515
2935
  debugHideSystemPrompt?: boolean;
@@ -2579,77 +2999,148 @@ declare class AxProgram<IN extends AxGenIn, OUT extends AxGenOut> implements AxT
2579
2999
  setDemos(demos: readonly AxProgramDemos<IN, OUT>[]): void;
2580
3000
  }
2581
3001
 
2582
- /**
2583
- * Interface for agents that can be used as child agents.
2584
- * Provides methods to get the agent's function definition and features.
2585
- */
2586
- interface AxAgentic<IN extends AxGenIn, OUT extends AxGenOut> extends AxTunable<IN, OUT>, AxUsable {
2587
- getFunction(): AxFunction;
2588
- getFeatures(): AxAgentFeatures;
2589
- }
2590
- type AxAgentOptions = Omit<AxProgramForwardOptions, 'functions'> & {
2591
- disableSmartModelRouting?: boolean;
2592
- /** List of field names that should not be automatically passed from parent to child agents */
2593
- excludeFieldsFromPassthrough?: string[];
2594
- debug?: boolean;
3002
+ type AxRewriteIn = {
3003
+ query: string;
2595
3004
  };
2596
- interface AxAgentFeatures {
2597
- /** Whether this agent can use smart model routing (requires an AI service) */
2598
- canConfigureSmartModelRouting: boolean;
2599
- /** List of fields that this agent excludes from parent->child value passing */
2600
- excludeFieldsFromPassthrough: string[];
3005
+ type AxRewriteOut = {
3006
+ rewrittenQuery: string;
3007
+ };
3008
+ type AxRerankerIn = {
3009
+ query: string;
3010
+ items: string[];
3011
+ };
3012
+ type AxRerankerOut = {
3013
+ rankedItems: string[];
3014
+ };
3015
+ interface AxDBLoaderOptions {
3016
+ chunker?: (text: string) => string[];
3017
+ rewriter?: AxProgram<AxRewriteIn, AxRewriteOut>;
3018
+ reranker?: AxProgram<AxRerankerIn, AxRerankerOut>;
2601
3019
  }
2602
- /**
2603
- * An AI agent that can process inputs using an AI service and coordinate with child agents.
2604
- * Supports features like smart model routing and automatic input field passing to child agents.
2605
- */
2606
- declare class AxAgent<IN extends AxGenIn, OUT extends AxGenOut> implements AxAgentic<IN, OUT> {
2607
- private ai?;
2608
- private program;
2609
- private functions?;
2610
- private agents?;
2611
- private disableSmartModelRouting?;
2612
- private excludeFieldsFromPassthrough;
2613
- private debug?;
2614
- private name;
2615
- private func;
2616
- constructor({ ai, name, description, definition, signature, agents, functions, }: Readonly<{
2617
- ai?: Readonly<AxAIService>;
2618
- name: string;
2619
- description: string;
2620
- definition?: string;
2621
- signature: NonNullable<ConstructorParameters<typeof AxSignature>[0]>;
2622
- agents?: AxAgentic<IN, OUT>[];
2623
- functions?: AxInputFunctionType;
2624
- }>, options?: Readonly<AxAgentOptions>);
2625
- setExamples(examples: Readonly<AxProgramExamples<IN, OUT>>, options?: Readonly<AxSetExamplesOptions>): void;
2626
- setId(id: string): void;
2627
- setParentId(parentId: string): void;
2628
- getTraces(): AxProgramTrace<IN, OUT>[];
2629
- setDemos(demos: readonly AxProgramDemos<IN, OUT>[]): void;
2630
- getUsage(): (AxModelUsage & {
2631
- ai: string;
2632
- model: string;
2633
- })[];
2634
- resetUsage(): void;
2635
- getFunction(): AxFunction;
2636
- getFeatures(): AxAgentFeatures;
2637
- /**
2638
- * Initializes the agent's execution context, processing child agents and their functions.
2639
- */
2640
- private init;
2641
- forward(parentAi: Readonly<AxAIService>, values: IN | AxMessage<IN>[], options?: Readonly<AxProgramForwardOptions>): Promise<OUT>;
2642
- streamingForward(parentAi: Readonly<AxAIService>, values: IN | AxMessage<IN>[], options?: Readonly<AxProgramStreamingForwardOptions>): AxGenStreamingOut<OUT>;
3020
+ interface AxDBManagerArgs {
3021
+ ai: AxAIService;
3022
+ db: AxDBService;
3023
+ config?: AxDBLoaderOptions;
3024
+ }
3025
+ interface AxDBMatch {
3026
+ score: number;
3027
+ text: string;
3028
+ }
3029
+ declare class AxDBManager {
3030
+ private ai;
3031
+ private db;
3032
+ private chunker;
3033
+ private rewriter?;
3034
+ private reranker?;
3035
+ constructor({ ai, db, config }: Readonly<AxDBManagerArgs>);
3036
+ private defaultChunker;
3037
+ insert: (text: Readonly<string | string[]>, options?: Readonly<{
3038
+ batchSize?: number;
3039
+ maxWordsPerChunk?: number;
3040
+ minWordsPerChunk?: number;
3041
+ abortSignal?: AbortSignal;
3042
+ }>) => Promise<void>;
3043
+ query: (query: Readonly<string | string[] | number | number[]>, { topPercent, abortSignal, }?: Readonly<{
3044
+ topPercent?: number;
3045
+ abortSignal?: AbortSignal;
3046
+ }> | undefined) => Promise<AxDBMatch[][]>;
3047
+ }
3048
+
3049
+ type AxFieldProcessorProcess = (value: AxFieldValue, context?: Readonly<{
3050
+ values?: AxGenOut;
3051
+ sessionId?: string;
3052
+ done?: boolean;
3053
+ }>) => unknown | Promise<unknown>;
3054
+ type AxStreamingFieldProcessorProcess = (value: string, context?: Readonly<{
3055
+ values?: AxGenOut;
3056
+ sessionId?: string;
3057
+ done?: boolean;
3058
+ }>) => unknown | Promise<unknown>;
3059
+ interface AxFieldProcessor {
3060
+ field: Readonly<AxField>;
2643
3061
  /**
2644
- * Updates the agent's description.
2645
- * This updates both the stored description and the function's description.
2646
- *
2647
- * @param description - New description for the agent (must be at least 20 characters)
2648
- * @throws Error if description is too short
3062
+ * Process the field value and return a new value (or undefined if no update is needed).
3063
+ * The returned value may be merged back into memory.
3064
+ * @param value - The current field value.
3065
+ * @param context - Additional context (e.g. memory and session id).
2649
3066
  */
2650
- setDescription(description: string): void;
2651
- setDefinition(definition: string): void;
2652
- private getDebug;
3067
+ process: AxFieldProcessorProcess | AxStreamingFieldProcessorProcess;
3068
+ }
3069
+
3070
+ type AxGenerateResult<OUT extends AxGenOut> = OUT & {
3071
+ thought?: string;
3072
+ };
3073
+ interface AxResponseHandlerArgs<T> {
3074
+ ai: Readonly<AxAIService>;
3075
+ model?: string;
3076
+ res: T;
3077
+ mem: AxAIMemory;
3078
+ sessionId?: string;
3079
+ traceId?: string;
3080
+ functions: Readonly<AxFunction[]>;
3081
+ strictMode?: boolean;
3082
+ span?: Span;
3083
+ }
3084
+ interface AxStreamingEvent<T> {
3085
+ event: 'delta' | 'done' | 'error';
3086
+ data: {
3087
+ contentDelta?: string;
3088
+ partialValues?: Partial<T>;
3089
+ error?: string;
3090
+ functions?: AxChatResponseFunctionCall[];
3091
+ };
3092
+ }
3093
+ declare class AxGen<IN extends AxGenIn = AxGenIn, OUT extends AxGenOut = AxGenOut> extends AxProgram<IN, OUT> {
3094
+ private promptTemplate;
3095
+ private asserts;
3096
+ private streamingAsserts;
3097
+ private options?;
3098
+ private functions?;
3099
+ private fieldProcessors;
3100
+ private streamingFieldProcessors;
3101
+ private excludeContentFromTrace;
3102
+ private thoughtFieldName;
3103
+ constructor(signature: NonNullable<ConstructorParameters<typeof AxSignature>[0]>, options?: Readonly<AxProgramForwardOptions>);
3104
+ private getSignatureName;
3105
+ private getMetricsInstruments;
3106
+ updateMeter(meter?: Meter): void;
3107
+ private createStates;
3108
+ addAssert: (fn: AxAssertion["fn"], message?: string) => void;
3109
+ addStreamingAssert: (fieldName: string, fn: AxStreamingAssertion["fn"], message?: string) => void;
3110
+ private addFieldProcessorInternal;
3111
+ addStreamingFieldProcessor: (fieldName: string, fn: AxFieldProcessor["process"]) => void;
3112
+ addFieldProcessor: (fieldName: string, fn: AxFieldProcessor["process"]) => void;
3113
+ private forwardSendRequest;
3114
+ private forwardCore;
3115
+ private _forward2;
3116
+ _forward1(ai: Readonly<AxAIService>, values: IN | AxMessage<IN>[], options: Readonly<AxProgramForwardOptions>): AxGenStreamingOut<OUT>;
3117
+ forward(ai: Readonly<AxAIService>, values: IN | AxMessage<IN>[], options?: Readonly<AxProgramForwardOptions>): Promise<OUT>;
3118
+ streamingForward(ai: Readonly<AxAIService>, values: IN | AxMessage<IN>[], options?: Readonly<AxProgramStreamingForwardOptions>): AxGenStreamingOut<OUT>;
3119
+ setExamples(examples: Readonly<AxProgramExamples<IN, OUT>>, options?: Readonly<AxSetExamplesOptions>): void;
3120
+ private isDebug;
3121
+ private getLogger;
3122
+ }
3123
+ type AxGenerateErrorDetails = {
3124
+ model?: string;
3125
+ maxTokens?: number;
3126
+ streaming: boolean;
3127
+ signature: {
3128
+ input: Readonly<AxIField[]>;
3129
+ output: Readonly<AxIField[]>;
3130
+ description?: string;
3131
+ };
3132
+ };
3133
+ type ErrorOptions = {
3134
+ cause?: Error;
3135
+ };
3136
+ declare class AxGenerateError extends Error {
3137
+ readonly details: AxGenerateErrorDetails;
3138
+ constructor(message: string, details: Readonly<AxGenerateErrorDetails>, options?: ErrorOptions);
3139
+ }
3140
+
3141
+ declare class AxDefaultResultReranker extends AxGen<AxRerankerIn, AxRerankerOut> {
3142
+ constructor(options?: Readonly<AxProgramForwardOptions>);
3143
+ forward: (ai: Readonly<AxAIService>, input: Readonly<AxRerankerIn>, options?: Readonly<AxProgramForwardOptions>) => Promise<AxRerankerOut>;
2653
3144
  }
2654
3145
 
2655
3146
  interface AxApacheTikaArgs {
@@ -2670,56 +3161,75 @@ declare class AxApacheTika {
2670
3161
  }>): Promise<string[]>;
2671
3162
  }
2672
3163
 
3164
+ interface AxSimpleClassifierForwardOptions {
3165
+ cutoff?: number;
3166
+ abortSignal?: AbortSignal;
3167
+ }
3168
+ declare class AxSimpleClassifierClass {
3169
+ private readonly name;
3170
+ private readonly context;
3171
+ constructor(name: string, context: readonly string[]);
3172
+ getName(): string;
3173
+ getContext(): readonly string[];
3174
+ }
3175
+ declare class AxSimpleClassifier {
3176
+ private readonly ai;
3177
+ private db;
3178
+ private debug?;
3179
+ constructor(ai: AxAIService);
3180
+ getState(): AxDBState | undefined;
3181
+ setState(state: AxDBState): void;
3182
+ setClasses: (classes: readonly AxSimpleClassifierClass[], options?: Readonly<{
3183
+ abortSignal?: AbortSignal;
3184
+ }>) => Promise<void>;
3185
+ forward(text: string, options?: Readonly<AxSimpleClassifierForwardOptions>): Promise<string>;
3186
+ setOptions(options: Readonly<{
3187
+ debug?: boolean;
3188
+ }>): void;
3189
+ }
3190
+
2673
3191
  /**
2674
- * Options for the balancer.
3192
+ * Calculates the Exact Match (EM) score between a prediction and ground truth.
3193
+ *
3194
+ * The EM score is a strict metric used in machine learning to assess if the predicted
3195
+ * answer matches the ground truth exactly, commonly used in tasks like question answering.
3196
+ *
3197
+ * @param prediction The predicted text.
3198
+ * @param groundTruth The actual correct text.
3199
+ * @returns A number (1.0 for exact match, 0.0 otherwise).
2675
3200
  */
2676
- type AxBalancerOptions = {
2677
- comparator?: (a: AxAIService, b: AxAIService) => number;
2678
- debug?: boolean;
2679
- initialBackoffMs?: number;
2680
- maxBackoffMs?: number;
2681
- maxRetries?: number;
2682
- };
3201
+ declare function emScore(prediction: string, groundTruth: string): number;
2683
3202
  /**
2684
- * Balancer that rotates through services.
3203
+ * Calculates the F1 score between a prediction and ground truth.
3204
+ *
3205
+ * The F1 score is a harmonic mean of precision and recall, widely used in NLP to measure
3206
+ * a model's accuracy in considering both false positives and false negatives, offering a
3207
+ * balance for evaluating classification models.
3208
+ *
3209
+ * @param prediction The predicted text.
3210
+ * @param groundTruth The actual correct text.
3211
+ * @returns The F1 score as a number.
2685
3212
  */
2686
- declare class AxBalancer implements AxAIService<unknown, unknown> {
2687
- private services;
2688
- private currentServiceIndex;
2689
- private currentService;
2690
- private debug;
2691
- private initialBackoffMs;
2692
- private maxBackoffMs;
2693
- private maxRetries;
2694
- private serviceFailures;
2695
- constructor(services: readonly AxAIService[], options?: AxBalancerOptions);
2696
- getLastUsedChatModel(): unknown;
2697
- getLastUsedEmbedModel(): unknown;
2698
- getLastUsedModelConfig(): AxModelConfig | undefined;
2699
- /**
2700
- * Service comparator that respects the input order of services.
2701
- */
2702
- static inputOrderComparator: () => number;
2703
- /**
2704
- * Service comparator that sorts services by cost.
2705
- */
2706
- static metricComparator: (a: AxAIService, b: AxAIService) => number;
2707
- getModelList(): AxAIModelList | undefined;
2708
- private getNextService;
2709
- private reset;
2710
- getName(): string;
2711
- getId(): string;
2712
- getFeatures(model?: string): AxAIFeatures;
2713
- getMetrics(): AxAIServiceMetrics;
2714
- private canRetryService;
2715
- private handleFailure;
2716
- private handleSuccess;
2717
- chat(req: Readonly<AxChatRequest>, options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions> | undefined): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
2718
- embed(req: Readonly<AxEmbedRequest>, options?: Readonly<AxAIServiceActionOptions> | undefined): Promise<AxEmbedResponse>;
2719
- setOptions(options: Readonly<AxAIServiceOptions>): void;
2720
- getOptions(): Readonly<AxAIServiceOptions>;
2721
- getLogger(): AxLoggerFunction;
2722
- }
3213
+ declare function f1Score(prediction: string, groundTruth: string): number;
3214
+ /**
3215
+ * Calculates a novel F1 score, taking into account a history of interaction and excluding stopwords.
3216
+ *
3217
+ * This metric extends the F1 score by considering contextual relevance and filtering out common words
3218
+ * that might skew the assessment of the prediction's quality, especially in conversational models or
3219
+ * when historical context is relevant.
3220
+ *
3221
+ * @param history The historical context or preceding interactions.
3222
+ * @param prediction The predicted text.
3223
+ * @param groundTruth The actual correct text.
3224
+ * @param returnRecall Optionally return the recall score instead of F1.
3225
+ * @returns The novel F1 or recall score as a number.
3226
+ */
3227
+ declare function novelF1ScoreOptimized(history: string, prediction: string, groundTruth: string, returnRecall?: boolean): number;
3228
+ declare const AxEvalUtil: {
3229
+ emScore: typeof emScore;
3230
+ f1Score: typeof f1Score;
3231
+ novelF1ScoreOptimized: typeof novelF1ScoreOptimized;
3232
+ };
2723
3233
 
2724
3234
  type AxExample = Record<string, AxFieldValue>;
2725
3235
  type AxMetricFn = <T extends AxGenOut = AxGenOut>(arg0: Readonly<{
@@ -3243,1411 +3753,830 @@ declare abstract class AxBaseOptimizer<IN extends AxGenIn = AxGenIn, OUT extends
3243
3753
  protected recordPerformanceMetrics(metricType: 'evaluation' | 'demo_generation' | 'metric_computation', duration: number, optimizerType: string): void;
3244
3754
  }
3245
3755
 
3246
- type AxDBUpsertRequest = {
3247
- id: string;
3248
- text?: string;
3249
- values?: readonly number[];
3250
- metadata?: Record<string, string>;
3251
- table: string;
3252
- namespace?: string;
3756
+ type AxEvaluateArgs<IN extends AxGenIn, OUT extends AxGenOut> = {
3757
+ ai: AxAIService;
3758
+ program: Readonly<AxProgram<IN, OUT>>;
3759
+ examples: Readonly<AxExample[]>;
3253
3760
  };
3254
- type AxDBUpsertResponse = {
3255
- ids: string[];
3256
- };
3257
- type AxDBQueryRequest = {
3258
- id?: string;
3259
- text?: string;
3260
- values?: readonly number[];
3261
- table: string;
3262
- columns?: string[];
3263
- limit?: number;
3264
- namespace?: string;
3265
- };
3266
- type AxDBQueryResponse = {
3267
- matches: {
3268
- id: string;
3269
- score: number;
3270
- metadata?: Record<string, string>;
3271
- table?: string;
3272
- }[];
3273
- };
3274
- interface AxDBService extends AxDBQueryService {
3275
- upsert(req: Readonly<AxDBUpsertRequest>, update?: boolean): Promise<AxDBUpsertResponse>;
3276
- batchUpsert(batchReq: Readonly<AxDBUpsertRequest[]>, update?: boolean): Promise<AxDBUpsertResponse>;
3277
- }
3278
- interface AxDBQueryService {
3279
- query(req: Readonly<AxDBQueryRequest>): Promise<AxDBQueryResponse>;
3761
+ declare class AxTestPrompt<IN extends AxGenIn = AxGenIn, OUT extends AxGenOut = AxGenOut> {
3762
+ private ai;
3763
+ private program;
3764
+ private examples;
3765
+ constructor({ ai, program, examples, }: Readonly<AxEvaluateArgs<IN, OUT>>);
3766
+ run(metricFn: AxMetricFn): Promise<void>;
3280
3767
  }
3281
3768
 
3282
- interface AxDBBaseArgs {
3283
- fetch?: typeof fetch;
3284
- tracer?: Tracer;
3285
- }
3286
- interface AxDBBaseOpOptions {
3287
- span?: Span;
3288
- }
3289
- declare class AxDBBase implements AxDBService {
3290
- protected name: string;
3291
- protected fetch?: typeof fetch;
3292
- private tracer?;
3293
- _upsert?: (req: Readonly<AxDBUpsertRequest>, update?: boolean, options?: Readonly<AxDBBaseOpOptions>) => Promise<AxDBUpsertResponse>;
3294
- _batchUpsert?: (batchReq: Readonly<AxDBUpsertRequest[]>, update?: boolean, options?: Readonly<AxDBBaseOpOptions>) => Promise<AxDBUpsertResponse>;
3295
- _query?: (req: Readonly<AxDBQueryRequest>, options?: Readonly<AxDBBaseOpOptions>) => Promise<AxDBQueryResponse>;
3296
- constructor({ name, fetch, tracer, }: Readonly<AxDBBaseArgs & {
3297
- name: string;
3298
- }>);
3299
- upsert(req: Readonly<AxDBUpsertRequest>, update?: boolean): Promise<AxDBUpsertResponse>;
3300
- batchUpsert(req: Readonly<AxDBUpsertRequest[]>, update?: boolean): Promise<AxDBUpsertResponse>;
3301
- query(req: Readonly<AxDBQueryRequest>): Promise<AxDBQueryResponse>;
3302
- }
3769
+ type AxFunctionResultFormatter = (result: unknown) => string;
3770
+ declare const axGlobals: {
3771
+ signatureStrict: boolean;
3772
+ tracer: Tracer | undefined;
3773
+ meter: Meter | undefined;
3774
+ functionResultFormatter: AxFunctionResultFormatter;
3775
+ };
3303
3776
 
3304
- type AxDBCloudflareOpOptions = AxDBBaseOpOptions;
3305
- interface AxDBCloudflareArgs extends AxDBBaseArgs {
3306
- name: 'cloudflare';
3307
- apiKey: string;
3308
- accountId: string;
3309
- fetch?: typeof fetch;
3310
- }
3311
- /**
3312
- * Cloudflare: DB Service
3313
- */
3314
- declare class AxDBCloudflare extends AxDBBase {
3315
- private apiKey;
3316
- private accountId;
3317
- constructor({ apiKey, accountId, fetch, tracer, }: Readonly<Omit<AxDBCloudflareArgs, 'name'>>);
3318
- _upsert: (req: Readonly<AxDBUpsertRequest>, _update?: boolean, options?: Readonly<AxDBCloudflareOpOptions>) => Promise<AxDBUpsertResponse>;
3319
- batchUpsert: (batchReq: Readonly<AxDBUpsertRequest[]>, update?: boolean, options?: Readonly<AxDBCloudflareOpOptions>) => Promise<AxDBUpsertResponse>;
3320
- query: (req: Readonly<AxDBQueryRequest>, options?: Readonly<AxDBCloudflareOpOptions>) => Promise<AxDBQueryResponse>;
3777
+ type AxDataRow = {
3778
+ row: Record<string, AxFieldValue>;
3779
+ };
3780
+ declare class AxHFDataLoader {
3781
+ private rows;
3782
+ private baseUrl;
3783
+ private dataset;
3784
+ private split;
3785
+ private config;
3786
+ private options?;
3787
+ constructor({ dataset, split, config, options, }: Readonly<{
3788
+ dataset: string;
3789
+ split: string;
3790
+ config: string;
3791
+ options?: Readonly<{
3792
+ offset?: number;
3793
+ length?: number;
3794
+ }>;
3795
+ }>);
3796
+ private fetchDataFromAPI;
3797
+ loadData(): Promise<AxDataRow[]>;
3798
+ setData(rows: AxDataRow[]): void;
3799
+ getData(): AxDataRow[];
3800
+ getRows<T>({ count, fields, renameMap, }: Readonly<{
3801
+ count: number;
3802
+ fields: readonly string[];
3803
+ renameMap?: Record<string, string>;
3804
+ }>): Promise<T[]>;
3321
3805
  }
3322
3806
 
3323
- type AxDBMemoryOpOptions = AxDBBaseOpOptions;
3324
- interface AxDBMemoryArgs extends AxDBBaseArgs {
3325
- name: 'memory';
3326
- }
3327
- type AxDBState = Record<string, Record<string, AxDBUpsertRequest>>;
3807
+ declare const axCreateDefaultColorLogger: (output?: (message: string) => void) => AxLoggerFunction;
3808
+ declare const axCreateDefaultTextLogger: (output?: (message: string) => void) => AxLoggerFunction;
3328
3809
  /**
3329
- * MemoryDB: DB Service
3810
+ * Factory function to create an enhanced optimizer logger with clean visual formatting
3811
+ * that works for all optimizer types using semantic tags for proper categorization
3330
3812
  */
3331
- declare class AxDBMemory extends AxDBBase {
3332
- private state;
3333
- constructor({ tracer }?: Readonly<Omit<AxDBMemoryArgs, 'name'>>);
3334
- _upsert: (req: Readonly<AxDBUpsertRequest>, _update?: boolean, _options?: Readonly<AxDBMemoryOpOptions>) => Promise<AxDBUpsertResponse>;
3335
- _batchUpsert: (batchReq: Readonly<AxDBUpsertRequest[]>, update?: boolean, _options?: Readonly<AxDBMemoryOpOptions>) => Promise<AxDBUpsertResponse>;
3336
- _query: (req: Readonly<AxDBQueryRequest>, _options?: Readonly<AxDBMemoryOpOptions>) => Promise<AxDBQueryResponse>;
3337
- getDB: () => AxDBState;
3338
- setDB: (state: AxDBState) => void;
3339
- clearDB: () => void;
3340
- }
3341
-
3342
- type AxDBPineconeOpOptions = AxDBBaseOpOptions;
3343
- interface AxDBPineconeArgs extends AxDBBaseArgs {
3344
- name: 'pinecone';
3345
- apiKey: string;
3346
- host: string;
3347
- fetch?: typeof fetch;
3348
- }
3813
+ declare const axCreateOptimizerLogger: (output?: (message: string) => void) => AxLoggerFunction;
3349
3814
  /**
3350
- * Pinecone: DB Service
3815
+ * Default optimizer logger instance
3351
3816
  */
3352
- declare class AxDBPinecone extends AxDBBase {
3353
- private apiKey;
3354
- private apiURL;
3355
- constructor({ apiKey, host, fetch, tracer, }: Readonly<Omit<AxDBPineconeArgs, 'name'>>);
3356
- _upsert: (req: Readonly<AxDBUpsertRequest>, update?: boolean, options?: Readonly<AxDBPineconeOpOptions>) => Promise<AxDBUpsertResponse>;
3357
- _batchUpsert: (batchReq: Readonly<AxDBUpsertRequest[]>, _update?: boolean, options?: Readonly<AxDBPineconeOpOptions>) => Promise<AxDBUpsertResponse>;
3358
- query: (req: Readonly<AxDBQueryRequest>, options?: Readonly<AxDBPineconeOpOptions>) => Promise<AxDBQueryResponse>;
3359
- }
3817
+ declare const axDefaultOptimizerLogger: AxLoggerFunction;
3360
3818
 
3361
- type AxDBWeaviateOpOptions = AxDBBaseOpOptions;
3362
- interface AxDBWeaviateArgs extends AxDBBaseArgs {
3363
- name: 'weaviate';
3364
- apiKey: string;
3365
- host: string;
3366
- fetch?: typeof fetch;
3819
+ interface AxMetricsConfig {
3820
+ enabled: boolean;
3821
+ enabledCategories: ('generation' | 'streaming' | 'functions' | 'errors' | 'performance')[];
3822
+ maxLabelLength: number;
3823
+ samplingRate: number;
3367
3824
  }
3368
- /**
3369
- * Weaviate: DB Service
3370
- */
3371
- declare class AxDBWeaviate extends AxDBBase {
3372
- private apiKey;
3373
- private apiURL;
3374
- constructor({ apiKey, host, fetch, tracer, }: Readonly<Omit<AxDBWeaviateArgs, 'name'>>);
3375
- _upsert: (req: Readonly<AxDBUpsertRequest>, update?: boolean, options?: Readonly<AxDBWeaviateOpOptions>) => Promise<AxDBUpsertResponse>;
3376
- _batchUpsert: (batchReq: Readonly<AxDBUpsertRequest[]>, update?: boolean, options?: Readonly<AxDBWeaviateOpOptions>) => Promise<AxDBUpsertResponse>;
3377
- _query: (req: Readonly<AxDBQueryRequest>, options?: Readonly<AxDBWeaviateOpOptions>) => Promise<AxDBQueryResponse>;
3825
+ declare const axDefaultMetricsConfig: AxMetricsConfig;
3826
+ type AxErrorCategory = 'validation_error' | 'assertion_error' | 'timeout_error' | 'abort_error' | 'network_error' | 'auth_error' | 'rate_limit_error' | 'function_error' | 'parsing_error' | 'unknown_error';
3827
+ interface AxGenMetricsInstruments {
3828
+ generationLatencyHistogram?: Histogram;
3829
+ generationRequestsCounter?: Counter;
3830
+ generationErrorsCounter?: Counter;
3831
+ multiStepGenerationsCounter?: Counter;
3832
+ stepsPerGenerationHistogram?: Histogram;
3833
+ maxStepsReachedCounter?: Counter;
3834
+ validationErrorsCounter?: Counter;
3835
+ assertionErrorsCounter?: Counter;
3836
+ errorCorrectionAttemptsHistogram?: Histogram;
3837
+ errorCorrectionSuccessCounter?: Counter;
3838
+ errorCorrectionFailureCounter?: Counter;
3839
+ maxRetriesReachedCounter?: Counter;
3840
+ functionsEnabledGenerationsCounter?: Counter;
3841
+ functionCallStepsCounter?: Counter;
3842
+ functionsExecutedPerGenerationHistogram?: Histogram;
3843
+ functionErrorCorrectionCounter?: Counter;
3844
+ fieldProcessorsExecutedCounter?: Counter;
3845
+ streamingFieldProcessorsExecutedCounter?: Counter;
3846
+ streamingGenerationsCounter?: Counter;
3847
+ streamingDeltasEmittedCounter?: Counter;
3848
+ streamingFinalizationLatencyHistogram?: Histogram;
3849
+ samplesGeneratedHistogram?: Histogram;
3850
+ resultPickerUsageCounter?: Counter;
3851
+ resultPickerLatencyHistogram?: Histogram;
3852
+ inputFieldsGauge?: Gauge;
3853
+ outputFieldsGauge?: Gauge;
3854
+ examplesUsedGauge?: Gauge;
3855
+ demosUsedGauge?: Gauge;
3856
+ promptRenderLatencyHistogram?: Histogram;
3857
+ extractionLatencyHistogram?: Histogram;
3858
+ assertionLatencyHistogram?: Histogram;
3859
+ stateCreationLatencyHistogram?: Histogram;
3860
+ memoryUpdateLatencyHistogram?: Histogram;
3378
3861
  }
3862
+ declare const axCheckMetricsHealth: () => {
3863
+ healthy: boolean;
3864
+ issues: string[];
3865
+ };
3866
+ declare const axUpdateMetricsConfig: (config: Readonly<Partial<AxMetricsConfig>>) => void;
3867
+ declare const axGetMetricsConfig: () => AxMetricsConfig;
3379
3868
 
3380
- type AxDBArgs = AxDBCloudflareArgs | AxDBPineconeArgs | AxDBWeaviateArgs | AxDBMemoryArgs;
3381
- declare class AxDB implements AxDBService {
3382
- private db;
3383
- constructor(args: Readonly<AxDBArgs>);
3384
- upsert(req: Readonly<AxDBUpsertRequest>, update?: boolean): Promise<AxDBUpsertResponse>;
3385
- batchUpsert(batchReq: Readonly<AxDBUpsertRequest[]>, update?: boolean): Promise<AxDBUpsertResponse>;
3386
- query(req: Readonly<AxDBQueryRequest>): Promise<AxDBQueryResponse>;
3869
+ declare class AxBootstrapFewShot<IN extends AxGenIn = AxGenIn, OUT extends AxGenOut = AxGenOut> extends AxBaseOptimizer<IN, OUT> {
3870
+ private maxRounds;
3871
+ private maxDemos;
3872
+ private maxExamples;
3873
+ private batchSize;
3874
+ private earlyStoppingPatience;
3875
+ private costMonitoring;
3876
+ private maxTokensPerGeneration;
3877
+ private verboseMode;
3878
+ private debugMode;
3879
+ private traces;
3880
+ constructor(args: Readonly<AxOptimizerArgs & {
3881
+ options?: AxBootstrapOptimizerOptions;
3882
+ }>);
3883
+ private compileRound;
3884
+ compile(program: Readonly<AxProgram<IN, OUT>>, metricFn: AxMetricFn, options?: AxBootstrapCompileOptions): Promise<AxOptimizerResult<OUT>>;
3387
3885
  }
3388
3886
 
3389
- type AxRewriteIn = {
3390
- query: string;
3391
- };
3392
- type AxRewriteOut = {
3393
- rewrittenQuery: string;
3394
- };
3395
- type AxRerankerIn = {
3396
- query: string;
3397
- items: string[];
3398
- };
3399
- type AxRerankerOut = {
3400
- rankedItems: string[];
3401
- };
3402
- interface AxDBLoaderOptions {
3403
- chunker?: (text: string) => string[];
3404
- rewriter?: AxProgram<AxRewriteIn, AxRewriteOut>;
3405
- reranker?: AxProgram<AxRerankerIn, AxRerankerOut>;
3406
- }
3407
- interface AxDBManagerArgs {
3408
- ai: AxAIService;
3409
- db: AxDBService;
3410
- config?: AxDBLoaderOptions;
3411
- }
3412
- interface AxDBMatch {
3413
- score: number;
3414
- text: string;
3887
+ interface AxMiPROResult<IN extends AxGenIn, OUT extends AxGenOut> extends AxOptimizerResult<OUT> {
3888
+ optimizedGen?: AxGen<IN, OUT>;
3415
3889
  }
3416
- declare class AxDBManager {
3417
- private ai;
3418
- private db;
3419
- private chunker;
3420
- private rewriter?;
3421
- private reranker?;
3422
- constructor({ ai, db, config }: Readonly<AxDBManagerArgs>);
3423
- private defaultChunker;
3424
- insert: (text: Readonly<string | string[]>, options?: Readonly<{
3425
- batchSize?: number;
3426
- maxWordsPerChunk?: number;
3427
- minWordsPerChunk?: number;
3428
- abortSignal?: AbortSignal;
3429
- }>) => Promise<void>;
3430
- query: (query: Readonly<string | string[] | number | number[]>, { topPercent, abortSignal, }?: Readonly<{
3431
- topPercent?: number;
3432
- abortSignal?: AbortSignal;
3433
- }> | undefined) => Promise<AxDBMatch[][]>;
3434
- }
3435
-
3436
- interface AxDockerContainer {
3437
- Id: string;
3438
- Names: string[];
3439
- Image: string;
3440
- ImageID: string;
3441
- Command: string;
3442
- Created: number;
3443
- State: {
3444
- Status: string;
3445
- Running: boolean;
3446
- Paused: boolean;
3447
- Restarting: boolean;
3448
- OOMKilled: boolean;
3449
- Dead: boolean;
3450
- Pid: number;
3451
- ExitCode: number;
3452
- Error: string;
3453
- StartedAt: Date;
3454
- FinishedAt: Date;
3455
- };
3456
- Status: string;
3457
- Ports: Array<{
3458
- IP: string;
3459
- PrivatePort: number;
3460
- PublicPort: number;
3461
- Type: string;
3462
- }>;
3463
- Labels: {
3464
- [key: string]: string;
3465
- };
3466
- SizeRw: number;
3467
- SizeRootFs: number;
3468
- HostConfig: {
3469
- NetworkMode: string;
3470
- };
3471
- NetworkSettings: {
3472
- Networks: {
3473
- [key: string]: {
3474
- IPAddress: string;
3475
- IPPrefixLen: number;
3476
- Gateway: string;
3477
- MacAddress: string;
3478
- };
3479
- };
3480
- };
3481
- Mounts: Array<{
3482
- Type: string;
3483
- Source: string;
3484
- Destination: string;
3485
- Mode: string;
3486
- RW: boolean;
3487
- Propagation: string;
3488
- }>;
3489
- }
3490
- declare class AxDockerSession {
3491
- private readonly apiUrl;
3492
- private containerId;
3493
- constructor(apiUrl?: string);
3494
- pullImage(imageName: string): Promise<void>;
3495
- createContainer({ imageName, volumes, doNotPullImage, tag, }: Readonly<{
3496
- imageName: string;
3497
- volumes?: Array<{
3498
- hostPath: string;
3499
- containerPath: string;
3500
- }>;
3501
- doNotPullImage?: boolean;
3502
- tag?: string;
3503
- }>): Promise<{
3504
- Id: string;
3505
- }>;
3506
- findOrCreateContainer({ imageName, volumes, doNotPullImage, tag, }: Readonly<{
3507
- imageName: string;
3508
- volumes?: Array<{
3509
- hostPath: string;
3510
- containerPath: string;
3511
- }>;
3512
- doNotPullImage?: boolean;
3513
- tag: string;
3514
- }>): Promise<{
3515
- Id: string;
3516
- isNew: boolean;
3517
- }>;
3518
- startContainer(): Promise<void>;
3519
- connectToContainer(containerId: string): Promise<void>;
3520
- stopContainers({ tag, remove, timeout, }: Readonly<{
3521
- tag?: string;
3522
- remove?: boolean;
3523
- timeout?: number;
3524
- }>): Promise<Array<{
3525
- Id: string;
3526
- Action: 'stopped' | 'removed';
3527
- }>>;
3528
- listContainers(all?: boolean): Promise<AxDockerContainer[]>;
3529
- getContainerLogs(): Promise<string>;
3530
- executeCommand(command: string): Promise<string>;
3531
- private getContainerInfo;
3532
- private waitForContainerToBeRunning;
3533
- private fetchDockerAPI;
3534
- toFunction(): AxFunction;
3535
- }
3536
-
3537
- type AxFieldProcessorProcess = (value: AxFieldValue, context?: Readonly<{
3538
- values?: AxGenOut;
3539
- sessionId?: string;
3540
- done?: boolean;
3541
- }>) => unknown | Promise<unknown>;
3542
- type AxStreamingFieldProcessorProcess = (value: string, context?: Readonly<{
3543
- values?: AxGenOut;
3544
- sessionId?: string;
3545
- done?: boolean;
3546
- }>) => unknown | Promise<unknown>;
3547
- interface AxFieldProcessor {
3548
- field: Readonly<AxField>;
3549
- /**
3550
- * Process the field value and return a new value (or undefined if no update is needed).
3551
- * The returned value may be merged back into memory.
3552
- * @param value - The current field value.
3553
- * @param context - Additional context (e.g. memory and session id).
3554
- */
3555
- process: AxFieldProcessorProcess | AxStreamingFieldProcessorProcess;
3556
- }
3557
-
3558
- type AxGenerateResult<OUT extends AxGenOut> = OUT & {
3559
- thought?: string;
3560
- };
3561
- interface AxResponseHandlerArgs<T> {
3562
- ai: Readonly<AxAIService>;
3563
- model?: string;
3564
- res: T;
3565
- mem: AxAIMemory;
3566
- sessionId?: string;
3567
- traceId?: string;
3568
- functions: Readonly<AxFunction[]>;
3569
- strictMode?: boolean;
3570
- span?: Span;
3571
- }
3572
- interface AxStreamingEvent<T> {
3573
- event: 'delta' | 'done' | 'error';
3574
- data: {
3575
- contentDelta?: string;
3576
- partialValues?: Partial<T>;
3577
- error?: string;
3578
- functions?: AxChatResponseFunctionCall[];
3579
- };
3580
- }
3581
- declare class AxGen<IN extends AxGenIn = AxGenIn, OUT extends AxGenOut = AxGenOut> extends AxProgram<IN, OUT> {
3582
- private promptTemplate;
3583
- private asserts;
3584
- private streamingAsserts;
3585
- private options?;
3586
- private functions?;
3587
- private fieldProcessors;
3588
- private streamingFieldProcessors;
3589
- private excludeContentFromTrace;
3590
- private thoughtFieldName;
3591
- constructor(signature: NonNullable<ConstructorParameters<typeof AxSignature>[0]>, options?: Readonly<AxProgramForwardOptions>);
3592
- private getSignatureName;
3593
- private getMetricsInstruments;
3594
- updateMeter(meter?: Meter): void;
3595
- private createStates;
3596
- addAssert: (fn: AxAssertion["fn"], message?: string) => void;
3597
- addStreamingAssert: (fieldName: string, fn: AxStreamingAssertion["fn"], message?: string) => void;
3598
- private addFieldProcessorInternal;
3599
- addStreamingFieldProcessor: (fieldName: string, fn: AxFieldProcessor["process"]) => void;
3600
- addFieldProcessor: (fieldName: string, fn: AxFieldProcessor["process"]) => void;
3601
- private forwardSendRequest;
3602
- private forwardCore;
3603
- private _forward2;
3604
- _forward1(ai: Readonly<AxAIService>, values: IN | AxMessage<IN>[], options: Readonly<AxProgramForwardOptions>): AxGenStreamingOut<OUT>;
3605
- forward(ai: Readonly<AxAIService>, values: IN | AxMessage<IN>[], options?: Readonly<AxProgramForwardOptions>): Promise<OUT>;
3606
- streamingForward(ai: Readonly<AxAIService>, values: IN | AxMessage<IN>[], options?: Readonly<AxProgramStreamingForwardOptions>): AxGenStreamingOut<OUT>;
3607
- setExamples(examples: Readonly<AxProgramExamples<IN, OUT>>, options?: Readonly<AxSetExamplesOptions>): void;
3608
- private isDebug;
3609
- private getLogger;
3610
- }
3611
- type AxGenerateErrorDetails = {
3612
- model?: string;
3613
- maxTokens?: number;
3614
- streaming: boolean;
3615
- signature: {
3616
- input: Readonly<AxIField[]>;
3617
- output: Readonly<AxIField[]>;
3618
- description?: string;
3619
- };
3620
- };
3621
- type ErrorOptions = {
3622
- cause?: Error;
3623
- };
3624
- declare class AxGenerateError extends Error {
3625
- readonly details: AxGenerateErrorDetails;
3626
- constructor(message: string, details: Readonly<AxGenerateErrorDetails>, options?: ErrorOptions);
3627
- }
3628
-
3629
- type AxFlowState = Record<string, unknown>;
3630
- type AxFlowStepFunction = (state: AxFlowState, context: Readonly<{
3631
- mainAi: AxAIService;
3632
- mainOptions?: AxProgramForwardOptions;
3633
- }>) => Promise<AxFlowState> | AxFlowState;
3634
- interface AxFlowDynamicContext {
3635
- ai?: AxAIService;
3636
- options?: AxProgramForwardOptions;
3637
- }
3638
- type GetGenIn<T extends AxGen<AxGenIn, AxGenOut>> = T extends AxGen<infer IN, AxGenOut> ? IN : never;
3639
- type GetGenOut<T extends AxGen<AxGenIn, AxGenOut>> = T extends AxGen<AxGenIn, infer OUT> ? OUT : never;
3640
- type InferAxGen<TSig extends string> = TSig extends string ? AxGen<AxGenIn, AxGenOut> : never;
3641
- type NodeResultKey<TNodeName extends string> = `${TNodeName}Result`;
3642
- type AddNodeResult<TState extends AxFlowState, TNodeName extends string, TNodeOut extends AxGenOut> = TState & {
3643
- [K in NodeResultKey<TNodeName>]: TNodeOut;
3644
- };
3645
- type AxFlowTypedParallelBranch<TNodes extends Record<string, AxGen<any, any>>, TState extends AxFlowState> = (subFlow: AxFlowTypedSubContext<TNodes, TState>) => AxFlowTypedSubContext<TNodes, AxFlowState>;
3646
- interface AxFlowTypedSubContext<TNodes extends Record<string, AxGen<any, any>>, TState extends AxFlowState> {
3647
- execute<TNodeName extends keyof TNodes & string>(nodeName: TNodeName, mapping: (state: TState) => GetGenIn<TNodes[TNodeName]>, dynamicContext?: AxFlowDynamicContext): AxFlowTypedSubContext<TNodes, AddNodeResult<TState, TNodeName, GetGenOut<TNodes[TNodeName]>>>;
3648
- map<TNewState extends AxFlowState>(transform: (state: TState) => TNewState): AxFlowTypedSubContext<TNodes, TNewState>;
3649
- executeSteps(initialState: TState, context: Readonly<{
3650
- mainAi: AxAIService;
3651
- mainOptions?: AxProgramForwardOptions;
3652
- }>): Promise<AxFlowState>;
3653
- }
3654
- type AxFlowParallelBranch = (subFlow: AxFlowSubContext) => AxFlowSubContext;
3655
- interface AxFlowSubContext {
3656
- execute(nodeName: string, mapping: (state: AxFlowState) => Record<string, AxFieldValue>, dynamicContext?: AxFlowDynamicContext): this;
3657
- map(transform: (state: AxFlowState) => AxFlowState): this;
3658
- executeSteps(initialState: AxFlowState, context: Readonly<{
3659
- mainAi: AxAIService;
3660
- mainOptions?: AxProgramForwardOptions;
3661
- }>): Promise<AxFlowState>;
3662
- }
3663
- interface AxFlowExecutionStep {
3664
- type: 'execute' | 'map' | 'other';
3665
- nodeName?: string;
3666
- dependencies: string[];
3667
- produces: string[];
3668
- stepFunction: AxFlowStepFunction;
3669
- stepIndex: number;
3670
- }
3671
- interface AxFlowParallelGroup {
3672
- level: number;
3673
- steps: AxFlowExecutionStep[];
3674
- }
3675
- /**
3676
- * AxFlow - A fluent, chainable API for building and orchestrating complex, stateful AI programs.
3677
- *
3678
- * Now with advanced type-safe chaining where each method call evolves the type information,
3679
- * providing compile-time type safety and superior IntelliSense.
3680
- *
3681
- * @example
3682
- * ```typescript
3683
- * const flow = new AxFlow<{ topic: string }, { finalAnswer: string }>()
3684
- * .node('summarizer', 'text:string -> summary:string')
3685
- * .node('critic', 'summary:string -> critique:string')
3686
- * .execute('summarizer', state => ({ text: `About ${state.topic}` })) // state is { topic: string }
3687
- * .execute('critic', state => ({ summary: state.summarizerResult.summary })) // state evolves!
3688
- * .map(state => ({ finalAnswer: state.criticResult.critique })) // fully typed!
3689
- *
3690
- * const result = await flow.forward(ai, { topic: "AI safety" })
3691
- * ```
3692
- */
3693
- declare class AxFlow<IN extends AxGenIn, OUT extends AxGenOut, TNodes extends Record<string, AxGen<any, any>> = Record<string, never>, // Node registry for type tracking
3694
- TState extends AxFlowState = IN> extends AxProgram<IN, OUT> {
3695
- private readonly nodes;
3696
- private readonly flowDefinition;
3697
- private readonly nodeGenerators;
3698
- private readonly loopStack;
3699
- private readonly stepLabels;
3700
- private branchContext;
3701
- private readonly autoParallelConfig;
3702
- private readonly executionPlanner;
3703
- constructor(signature?: NonNullable<ConstructorParameters<typeof AxSignature>[0]>, options?: {
3704
- autoParallel?: boolean;
3705
- });
3706
- /**
3707
- * Declares a reusable computational node using a signature string.
3708
- * Returns a new AxFlow type that tracks this node in the TNodes registry.
3709
- *
3710
- * @param name - The name of the node
3711
- * @param signature - Signature string in the same format as AxSignature
3712
- * @param options - Optional program forward options (same as AxGen)
3713
- * @returns New AxFlow instance with updated TNodes type
3714
- *
3715
- * @example
3716
- * ```typescript
3717
- * flow.node('summarizer', 'text:string -> summary:string')
3718
- * flow.node('analyzer', 'text:string -> analysis:string, confidence:number', { debug: true })
3719
- * ```
3720
- */
3721
- node<TName extends string, TSig extends string>(name: TName, signature: TSig, options?: Readonly<AxProgramForwardOptions>): AxFlow<IN, OUT, TNodes & {
3722
- [K in TName]: InferAxGen<TSig>;
3723
- }, // Add new node to registry
3724
- TState>;
3725
- /**
3726
- * Declares a reusable computational node using an AxSignature instance.
3727
- * This allows using pre-configured signatures in the flow.
3728
- *
3729
- * @param name - The name of the node
3730
- * @param signature - AxSignature instance to use for this node
3731
- * @param options - Optional program forward options (same as AxGen)
3732
- * @returns New AxFlow instance with updated TNodes type
3733
- *
3734
- * @example
3735
- * ```typescript
3736
- * const sig = new AxSignature('text:string -> summary:string')
3737
- * flow.node('summarizer', sig, { temperature: 0.1 })
3738
- * ```
3739
- */
3740
- node<TName extends string>(name: TName, signature: AxSignature, options?: Readonly<AxProgramForwardOptions>): AxFlow<IN, OUT, TNodes & {
3741
- [K in TName]: AxGen<AxGenIn, AxGenOut>;
3742
- }, // Add new node to registry
3743
- TState>;
3744
- /**
3745
- * Declares a reusable computational node using an existing AxGen instance.
3746
- * This allows reusing pre-configured generators in the flow.
3747
- *
3748
- * @param name - The name of the node
3749
- * @param axgenInstance - Existing AxGen instance to use for this node
3750
- * @returns New AxFlow instance with updated TNodes type
3751
- *
3752
- * @example
3753
- * ```typescript
3754
- * const summarizer = new AxGen('text:string -> summary:string', { temperature: 0.1 })
3755
- * flow.node('summarizer', summarizer)
3756
- * ```
3757
- */
3758
- node<TName extends string, TGen extends AxGen<any, any>>(name: TName, axgenInstance: TGen): AxFlow<IN, OUT, TNodes & {
3759
- [K in TName]: TGen;
3760
- }, // Add new node to registry with exact type
3761
- TState>;
3762
- /**
3763
- * Declares a reusable computational node using a class that extends AxProgram.
3764
- * This allows using custom program classes in the flow.
3765
- *
3766
- * @param name - The name of the node
3767
- * @param programClass - Class that extends AxProgram to use for this node
3768
- * @returns New AxFlow instance with updated TNodes type
3769
- *
3770
- * @example
3771
- * ```typescript
3772
- * class CustomProgram extends AxProgram<{ input: string }, { output: string }> {
3773
- * async forward(ai, values) { return { output: values.input.toUpperCase() } }
3774
- * }
3775
- * flow.node('custom', CustomProgram)
3776
- * ```
3777
- */
3778
- node<TName extends string, TProgram extends new () => AxProgram<any, any>>(name: TName, programClass: TProgram): AxFlow<IN, OUT, TNodes & {
3779
- [K in TName]: InstanceType<TProgram>;
3780
- }, // Add new node to registry with exact type
3781
- TState>;
3782
- /**
3783
- * Short alias for node() - supports signature strings, AxSignature instances, AxGen instances, and program classes
3784
- */
3785
- n<TName extends string, TSig extends string>(name: TName, signature: TSig, options?: Readonly<AxProgramForwardOptions>): AxFlow<IN, OUT, TNodes & {
3786
- [K in TName]: InferAxGen<TSig>;
3787
- }, TState>;
3788
- n<TName extends string>(name: TName, signature: AxSignature, options?: Readonly<AxProgramForwardOptions>): AxFlow<IN, OUT, TNodes & {
3789
- [K in TName]: AxGen<AxGenIn, AxGenOut>;
3790
- }, TState>;
3791
- n<TName extends string, TGen extends AxGen<any, any>>(name: TName, axgenInstance: TGen): AxFlow<IN, OUT, TNodes & {
3792
- [K in TName]: TGen;
3793
- }, TState>;
3794
- n<TName extends string, TProgram extends new () => AxProgram<any, any>>(name: TName, programClass: TProgram): AxFlow<IN, OUT, TNodes & {
3795
- [K in TName]: InstanceType<TProgram>;
3796
- }, TState>;
3797
- /**
3798
- * Applies a synchronous transformation to the state object.
3799
- * Returns a new AxFlow type with the evolved state.
3800
- *
3801
- * @param transform - Function that takes the current state and returns a new state
3802
- * @returns New AxFlow instance with updated TState type
3803
- *
3804
- * @example
3805
- * ```typescript
3806
- * flow.map(state => ({ ...state, processedText: state.text.toLowerCase() }))
3807
- * ```
3808
- */
3809
- map<TNewState extends AxFlowState>(transform: (state: TState) => TNewState): AxFlow<IN, OUT, TNodes, TNewState>;
3810
- /**
3811
- * Short alias for map()
3812
- */
3813
- m<TNewState extends AxFlowState>(transform: (state: TState) => TNewState): AxFlow<IN, OUT, TNodes, TNewState>;
3814
- /**
3815
- * Labels a step for later reference (useful for feedback loops).
3816
- *
3817
- * @param label - The label to assign to the current step position
3818
- * @returns this (for chaining, no type change)
3819
- *
3820
- * @example
3821
- * ```typescript
3822
- * flow.label('retry-point')
3823
- * .execute('queryGen', ...)
3824
- * ```
3825
- */
3826
- label(label: string): this;
3827
- /**
3828
- * Short alias for label()
3829
- */
3830
- l(label: string): this;
3831
- /**
3832
- * Executes a previously defined node with full type safety.
3833
- * The node name must exist in TNodes, and the mapping function is typed based on the node's signature.
3834
- *
3835
- * @param nodeName - The name of the node to execute (must exist in TNodes)
3836
- * @param mapping - Typed function that takes the current state and returns the input for the node
3837
- * @param dynamicContext - Optional object to override the AI service or options for this specific step
3838
- * @returns New AxFlow instance with TState augmented with the node's result
3839
- *
3840
- * @example
3841
- * ```typescript
3842
- * flow.execute('summarizer', state => ({ text: state.originalText }), { ai: cheapAI })
3843
- * ```
3844
- */
3845
- execute<TNodeName extends keyof TNodes & string>(nodeName: TNodeName, mapping: (state: TState) => GetGenIn<TNodes[TNodeName]>, dynamicContext?: AxFlowDynamicContext): AxFlow<IN, OUT, TNodes, AddNodeResult<TState, TNodeName, GetGenOut<TNodes[TNodeName]>>>;
3846
- /**
3847
- * Short alias for execute()
3848
- */
3849
- e<TNodeName extends keyof TNodes & string>(nodeName: TNodeName, mapping: (state: TState) => GetGenIn<TNodes[TNodeName]>, dynamicContext?: AxFlowDynamicContext): AxFlow<IN, OUT, TNodes, AddNodeResult<TState, TNodeName, GetGenOut<TNodes[TNodeName]>>>;
3850
- /**
3851
- * Starts a conditional branch based on a predicate function.
3852
- *
3853
- * @param predicate - Function that takes state and returns a value to branch on
3854
- * @returns this (for chaining)
3855
- *
3856
- * @example
3857
- * ```typescript
3858
- * flow.branch(state => state.qualityResult.needsMoreInfo)
3859
- * .when(true)
3860
- * .execute('queryGen', ...)
3861
- * .when(false)
3862
- * .execute('answer', ...)
3863
- * .merge()
3864
- * ```
3865
- */
3866
- branch(predicate: (state: TState) => unknown): this;
3867
- /**
3868
- * Short alias for branch()
3869
- */
3870
- b(predicate: (state: TState) => unknown): this;
3871
- /**
3872
- * Defines a branch case for the current branch context.
3873
- *
3874
- * @param value - The value to match against the branch predicate result
3875
- * @returns this (for chaining)
3876
- */
3877
- when(value: unknown): this;
3878
- /**
3879
- * Short alias for when()
3880
- */
3881
- w(value: unknown): this;
3882
- /**
3883
- * Ends the current branch and merges all branch paths back into the main flow.
3884
- * Optionally specify the explicit merged state type for better type safety.
3885
- *
3886
- * @param explicitMergedType - Optional type hint for the merged state (defaults to current TState)
3887
- * @returns AxFlow instance with the merged state type
3888
- *
3889
- * @example
3890
- * ```typescript
3891
- * // Default behavior - preserves current TState
3892
- * flow.branch(state => state.type)
3893
- * .when('simple').execute('simpleProcessor', ...)
3894
- * .when('complex').execute('complexProcessor', ...)
3895
- * .merge()
3896
- *
3897
- * // Explicit type - specify exact merged state shape
3898
- * flow.branch(state => state.type)
3899
- * .when('simple').map(state => ({ result: state.simpleResult, method: 'simple' }))
3900
- * .when('complex').map(state => ({ result: state.complexResult, method: 'complex' }))
3901
- * .merge<{ result: string; method: string }>()
3902
- * ```
3903
- */
3904
- merge<TMergedState extends AxFlowState = TState>(): AxFlow<IN, OUT, TNodes, TMergedState>;
3905
- /**
3906
- * Short alias for merge()
3907
- */
3908
- mg<TMergedState extends AxFlowState = TState>(): AxFlow<IN, OUT, TNodes, TMergedState>;
3909
- /**
3910
- * Executes multiple operations in parallel and merges their results.
3911
- * Both typed and legacy untyped branches are supported.
3912
- *
3913
- * @param branches - Array of functions that define parallel operations
3914
- * @returns Object with merge method for combining results
3915
- *
3916
- * @example
3917
- * ```typescript
3918
- * flow.parallel([
3919
- * subFlow => subFlow.execute('retrieve1', state => ({ query: state.query1 })),
3920
- * subFlow => subFlow.execute('retrieve2', state => ({ query: state.query2 })),
3921
- * subFlow => subFlow.execute('retrieve3', state => ({ query: state.query3 }))
3922
- * ]).merge('documents', (docs1, docs2, docs3) => [...docs1, ...docs2, ...docs3])
3923
- * ```
3924
- */
3925
- parallel(branches: (AxFlowParallelBranch | AxFlowTypedParallelBranch<TNodes, TState>)[]): {
3926
- merge<T, TResultKey extends string>(resultKey: TResultKey, mergeFunction: (...results: unknown[]) => T): AxFlow<IN, OUT, TNodes, TState & {
3927
- [K in TResultKey]: T;
3928
- }>;
3929
- };
3930
- /**
3931
- * Short alias for parallel()
3932
- */
3933
- p(branches: (AxFlowParallelBranch | AxFlowTypedParallelBranch<TNodes, TState>)[]): {
3934
- merge<T, TResultKey extends string>(resultKey: TResultKey, mergeFunction: (...results: unknown[]) => T): AxFlow<IN, OUT, TNodes, TState & {
3935
- [K in TResultKey]: T;
3936
- }>;
3937
- };
3938
- /**
3939
- * Creates a feedback loop that jumps back to a labeled step if a condition is met.
3940
- *
3941
- * @param condition - Function that returns true to trigger the feedback loop
3942
- * @param targetLabel - The label to jump back to
3943
- * @param maxIterations - Maximum number of iterations to prevent infinite loops (default: 10)
3944
- * @returns this (for chaining)
3945
- *
3946
- * @example
3947
- * ```typescript
3948
- * flow.label('retry-point')
3949
- * .execute('answer', ...)
3950
- * .execute('qualityCheck', ...)
3951
- * .feedback(state => state.qualityCheckResult.confidence < 0.7, 'retry-point')
3952
- * ```
3953
- */
3954
- feedback(condition: (state: TState) => boolean, targetLabel: string, maxIterations?: number): this;
3955
- /**
3956
- * Short alias for feedback()
3957
- */
3958
- fb(condition: (state: TState) => boolean, targetLabel: string, maxIterations?: number): this;
3959
- /**
3960
- * Marks the beginning of a loop block.
3961
- *
3962
- * @param condition - Function that takes the current state and returns a boolean
3963
- * @param maxIterations - Maximum number of iterations to prevent infinite loops (default: 100)
3964
- * @returns this (for chaining)
3965
- *
3966
- * @example
3967
- * ```typescript
3968
- * flow.while(state => state.iterations < 3, 10)
3969
- * .map(state => ({ ...state, iterations: (state.iterations || 0) + 1 }))
3970
- * .endWhile()
3971
- * ```
3972
- */
3973
- while(condition: (state: TState) => boolean, maxIterations?: number): this;
3974
- /**
3975
- * Short alias for while()
3976
- */
3977
- wh(condition: (state: TState) => boolean, maxIterations?: number): this;
3978
- /**
3979
- * Marks the end of a loop block.
3980
- *
3981
- * @returns this (for chaining)
3982
- */
3983
- endWhile(): this;
3984
- /**
3985
- * Short alias for endWhile()
3986
- */
3987
- end(): this;
3988
- /**
3989
- * Executes the flow with the given AI service and input values.
3990
- *
3991
- * @param ai - The AI service to use as the default for all steps
3992
- * @param values - The input values for the flow
3993
- * @param options - Optional forward options to use as defaults (includes autoParallel override)
3994
- * @returns Promise that resolves to the final output
3995
- */
3996
- forward(ai: Readonly<AxAIService>, values: IN, options?: Readonly<AxProgramForwardOptions & {
3997
- autoParallel?: boolean;
3998
- }>): Promise<OUT>;
3999
- /**
4000
- * Gets execution plan information for debugging automatic parallelization
4001
- *
4002
- * @returns Object with execution plan details
4003
- */
4004
- getExecutionPlan(): {
4005
- totalSteps: number;
4006
- parallelGroups: number;
4007
- maxParallelism: number;
4008
- autoParallelEnabled: boolean;
4009
- steps?: AxFlowExecutionStep[];
4010
- groups?: AxFlowParallelGroup[];
4011
- };
4012
- }
4013
- /**
4014
- * Typed implementation of the sub-context for parallel execution with full type safety
4015
- */
4016
- declare class AxFlowTypedSubContextImpl<TNodes extends Record<string, AxGen<any, any>>, TState extends AxFlowState> implements AxFlowTypedSubContext<TNodes, TState> {
4017
- private readonly nodeGenerators;
4018
- private readonly steps;
4019
- constructor(nodeGenerators: Map<string, AxGen<AxGenIn, AxGenOut> | AxProgram<AxGenIn, AxGenOut>>);
4020
- execute<TNodeName extends keyof TNodes & string>(nodeName: TNodeName, mapping: (state: TState) => GetGenIn<TNodes[TNodeName]>, dynamicContext?: AxFlowDynamicContext): AxFlowTypedSubContext<TNodes, AddNodeResult<TState, TNodeName, GetGenOut<TNodes[TNodeName]>>>;
4021
- map<TNewState extends AxFlowState>(transform: (state: TState) => TNewState): AxFlowTypedSubContext<TNodes, TNewState>;
4022
- executeSteps(initialState: TState, context: Readonly<{
4023
- mainAi: AxAIService;
4024
- mainOptions?: AxProgramForwardOptions;
4025
- }>): Promise<AxFlowState>;
4026
- }
4027
-
4028
- type AxDataRow = {
4029
- row: Record<string, AxFieldValue>;
4030
- };
4031
- declare class AxHFDataLoader {
4032
- private rows;
4033
- private baseUrl;
4034
- private dataset;
4035
- private split;
4036
- private config;
4037
- private options?;
4038
- constructor({ dataset, split, config, options, }: Readonly<{
4039
- dataset: string;
4040
- split: string;
4041
- config: string;
4042
- options?: Readonly<{
4043
- offset?: number;
4044
- length?: number;
4045
- }>;
3890
+ declare class AxMiPRO<IN extends AxGenIn = AxGenIn, OUT extends AxGenOut = AxGenOut> extends AxBaseOptimizer<IN, OUT> {
3891
+ private maxBootstrappedDemos;
3892
+ private maxLabeledDemos;
3893
+ private numCandidates;
3894
+ private initTemperature;
3895
+ private numTrials;
3896
+ private minibatch;
3897
+ private minibatchSize;
3898
+ private minibatchFullEvalSteps;
3899
+ private programAwareProposer;
3900
+ private dataAwareProposer;
3901
+ private viewDataBatchSize;
3902
+ private tipAwareProposer;
3903
+ private fewshotAwareProposer;
3904
+ private earlyStoppingTrials;
3905
+ private minImprovementThreshold;
3906
+ private bayesianOptimization;
3907
+ private acquisitionFunction;
3908
+ private explorationWeight;
3909
+ private sampleCount;
3910
+ private miproConfigHistory;
3911
+ private surrogateModel;
3912
+ constructor(args: Readonly<AxOptimizerArgs & {
3913
+ options?: AxMiPROOptimizerOptions;
4046
3914
  }>);
4047
- private fetchDataFromAPI;
4048
- loadData(): Promise<AxDataRow[]>;
4049
- setData(rows: AxDataRow[]): void;
4050
- getData(): AxDataRow[];
4051
- getRows<T>({ count, fields, renameMap, }: Readonly<{
4052
- count: number;
4053
- fields: readonly string[];
4054
- renameMap?: Record<string, string>;
4055
- }>): Promise<T[]>;
4056
- }
4057
-
4058
- declare enum AxJSInterpreterPermission {
4059
- FS = "node:fs",
4060
- NET = "net",
4061
- OS = "os",
4062
- CRYPTO = "crypto",
4063
- PROCESS = "process"
4064
- }
4065
- declare class AxJSInterpreter {
4066
- private permissions;
4067
- constructor({ permissions, }?: Readonly<{
4068
- permissions?: readonly AxJSInterpreterPermission[];
4069
- }> | undefined);
4070
- private codeInterpreterJavascript;
4071
- toFunction(): AxFunction;
4072
- }
4073
-
4074
- declare const axSpanAttributes: {
4075
- LLM_SYSTEM: string;
4076
- LLM_OPERATION_NAME: string;
4077
- LLM_REQUEST_MODEL: string;
4078
- LLM_REQUEST_MAX_TOKENS: string;
4079
- LLM_REQUEST_TEMPERATURE: string;
4080
- LLM_REQUEST_TOP_K: string;
4081
- LLM_REQUEST_FREQUENCY_PENALTY: string;
4082
- LLM_REQUEST_PRESENCE_PENALTY: string;
4083
- LLM_REQUEST_STOP_SEQUENCES: string;
4084
- LLM_REQUEST_LLM_IS_STREAMING: string;
4085
- LLM_REQUEST_TOP_P: string;
4086
- LLM_USAGE_INPUT_TOKENS: string;
4087
- LLM_USAGE_OUTPUT_TOKENS: string;
4088
- LLM_USAGE_TOTAL_TOKENS: string;
4089
- LLM_USAGE_THOUGHTS_TOKENS: string;
4090
- DB_SYSTEM: string;
4091
- DB_TABLE: string;
4092
- DB_NAMESPACE: string;
4093
- DB_ID: string;
4094
- DB_QUERY_TEXT: string;
4095
- DB_VECTOR: string;
4096
- DB_OPERATION_NAME: string;
4097
- DB_VECTOR_QUERY_TOP_K: string;
4098
- DB_QUERY_EMBEDDINGS: string;
4099
- DB_QUERY_RESULT: string;
4100
- DB_QUERY_EMBEDDINGS_VECTOR: string;
4101
- DB_QUERY_RESULT_ID: string;
4102
- DB_QUERY_RESULT_SCORE: string;
4103
- DB_QUERY_RESULT_DISTANCE: string;
4104
- DB_QUERY_RESULT_METADATA: string;
4105
- DB_QUERY_RESULT_VECTOR: string;
4106
- DB_QUERY_RESULT_DOCUMENT: string;
4107
- };
4108
- declare const axSpanEvents: {
4109
- GEN_AI_USER_MESSAGE: string;
4110
- GEN_AI_SYSTEM_MESSAGE: string;
4111
- GEN_AI_ASSISTANT_MESSAGE: string;
4112
- GEN_AI_TOOL_MESSAGE: string;
4113
- GEN_AI_CHOICE: string;
4114
- GEN_AI_USAGE: string;
4115
- };
4116
- declare enum AxLLMRequestTypeValues {
4117
- COMPLETION = "completion",
4118
- CHAT = "chat",
4119
- RERANK = "rerank",
4120
- UNKNOWN = "unknown"
4121
- }
4122
- declare enum AxSpanKindValues {
4123
- WORKFLOW = "workflow",
4124
- TASK = "task",
4125
- AGENT = "agent",
4126
- TOOL = "tool",
4127
- UNKNOWN = "unknown"
4128
- }
4129
-
4130
- interface JSONRPCRequest<T> {
4131
- jsonrpc: '2.0';
4132
- id: string | number;
4133
- method: string;
4134
- params?: T;
4135
- }
4136
- interface JSONRPCSuccessResponse<T = unknown> {
4137
- jsonrpc: '2.0';
4138
- id: string | number;
4139
- result: T;
4140
- }
4141
- interface JSONRPCErrorResponse {
4142
- jsonrpc: '2.0';
4143
- id: string | number;
4144
- error: {
4145
- code: number;
4146
- message: string;
4147
- data?: unknown;
4148
- };
4149
- }
4150
- type JSONRPCResponse<T = unknown> = JSONRPCSuccessResponse<T> | JSONRPCErrorResponse;
4151
- interface JSONRPCNotification {
4152
- jsonrpc: '2.0';
4153
- method: string;
4154
- params?: Record<string, unknown>;
4155
- }
4156
-
4157
- interface AxMCPTransport {
4158
3915
  /**
4159
- * Sends a JSON-RPC request or notification and returns the response
4160
- * @param message The JSON-RPC request or notification to send
4161
- * @returns A Promise that resolves to the JSON-RPC response
3916
+ * Configures the optimizer for light, medium, or heavy optimization
3917
+ * @param level The optimization level: "light", "medium", or "heavy"
4162
3918
  */
4163
- send(message: Readonly<JSONRPCRequest<unknown>>): Promise<JSONRPCResponse<unknown>>;
3919
+ configureAuto(level: 'light' | 'medium' | 'heavy'): void;
4164
3920
  /**
4165
- * Sends a JSON-RPC notification
4166
- * @param message The JSON-RPC notification to send
3921
+ * Generates creative tips for instruction generation
4167
3922
  */
4168
- sendNotification(message: Readonly<JSONRPCNotification>): Promise<void>;
3923
+ private generateTips;
4169
3924
  /**
4170
- * Connects to the transport if needed
4171
- * This method is optional and only required for transports that need connection setup
3925
+ * Generates program summary for context-aware instruction generation
4172
3926
  */
4173
- connect?(): Promise<void>;
4174
- }
4175
-
4176
- declare class AxMCPHTTPSSETransport implements AxMCPTransport {
4177
- private endpoint;
4178
- private sseUrl;
4179
- private eventSource?;
4180
- constructor(sseUrl: string);
4181
- connect(): Promise<void>;
4182
- send(message: JSONRPCRequest<unknown> | JSONRPCNotification): Promise<JSONRPCResponse<unknown>>;
4183
- sendNotification(message: Readonly<JSONRPCNotification>): Promise<void>;
4184
- }
4185
- interface AxMCPStreamableHTTPTransportOptions {
3927
+ private generateProgramSummary;
4186
3928
  /**
4187
- * Custom headers to include with all HTTP requests
4188
- * Note: Content-Type, Accept, and Mcp-Session-Id are managed automatically
3929
+ * Generates dataset summary for context-aware instruction generation
4189
3930
  */
4190
- headers?: Record<string, string>;
3931
+ private generateDatasetSummary;
4191
3932
  /**
4192
- * Authorization header value (convenience for common use case)
4193
- * If provided, will be added to the headers as 'Authorization'
3933
+ * Enhanced instruction generation using AI with program and data awareness
4194
3934
  */
4195
- authorization?: string;
4196
- }
4197
- /**
4198
- * AxMCPStreambleHTTPTransport implements the 2025-03-26 Streamable HTTP transport specification
4199
- * This transport uses a single HTTP endpoint that supports both POST and GET methods
4200
- */
4201
- declare class AxMCPStreambleHTTPTransport implements AxMCPTransport {
4202
- private mcpEndpoint;
4203
- private sessionId?;
4204
- private eventSource?;
4205
- private pendingRequests;
4206
- private messageHandler?;
4207
- private customHeaders;
4208
- constructor(mcpEndpoint: string, options?: AxMCPStreamableHTTPTransportOptions);
3935
+ private generateInstruction;
4209
3936
  /**
4210
- * Update custom headers (useful for refreshing tokens)
3937
+ * Generates instruction candidates using enhanced AI-powered generation
3938
+ * @param options Optional compile options that may override teacher AI
3939
+ * @returns Array of generated instruction candidates
4211
3940
  */
4212
- setHeaders(headers: Record<string, string>): void;
3941
+ private proposeInstructionCandidates;
4213
3942
  /**
4214
- * Update authorization header (convenience method)
3943
+ * Bootstraps few-shot examples for the program
4215
3944
  */
4216
- setAuthorization(authorization: string): void;
3945
+ private bootstrapFewShotExamples;
4217
3946
  /**
4218
- * Get a copy of the current custom headers
3947
+ * Selects labeled examples directly from the training set
4219
3948
  */
4220
- getHeaders(): Record<string, string>;
3949
+ private selectLabeledExamples;
4221
3950
  /**
4222
- * Build headers for HTTP requests, merging custom headers with required ones
3951
+ * Runs optimization to find the best combination of few-shot examples and instructions
4223
3952
  */
4224
- private buildHeaders;
3953
+ private runOptimization;
3954
+ private evaluateConfig;
4225
3955
  /**
4226
- * Set a handler for incoming server messages (requests/notifications)
3956
+ * Fisher-Yates shuffle for stochastic evaluation
4227
3957
  */
4228
- setMessageHandler(handler: (message: JSONRPCRequest<unknown> | JSONRPCNotification) => void): void;
4229
- connect(): Promise<void>;
3958
+ private shuffleArray;
3959
+ private applyConfigToProgram;
4230
3960
  /**
4231
- * Opens an SSE stream to listen for server-initiated messages
3961
+ * The main compile method to run MIPROv2 optimization
4232
3962
  */
4233
- openListeningStream(): Promise<void>;
3963
+ compile(program: Readonly<AxProgram<IN, OUT>>, metricFn: AxMetricFn, options?: AxCompileOptions): Promise<AxMiPROResult<IN, OUT>>;
4234
3964
  /**
4235
- * Opens an SSE stream using fetch API to support custom headers
3965
+ * Applies a configuration to an AxGen instance
4236
3966
  */
4237
- private openListeningStreamWithFetch;
4238
- send(message: Readonly<JSONRPCRequest<unknown>>): Promise<JSONRPCResponse<unknown>>;
4239
- private handleSSEResponse;
4240
- sendNotification(message: Readonly<JSONRPCNotification>): Promise<void>;
3967
+ private applyConfigToAxGen;
4241
3968
  /**
4242
- * Explicitly terminate the session (if supported by server)
3969
+ * Get optimizer-specific configuration
3970
+ * @returns Current optimizer configuration
4243
3971
  */
4244
- terminateSession(): Promise<void>;
3972
+ getConfiguration(): Record<string, unknown>;
4245
3973
  /**
4246
- * Close any open connections
3974
+ * Update optimizer configuration
3975
+ * @param config New configuration to merge with existing
4247
3976
  */
4248
- close(): void;
4249
- }
4250
-
4251
- interface AxMiPROResult<IN extends AxGenIn, OUT extends AxGenOut> extends AxOptimizerResult<OUT> {
4252
- optimizedGen?: AxGen<IN, OUT>;
4253
- }
4254
- declare class AxMiPRO<IN extends AxGenIn = AxGenIn, OUT extends AxGenOut = AxGenOut> extends AxBaseOptimizer<IN, OUT> {
4255
- private maxBootstrappedDemos;
4256
- private maxLabeledDemos;
4257
- private numCandidates;
4258
- private initTemperature;
4259
- private numTrials;
4260
- private minibatch;
4261
- private minibatchSize;
4262
- private minibatchFullEvalSteps;
4263
- private programAwareProposer;
4264
- private dataAwareProposer;
4265
- private viewDataBatchSize;
4266
- private tipAwareProposer;
4267
- private fewshotAwareProposer;
4268
- private earlyStoppingTrials;
4269
- private minImprovementThreshold;
4270
- private bayesianOptimization;
4271
- private acquisitionFunction;
4272
- private explorationWeight;
4273
- private sampleCount;
4274
- private miproConfigHistory;
4275
- private surrogateModel;
4276
- constructor(args: Readonly<AxOptimizerArgs & {
4277
- options?: AxMiPROOptimizerOptions;
4278
- }>);
3977
+ updateConfiguration(config: Readonly<Record<string, unknown>>): void;
3978
+ /**
3979
+ * Reset optimizer state for reuse with different programs
3980
+ */
3981
+ reset(): void;
3982
+ /**
3983
+ * Validate that the optimizer can handle the given program
3984
+ * @param program Program to validate
3985
+ * @returns Validation result with any issues found
3986
+ */
3987
+ validateProgram(program: Readonly<AxProgram<IN, OUT>>): {
3988
+ isValid: boolean;
3989
+ issues: string[];
3990
+ suggestions: string[];
3991
+ };
3992
+ /**
3993
+ * Encodes a configuration into a string key for surrogate model lookup
3994
+ */
3995
+ private encodeConfiguration;
3996
+ /**
3997
+ * Updates the surrogate model with a new configuration-score pair
3998
+ */
3999
+ private updateSurrogateModel;
4279
4000
  /**
4280
- * Configures the optimizer for light, medium, or heavy optimization
4281
- * @param level The optimization level: "light", "medium", or "heavy"
4001
+ * Predicts performance using the surrogate model
4282
4002
  */
4283
- configureAuto(level: 'light' | 'medium' | 'heavy'): void;
4003
+ private predictPerformance;
4284
4004
  /**
4285
- * Generates creative tips for instruction generation
4005
+ * Calculates acquisition function value for Bayesian optimization
4286
4006
  */
4287
- private generateTips;
4007
+ private calculateAcquisitionValue;
4288
4008
  /**
4289
- * Generates program summary for context-aware instruction generation
4009
+ * Error function approximation for acquisition function calculations
4290
4010
  */
4291
- private generateProgramSummary;
4011
+ private erf;
4292
4012
  /**
4293
- * Generates dataset summary for context-aware instruction generation
4013
+ * Selects the next configuration to evaluate using Bayesian optimization
4294
4014
  */
4295
- private generateDatasetSummary;
4015
+ private selectConfigurationViaBayesianOptimization;
4016
+ }
4017
+
4018
+ type AxInstanceRegistryItem<T extends AxTunable<IN, OUT>, IN extends AxGenIn, OUT extends AxGenOut> = T & AxUsable;
4019
+ declare class AxInstanceRegistry<T extends AxTunable<IN, OUT>, IN extends AxGenIn, OUT extends AxGenOut> {
4020
+ private reg;
4021
+ constructor();
4022
+ register(instance: AxInstanceRegistryItem<T, IN, OUT>): void;
4023
+ [Symbol.iterator](): Generator<AxInstanceRegistryItem<T, IN, OUT>, void, unknown>;
4024
+ }
4025
+
4026
+ interface AxSamplePickerOptions<OUT extends AxGenOut> {
4027
+ resultPicker?: AxResultPickerFunction<OUT>;
4028
+ }
4029
+
4030
+ declare const AxStringUtil: {
4031
+ trimNonAlphaNum: (str: string) => string;
4032
+ splitIntoTwo: (str: string, separator: Readonly<RegExp | string>) => string[];
4033
+ dedup: (seq: readonly string[]) => string[];
4034
+ extractIdAndText: (input: string) => {
4035
+ id: number;
4036
+ text: string;
4037
+ };
4038
+ extractIndexPrefixedText: (input: string) => string;
4039
+ batchArray: <T>(arr: readonly T[], size: number) => T[][];
4040
+ };
4041
+
4042
+ type AxSignatureTemplateValue = string | AxFieldType | AxFieldDescriptor | AxSignature;
4043
+ interface AxFieldType {
4044
+ readonly type: 'string' | 'number' | 'boolean' | 'json' | 'image' | 'audio' | 'date' | 'datetime' | 'class' | 'code';
4045
+ readonly isArray?: boolean;
4046
+ readonly options?: readonly string[];
4047
+ readonly description?: string;
4048
+ readonly isOptional?: boolean;
4049
+ readonly isInternal?: boolean;
4050
+ }
4051
+ interface AxFieldDescriptor {
4052
+ readonly name: string;
4053
+ readonly type?: AxFieldType;
4054
+ readonly description?: string;
4055
+ readonly isOptional?: boolean;
4056
+ readonly isInternal?: boolean;
4057
+ }
4058
+ declare function s(strings: TemplateStringsArray, ...values: readonly AxSignatureTemplateValue[]): AxSignature;
4059
+ declare function ax<IN extends AxGenIn = AxGenIn, OUT extends AxGenerateResult<AxGenOut> = AxGenerateResult<AxGenOut>>(strings: TemplateStringsArray, ...values: readonly AxSignatureTemplateValue[]): AxGen<IN, OUT>;
4060
+ declare const f: {
4061
+ string: (desc?: string) => AxFieldType;
4062
+ number: (desc?: string) => AxFieldType;
4063
+ boolean: (desc?: string) => AxFieldType;
4064
+ date: (desc?: string) => AxFieldType;
4065
+ datetime: (desc?: string) => AxFieldType;
4066
+ json: (desc?: string) => AxFieldType;
4067
+ image: (desc?: string) => AxFieldType;
4068
+ audio: (desc?: string) => AxFieldType;
4069
+ class: (options: readonly string[], desc?: string) => AxFieldType;
4070
+ code: (language: string, desc?: string) => AxFieldType;
4071
+ array: <T extends AxFieldType>(baseType: T) => T & {
4072
+ readonly isArray: true;
4073
+ };
4074
+ optional: <T extends AxFieldType>(baseType: T) => T & {
4075
+ readonly isOptional: true;
4076
+ };
4077
+ internal: <T extends AxFieldType>(baseType: T) => T & {
4078
+ readonly isInternal: true;
4079
+ };
4080
+ };
4081
+
4082
+ type AxFlowState = Record<string, unknown>;
4083
+ type AxFlowStepFunction = (state: AxFlowState, context: Readonly<{
4084
+ mainAi: AxAIService;
4085
+ mainOptions?: AxProgramForwardOptions;
4086
+ }>) => Promise<AxFlowState> | AxFlowState;
4087
+ interface AxFlowDynamicContext {
4088
+ ai?: AxAIService;
4089
+ options?: AxProgramForwardOptions;
4090
+ }
4091
+ type GetGenIn<T extends AxGen<AxGenIn, AxGenOut>> = T extends AxGen<infer IN, AxGenOut> ? IN : never;
4092
+ type GetGenOut<T extends AxGen<AxGenIn, AxGenOut>> = T extends AxGen<AxGenIn, infer OUT> ? OUT : never;
4093
+ type InferAxGen<TSig extends string> = TSig extends string ? AxGen<AxGenIn, AxGenOut> : never;
4094
+ type NodeResultKey<TNodeName extends string> = `${TNodeName}Result`;
4095
+ type AddNodeResult<TState extends AxFlowState, TNodeName extends string, TNodeOut extends AxGenOut> = TState & {
4096
+ [K in NodeResultKey<TNodeName>]: TNodeOut;
4097
+ };
4098
+ type AxFlowTypedParallelBranch<TNodes extends Record<string, AxGen<any, any>>, TState extends AxFlowState> = (subFlow: AxFlowTypedSubContext<TNodes, TState>) => AxFlowTypedSubContext<TNodes, AxFlowState>;
4099
+ interface AxFlowTypedSubContext<TNodes extends Record<string, AxGen<any, any>>, TState extends AxFlowState> {
4100
+ execute<TNodeName extends keyof TNodes & string>(nodeName: TNodeName, mapping: (state: TState) => GetGenIn<TNodes[TNodeName]>, dynamicContext?: AxFlowDynamicContext): AxFlowTypedSubContext<TNodes, AddNodeResult<TState, TNodeName, GetGenOut<TNodes[TNodeName]>>>;
4101
+ map<TNewState extends AxFlowState>(transform: (state: TState) => TNewState): AxFlowTypedSubContext<TNodes, TNewState>;
4102
+ executeSteps(initialState: TState, context: Readonly<{
4103
+ mainAi: AxAIService;
4104
+ mainOptions?: AxProgramForwardOptions;
4105
+ }>): Promise<AxFlowState>;
4106
+ }
4107
+ type AxFlowParallelBranch = (subFlow: AxFlowSubContext) => AxFlowSubContext;
4108
+ interface AxFlowSubContext {
4109
+ execute(nodeName: string, mapping: (state: AxFlowState) => Record<string, AxFieldValue>, dynamicContext?: AxFlowDynamicContext): this;
4110
+ map(transform: (state: AxFlowState) => AxFlowState): this;
4111
+ executeSteps(initialState: AxFlowState, context: Readonly<{
4112
+ mainAi: AxAIService;
4113
+ mainOptions?: AxProgramForwardOptions;
4114
+ }>): Promise<AxFlowState>;
4115
+ }
4116
+ interface AxFlowExecutionStep {
4117
+ type: 'execute' | 'map' | 'other';
4118
+ nodeName?: string;
4119
+ dependencies: string[];
4120
+ produces: string[];
4121
+ stepFunction: AxFlowStepFunction;
4122
+ stepIndex: number;
4123
+ }
4124
+ interface AxFlowParallelGroup {
4125
+ level: number;
4126
+ steps: AxFlowExecutionStep[];
4127
+ }
4128
+ /**
4129
+ * AxFlow - A fluent, chainable API for building and orchestrating complex, stateful AI programs.
4130
+ *
4131
+ * Now with advanced type-safe chaining where each method call evolves the type information,
4132
+ * providing compile-time type safety and superior IntelliSense.
4133
+ *
4134
+ * @example
4135
+ * ```typescript
4136
+ * const flow = new AxFlow<{ topic: string }, { finalAnswer: string }>()
4137
+ * .node('summarizer', 'text:string -> summary:string')
4138
+ * .node('critic', 'summary:string -> critique:string')
4139
+ * .execute('summarizer', state => ({ text: `About ${state.topic}` })) // state is { topic: string }
4140
+ * .execute('critic', state => ({ summary: state.summarizerResult.summary })) // state evolves!
4141
+ * .map(state => ({ finalAnswer: state.criticResult.critique })) // fully typed!
4142
+ *
4143
+ * const result = await flow.forward(ai, { topic: "AI safety" })
4144
+ * ```
4145
+ */
4146
+ declare class AxFlow<IN extends AxGenIn, OUT extends AxGenOut, TNodes extends Record<string, AxGen<any, any>> = Record<string, never>, // Node registry for type tracking
4147
+ TState extends AxFlowState = IN> extends AxProgram<IN, OUT> {
4148
+ private readonly nodes;
4149
+ private readonly flowDefinition;
4150
+ private readonly nodeGenerators;
4151
+ private readonly loopStack;
4152
+ private readonly stepLabels;
4153
+ private branchContext;
4154
+ private readonly autoParallelConfig;
4155
+ private readonly executionPlanner;
4156
+ constructor(signature?: NonNullable<ConstructorParameters<typeof AxSignature>[0]>, options?: {
4157
+ autoParallel?: boolean;
4158
+ });
4296
4159
  /**
4297
- * Enhanced instruction generation using AI with program and data awareness
4160
+ * Declares a reusable computational node using a signature string.
4161
+ * Returns a new AxFlow type that tracks this node in the TNodes registry.
4162
+ *
4163
+ * @param name - The name of the node
4164
+ * @param signature - Signature string in the same format as AxSignature
4165
+ * @param options - Optional program forward options (same as AxGen)
4166
+ * @returns New AxFlow instance with updated TNodes type
4167
+ *
4168
+ * @example
4169
+ * ```typescript
4170
+ * flow.node('summarizer', 'text:string -> summary:string')
4171
+ * flow.node('analyzer', 'text:string -> analysis:string, confidence:number', { debug: true })
4172
+ * ```
4298
4173
  */
4299
- private generateInstruction;
4174
+ node<TName extends string, TSig extends string>(name: TName, signature: TSig, options?: Readonly<AxProgramForwardOptions>): AxFlow<IN, OUT, TNodes & {
4175
+ [K in TName]: InferAxGen<TSig>;
4176
+ }, // Add new node to registry
4177
+ TState>;
4300
4178
  /**
4301
- * Generates instruction candidates using enhanced AI-powered generation
4302
- * @param options Optional compile options that may override teacher AI
4303
- * @returns Array of generated instruction candidates
4179
+ * Declares a reusable computational node using an AxSignature instance.
4180
+ * This allows using pre-configured signatures in the flow.
4181
+ *
4182
+ * @param name - The name of the node
4183
+ * @param signature - AxSignature instance to use for this node
4184
+ * @param options - Optional program forward options (same as AxGen)
4185
+ * @returns New AxFlow instance with updated TNodes type
4186
+ *
4187
+ * @example
4188
+ * ```typescript
4189
+ * const sig = new AxSignature('text:string -> summary:string')
4190
+ * flow.node('summarizer', sig, { temperature: 0.1 })
4191
+ * ```
4304
4192
  */
4305
- private proposeInstructionCandidates;
4193
+ node<TName extends string>(name: TName, signature: AxSignature, options?: Readonly<AxProgramForwardOptions>): AxFlow<IN, OUT, TNodes & {
4194
+ [K in TName]: AxGen<AxGenIn, AxGenOut>;
4195
+ }, // Add new node to registry
4196
+ TState>;
4306
4197
  /**
4307
- * Bootstraps few-shot examples for the program
4198
+ * Declares a reusable computational node using an existing AxGen instance.
4199
+ * This allows reusing pre-configured generators in the flow.
4200
+ *
4201
+ * @param name - The name of the node
4202
+ * @param axgenInstance - Existing AxGen instance to use for this node
4203
+ * @returns New AxFlow instance with updated TNodes type
4204
+ *
4205
+ * @example
4206
+ * ```typescript
4207
+ * const summarizer = new AxGen('text:string -> summary:string', { temperature: 0.1 })
4208
+ * flow.node('summarizer', summarizer)
4209
+ * ```
4308
4210
  */
4309
- private bootstrapFewShotExamples;
4211
+ node<TName extends string, TGen extends AxGen<any, any>>(name: TName, axgenInstance: TGen): AxFlow<IN, OUT, TNodes & {
4212
+ [K in TName]: TGen;
4213
+ }, // Add new node to registry with exact type
4214
+ TState>;
4310
4215
  /**
4311
- * Selects labeled examples directly from the training set
4216
+ * Declares a reusable computational node using a class that extends AxProgram.
4217
+ * This allows using custom program classes in the flow.
4218
+ *
4219
+ * @param name - The name of the node
4220
+ * @param programClass - Class that extends AxProgram to use for this node
4221
+ * @returns New AxFlow instance with updated TNodes type
4222
+ *
4223
+ * @example
4224
+ * ```typescript
4225
+ * class CustomProgram extends AxProgram<{ input: string }, { output: string }> {
4226
+ * async forward(ai, values) { return { output: values.input.toUpperCase() } }
4227
+ * }
4228
+ * flow.node('custom', CustomProgram)
4229
+ * ```
4312
4230
  */
4313
- private selectLabeledExamples;
4231
+ node<TName extends string, TProgram extends new () => AxProgram<any, any>>(name: TName, programClass: TProgram): AxFlow<IN, OUT, TNodes & {
4232
+ [K in TName]: InstanceType<TProgram>;
4233
+ }, // Add new node to registry with exact type
4234
+ TState>;
4314
4235
  /**
4315
- * Runs optimization to find the best combination of few-shot examples and instructions
4236
+ * Short alias for node() - supports signature strings, AxSignature instances, AxGen instances, and program classes
4316
4237
  */
4317
- private runOptimization;
4318
- private evaluateConfig;
4238
+ n<TName extends string, TSig extends string>(name: TName, signature: TSig, options?: Readonly<AxProgramForwardOptions>): AxFlow<IN, OUT, TNodes & {
4239
+ [K in TName]: InferAxGen<TSig>;
4240
+ }, TState>;
4241
+ n<TName extends string>(name: TName, signature: AxSignature, options?: Readonly<AxProgramForwardOptions>): AxFlow<IN, OUT, TNodes & {
4242
+ [K in TName]: AxGen<AxGenIn, AxGenOut>;
4243
+ }, TState>;
4244
+ n<TName extends string, TGen extends AxGen<any, any>>(name: TName, axgenInstance: TGen): AxFlow<IN, OUT, TNodes & {
4245
+ [K in TName]: TGen;
4246
+ }, TState>;
4247
+ n<TName extends string, TProgram extends new () => AxProgram<any, any>>(name: TName, programClass: TProgram): AxFlow<IN, OUT, TNodes & {
4248
+ [K in TName]: InstanceType<TProgram>;
4249
+ }, TState>;
4319
4250
  /**
4320
- * Fisher-Yates shuffle for stochastic evaluation
4251
+ * Applies a synchronous transformation to the state object.
4252
+ * Returns a new AxFlow type with the evolved state.
4253
+ *
4254
+ * @param transform - Function that takes the current state and returns a new state
4255
+ * @returns New AxFlow instance with updated TState type
4256
+ *
4257
+ * @example
4258
+ * ```typescript
4259
+ * flow.map(state => ({ ...state, processedText: state.text.toLowerCase() }))
4260
+ * ```
4321
4261
  */
4322
- private shuffleArray;
4323
- private applyConfigToProgram;
4262
+ map<TNewState extends AxFlowState>(transform: (state: TState) => TNewState): AxFlow<IN, OUT, TNodes, TNewState>;
4324
4263
  /**
4325
- * The main compile method to run MIPROv2 optimization
4264
+ * Short alias for map()
4326
4265
  */
4327
- compile(program: Readonly<AxProgram<IN, OUT>>, metricFn: AxMetricFn, options?: AxCompileOptions): Promise<AxMiPROResult<IN, OUT>>;
4266
+ m<TNewState extends AxFlowState>(transform: (state: TState) => TNewState): AxFlow<IN, OUT, TNodes, TNewState>;
4328
4267
  /**
4329
- * Applies a configuration to an AxGen instance
4268
+ * Labels a step for later reference (useful for feedback loops).
4269
+ *
4270
+ * @param label - The label to assign to the current step position
4271
+ * @returns this (for chaining, no type change)
4272
+ *
4273
+ * @example
4274
+ * ```typescript
4275
+ * flow.label('retry-point')
4276
+ * .execute('queryGen', ...)
4277
+ * ```
4330
4278
  */
4331
- private applyConfigToAxGen;
4279
+ label(label: string): this;
4332
4280
  /**
4333
- * Get optimizer-specific configuration
4334
- * @returns Current optimizer configuration
4281
+ * Short alias for label()
4335
4282
  */
4336
- getConfiguration(): Record<string, unknown>;
4283
+ l(label: string): this;
4337
4284
  /**
4338
- * Update optimizer configuration
4339
- * @param config New configuration to merge with existing
4285
+ * Executes a previously defined node with full type safety.
4286
+ * The node name must exist in TNodes, and the mapping function is typed based on the node's signature.
4287
+ *
4288
+ * @param nodeName - The name of the node to execute (must exist in TNodes)
4289
+ * @param mapping - Typed function that takes the current state and returns the input for the node
4290
+ * @param dynamicContext - Optional object to override the AI service or options for this specific step
4291
+ * @returns New AxFlow instance with TState augmented with the node's result
4292
+ *
4293
+ * @example
4294
+ * ```typescript
4295
+ * flow.execute('summarizer', state => ({ text: state.originalText }), { ai: cheapAI })
4296
+ * ```
4340
4297
  */
4341
- updateConfiguration(config: Readonly<Record<string, unknown>>): void;
4298
+ execute<TNodeName extends keyof TNodes & string>(nodeName: TNodeName, mapping: (state: TState) => GetGenIn<TNodes[TNodeName]>, dynamicContext?: AxFlowDynamicContext): AxFlow<IN, OUT, TNodes, AddNodeResult<TState, TNodeName, GetGenOut<TNodes[TNodeName]>>>;
4342
4299
  /**
4343
- * Reset optimizer state for reuse with different programs
4300
+ * Short alias for execute()
4344
4301
  */
4345
- reset(): void;
4302
+ e<TNodeName extends keyof TNodes & string>(nodeName: TNodeName, mapping: (state: TState) => GetGenIn<TNodes[TNodeName]>, dynamicContext?: AxFlowDynamicContext): AxFlow<IN, OUT, TNodes, AddNodeResult<TState, TNodeName, GetGenOut<TNodes[TNodeName]>>>;
4346
4303
  /**
4347
- * Validate that the optimizer can handle the given program
4348
- * @param program Program to validate
4349
- * @returns Validation result with any issues found
4304
+ * Starts a conditional branch based on a predicate function.
4305
+ *
4306
+ * @param predicate - Function that takes state and returns a value to branch on
4307
+ * @returns this (for chaining)
4308
+ *
4309
+ * @example
4310
+ * ```typescript
4311
+ * flow.branch(state => state.qualityResult.needsMoreInfo)
4312
+ * .when(true)
4313
+ * .execute('queryGen', ...)
4314
+ * .when(false)
4315
+ * .execute('answer', ...)
4316
+ * .merge()
4317
+ * ```
4350
4318
  */
4351
- validateProgram(program: Readonly<AxProgram<IN, OUT>>): {
4352
- isValid: boolean;
4353
- issues: string[];
4354
- suggestions: string[];
4355
- };
4319
+ branch(predicate: (state: TState) => unknown): this;
4356
4320
  /**
4357
- * Encodes a configuration into a string key for surrogate model lookup
4321
+ * Short alias for branch()
4358
4322
  */
4359
- private encodeConfiguration;
4323
+ b(predicate: (state: TState) => unknown): this;
4360
4324
  /**
4361
- * Updates the surrogate model with a new configuration-score pair
4325
+ * Defines a branch case for the current branch context.
4326
+ *
4327
+ * @param value - The value to match against the branch predicate result
4328
+ * @returns this (for chaining)
4362
4329
  */
4363
- private updateSurrogateModel;
4330
+ when(value: unknown): this;
4364
4331
  /**
4365
- * Predicts performance using the surrogate model
4332
+ * Short alias for when()
4366
4333
  */
4367
- private predictPerformance;
4334
+ w(value: unknown): this;
4368
4335
  /**
4369
- * Calculates acquisition function value for Bayesian optimization
4336
+ * Ends the current branch and merges all branch paths back into the main flow.
4337
+ * Optionally specify the explicit merged state type for better type safety.
4338
+ *
4339
+ * @param explicitMergedType - Optional type hint for the merged state (defaults to current TState)
4340
+ * @returns AxFlow instance with the merged state type
4341
+ *
4342
+ * @example
4343
+ * ```typescript
4344
+ * // Default behavior - preserves current TState
4345
+ * flow.branch(state => state.type)
4346
+ * .when('simple').execute('simpleProcessor', ...)
4347
+ * .when('complex').execute('complexProcessor', ...)
4348
+ * .merge()
4349
+ *
4350
+ * // Explicit type - specify exact merged state shape
4351
+ * flow.branch(state => state.type)
4352
+ * .when('simple').map(state => ({ result: state.simpleResult, method: 'simple' }))
4353
+ * .when('complex').map(state => ({ result: state.complexResult, method: 'complex' }))
4354
+ * .merge<{ result: string; method: string }>()
4355
+ * ```
4370
4356
  */
4371
- private calculateAcquisitionValue;
4357
+ merge<TMergedState extends AxFlowState = TState>(): AxFlow<IN, OUT, TNodes, TMergedState>;
4372
4358
  /**
4373
- * Error function approximation for acquisition function calculations
4359
+ * Short alias for merge()
4374
4360
  */
4375
- private erf;
4361
+ mg<TMergedState extends AxFlowState = TState>(): AxFlow<IN, OUT, TNodes, TMergedState>;
4376
4362
  /**
4377
- * Selects the next configuration to evaluate using Bayesian optimization
4378
- */
4379
- private selectConfigurationViaBayesianOptimization;
4380
- }
4381
-
4382
- type AxMockAIServiceConfig = {
4383
- name?: string;
4384
- id?: string;
4385
- modelInfo?: Partial<AxModelInfoWithProvider>;
4386
- embedModelInfo?: AxModelInfoWithProvider;
4387
- features?: {
4388
- functions?: boolean;
4389
- streaming?: boolean;
4390
- };
4391
- models?: AxAIModelList;
4392
- options?: AxAIServiceOptions;
4393
- chatResponse?: AxChatResponse | ReadableStream<AxChatResponse> | (() => Promise<AxChatResponse | ReadableStream<AxChatResponse>>) | ((req: Readonly<AxChatRequest<unknown>>, options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions<unknown, unknown>>) => Promise<AxChatResponse | ReadableStream<AxChatResponse>>);
4394
- embedResponse?: AxEmbedResponse | ((req: Readonly<AxEmbedRequest>) => AxEmbedResponse | Promise<AxEmbedResponse>);
4395
- shouldError?: boolean;
4396
- errorMessage?: string;
4397
- latencyMs?: number;
4398
- };
4399
- declare class AxMockAIService implements AxAIService {
4400
- private readonly config;
4401
- private metrics;
4402
- constructor(config?: AxMockAIServiceConfig);
4403
- getLastUsedChatModel(): unknown;
4404
- getLastUsedEmbedModel(): unknown;
4405
- getLastUsedModelConfig(): AxModelConfig | undefined;
4406
- getName(): string;
4407
- getId(): string;
4408
- getFeatures(_model?: string): {
4409
- functions: boolean;
4410
- streaming: boolean;
4411
- };
4412
- getModelList(): AxAIModelList | undefined;
4413
- getMetrics(): AxAIServiceMetrics;
4414
- chat(req: Readonly<AxChatRequest<unknown>>, options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions<unknown, unknown>>): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
4415
- embed(req: Readonly<AxEmbedRequest>, _options?: Readonly<AxAIServiceActionOptions>): Promise<AxEmbedResponse>;
4416
- setOptions(options: Readonly<AxAIServiceOptions>): void;
4417
- getOptions(): Readonly<AxAIServiceOptions>;
4418
- getLogger(): AxLoggerFunction;
4419
- private updateMetrics;
4420
- }
4421
-
4422
- interface AxRateLimiterTokenUsageOptions {
4423
- debug?: boolean;
4424
- }
4425
- declare class AxRateLimiterTokenUsage {
4426
- private options?;
4427
- private maxTokens;
4428
- private refillRate;
4429
- private currentTokens;
4430
- private lastRefillTime;
4431
- constructor(maxTokens: number, refillRate: number, options?: Readonly<AxRateLimiterTokenUsageOptions>);
4432
- private refillTokens;
4433
- private waitUntilTokensAvailable;
4434
- acquire(tokens: number): Promise<void>;
4435
- }
4436
-
4437
- interface AxSimpleClassifierForwardOptions {
4438
- cutoff?: number;
4439
- abortSignal?: AbortSignal;
4440
- }
4441
- declare class AxSimpleClassifierClass {
4442
- private readonly name;
4443
- private readonly context;
4444
- constructor(name: string, context: readonly string[]);
4445
- getName(): string;
4446
- getContext(): readonly string[];
4447
- }
4448
- declare class AxSimpleClassifier {
4449
- private readonly ai;
4450
- private db;
4451
- private debug?;
4452
- constructor(ai: AxAIService);
4453
- getState(): AxDBState | undefined;
4454
- setState(state: AxDBState): void;
4455
- setClasses: (classes: readonly AxSimpleClassifierClass[], options?: Readonly<{
4456
- abortSignal?: AbortSignal;
4457
- }>) => Promise<void>;
4458
- forward(text: string, options?: Readonly<AxSimpleClassifierForwardOptions>): Promise<string>;
4459
- setOptions(options: Readonly<{
4460
- debug?: boolean;
4461
- }>): void;
4462
- }
4463
-
4464
- type AxEvaluateArgs<IN extends AxGenIn, OUT extends AxGenOut> = {
4465
- ai: AxAIService;
4466
- program: Readonly<AxProgram<IN, OUT>>;
4467
- examples: Readonly<AxExample[]>;
4468
- };
4469
- declare class AxTestPrompt<IN extends AxGenIn = AxGenIn, OUT extends AxGenOut = AxGenOut> {
4470
- private ai;
4471
- private program;
4472
- private examples;
4473
- constructor({ ai, program, examples, }: Readonly<AxEvaluateArgs<IN, OUT>>);
4474
- run(metricFn: AxMetricFn): Promise<void>;
4475
- }
4476
-
4477
- type AxSignatureTemplateValue = string | AxFieldType | AxFieldDescriptor | AxSignature;
4478
- interface AxFieldType {
4479
- readonly type: 'string' | 'number' | 'boolean' | 'json' | 'image' | 'audio' | 'date' | 'datetime' | 'class' | 'code';
4480
- readonly isArray?: boolean;
4481
- readonly options?: readonly string[];
4482
- readonly description?: string;
4483
- readonly isOptional?: boolean;
4484
- readonly isInternal?: boolean;
4485
- }
4486
- interface AxFieldDescriptor {
4487
- readonly name: string;
4488
- readonly type?: AxFieldType;
4489
- readonly description?: string;
4490
- readonly isOptional?: boolean;
4491
- readonly isInternal?: boolean;
4492
- }
4493
- declare function s(strings: TemplateStringsArray, ...values: readonly AxSignatureTemplateValue[]): AxSignature;
4494
- declare function ax<IN extends AxGenIn = AxGenIn, OUT extends AxGenerateResult<AxGenOut> = AxGenerateResult<AxGenOut>>(strings: TemplateStringsArray, ...values: readonly AxSignatureTemplateValue[]): AxGen<IN, OUT>;
4495
- declare const f: {
4496
- string: (desc?: string) => AxFieldType;
4497
- number: (desc?: string) => AxFieldType;
4498
- boolean: (desc?: string) => AxFieldType;
4499
- date: (desc?: string) => AxFieldType;
4500
- datetime: (desc?: string) => AxFieldType;
4501
- json: (desc?: string) => AxFieldType;
4502
- image: (desc?: string) => AxFieldType;
4503
- audio: (desc?: string) => AxFieldType;
4504
- class: (options: readonly string[], desc?: string) => AxFieldType;
4505
- code: (language: string, desc?: string) => AxFieldType;
4506
- array: <T extends AxFieldType>(baseType: T) => T & {
4507
- readonly isArray: true;
4363
+ * Executes multiple operations in parallel and merges their results.
4364
+ * Both typed and legacy untyped branches are supported.
4365
+ *
4366
+ * @param branches - Array of functions that define parallel operations
4367
+ * @returns Object with merge method for combining results
4368
+ *
4369
+ * @example
4370
+ * ```typescript
4371
+ * flow.parallel([
4372
+ * subFlow => subFlow.execute('retrieve1', state => ({ query: state.query1 })),
4373
+ * subFlow => subFlow.execute('retrieve2', state => ({ query: state.query2 })),
4374
+ * subFlow => subFlow.execute('retrieve3', state => ({ query: state.query3 }))
4375
+ * ]).merge('documents', (docs1, docs2, docs3) => [...docs1, ...docs2, ...docs3])
4376
+ * ```
4377
+ */
4378
+ parallel(branches: (AxFlowParallelBranch | AxFlowTypedParallelBranch<TNodes, TState>)[]): {
4379
+ merge<T, TResultKey extends string>(resultKey: TResultKey, mergeFunction: (...results: unknown[]) => T): AxFlow<IN, OUT, TNodes, TState & {
4380
+ [K in TResultKey]: T;
4381
+ }>;
4508
4382
  };
4509
- optional: <T extends AxFieldType>(baseType: T) => T & {
4510
- readonly isOptional: true;
4383
+ /**
4384
+ * Short alias for parallel()
4385
+ */
4386
+ p(branches: (AxFlowParallelBranch | AxFlowTypedParallelBranch<TNodes, TState>)[]): {
4387
+ merge<T, TResultKey extends string>(resultKey: TResultKey, mergeFunction: (...results: unknown[]) => T): AxFlow<IN, OUT, TNodes, TState & {
4388
+ [K in TResultKey]: T;
4389
+ }>;
4511
4390
  };
4512
- internal: <T extends AxFieldType>(baseType: T) => T & {
4513
- readonly isInternal: true;
4391
+ /**
4392
+ * Creates a feedback loop that jumps back to a labeled step if a condition is met.
4393
+ *
4394
+ * @param condition - Function that returns true to trigger the feedback loop
4395
+ * @param targetLabel - The label to jump back to
4396
+ * @param maxIterations - Maximum number of iterations to prevent infinite loops (default: 10)
4397
+ * @returns this (for chaining)
4398
+ *
4399
+ * @example
4400
+ * ```typescript
4401
+ * flow.label('retry-point')
4402
+ * .execute('answer', ...)
4403
+ * .execute('qualityCheck', ...)
4404
+ * .feedback(state => state.qualityCheckResult.confidence < 0.7, 'retry-point')
4405
+ * ```
4406
+ */
4407
+ feedback(condition: (state: TState) => boolean, targetLabel: string, maxIterations?: number): this;
4408
+ /**
4409
+ * Short alias for feedback()
4410
+ */
4411
+ fb(condition: (state: TState) => boolean, targetLabel: string, maxIterations?: number): this;
4412
+ /**
4413
+ * Marks the beginning of a loop block.
4414
+ *
4415
+ * @param condition - Function that takes the current state and returns a boolean
4416
+ * @param maxIterations - Maximum number of iterations to prevent infinite loops (default: 100)
4417
+ * @returns this (for chaining)
4418
+ *
4419
+ * @example
4420
+ * ```typescript
4421
+ * flow.while(state => state.iterations < 3, 10)
4422
+ * .map(state => ({ ...state, iterations: (state.iterations || 0) + 1 }))
4423
+ * .endWhile()
4424
+ * ```
4425
+ */
4426
+ while(condition: (state: TState) => boolean, maxIterations?: number): this;
4427
+ /**
4428
+ * Short alias for while()
4429
+ */
4430
+ wh(condition: (state: TState) => boolean, maxIterations?: number): this;
4431
+ /**
4432
+ * Marks the end of a loop block.
4433
+ *
4434
+ * @returns this (for chaining)
4435
+ */
4436
+ endWhile(): this;
4437
+ /**
4438
+ * Short alias for endWhile()
4439
+ */
4440
+ end(): this;
4441
+ /**
4442
+ * Executes the flow with the given AI service and input values.
4443
+ *
4444
+ * @param ai - The AI service to use as the default for all steps
4445
+ * @param values - The input values for the flow
4446
+ * @param options - Optional forward options to use as defaults (includes autoParallel override)
4447
+ * @returns Promise that resolves to the final output
4448
+ */
4449
+ forward(ai: Readonly<AxAIService>, values: IN, options?: Readonly<AxProgramForwardOptions & {
4450
+ autoParallel?: boolean;
4451
+ }>): Promise<OUT>;
4452
+ /**
4453
+ * Gets execution plan information for debugging automatic parallelization
4454
+ *
4455
+ * @returns Object with execution plan details
4456
+ */
4457
+ getExecutionPlan(): {
4458
+ totalSteps: number;
4459
+ parallelGroups: number;
4460
+ maxParallelism: number;
4461
+ autoParallelEnabled: boolean;
4462
+ steps?: AxFlowExecutionStep[];
4463
+ groups?: AxFlowParallelGroup[];
4514
4464
  };
4515
- };
4516
-
4517
- interface AxMetricsConfig {
4518
- enabled: boolean;
4519
- enabledCategories: ('generation' | 'streaming' | 'functions' | 'errors' | 'performance')[];
4520
- maxLabelLength: number;
4521
- samplingRate: number;
4522
- }
4523
- declare const axDefaultMetricsConfig: AxMetricsConfig;
4524
- type AxErrorCategory = 'validation_error' | 'assertion_error' | 'timeout_error' | 'abort_error' | 'network_error' | 'auth_error' | 'rate_limit_error' | 'function_error' | 'parsing_error' | 'unknown_error';
4525
- interface AxGenMetricsInstruments {
4526
- generationLatencyHistogram?: Histogram;
4527
- generationRequestsCounter?: Counter;
4528
- generationErrorsCounter?: Counter;
4529
- multiStepGenerationsCounter?: Counter;
4530
- stepsPerGenerationHistogram?: Histogram;
4531
- maxStepsReachedCounter?: Counter;
4532
- validationErrorsCounter?: Counter;
4533
- assertionErrorsCounter?: Counter;
4534
- errorCorrectionAttemptsHistogram?: Histogram;
4535
- errorCorrectionSuccessCounter?: Counter;
4536
- errorCorrectionFailureCounter?: Counter;
4537
- maxRetriesReachedCounter?: Counter;
4538
- functionsEnabledGenerationsCounter?: Counter;
4539
- functionCallStepsCounter?: Counter;
4540
- functionsExecutedPerGenerationHistogram?: Histogram;
4541
- functionErrorCorrectionCounter?: Counter;
4542
- fieldProcessorsExecutedCounter?: Counter;
4543
- streamingFieldProcessorsExecutedCounter?: Counter;
4544
- streamingGenerationsCounter?: Counter;
4545
- streamingDeltasEmittedCounter?: Counter;
4546
- streamingFinalizationLatencyHistogram?: Histogram;
4547
- samplesGeneratedHistogram?: Histogram;
4548
- resultPickerUsageCounter?: Counter;
4549
- resultPickerLatencyHistogram?: Histogram;
4550
- inputFieldsGauge?: Gauge;
4551
- outputFieldsGauge?: Gauge;
4552
- examplesUsedGauge?: Gauge;
4553
- demosUsedGauge?: Gauge;
4554
- promptRenderLatencyHistogram?: Histogram;
4555
- extractionLatencyHistogram?: Histogram;
4556
- assertionLatencyHistogram?: Histogram;
4557
- stateCreationLatencyHistogram?: Histogram;
4558
- memoryUpdateLatencyHistogram?: Histogram;
4559
4465
  }
4560
- declare const axCheckMetricsHealth: () => {
4561
- healthy: boolean;
4562
- issues: string[];
4563
- };
4564
- declare const axUpdateMetricsConfig: (config: Readonly<Partial<AxMetricsConfig>>) => void;
4565
- declare const axGetMetricsConfig: () => AxMetricsConfig;
4566
-
4567
- declare const axCreateDefaultLogger: (output?: (message: string) => void) => AxLoggerFunction;
4568
- declare const axCreateDefaultTextLogger: (output?: (message: string) => void) => AxLoggerFunction;
4569
- /**
4570
- * Factory function to create an enhanced optimizer logger with clean visual formatting
4571
- * that works for all optimizer types using semantic tags for proper categorization
4572
- */
4573
- declare const axCreateOptimizerLogger: (output?: (message: string) => void) => AxLoggerFunction;
4574
- /**
4575
- * Default optimizer logger instance
4576
- */
4577
- declare const axDefaultOptimizerLogger: AxLoggerFunction;
4578
-
4579
4466
  /**
4580
- * OpenAI: Model information
4581
- */
4582
- declare const axModelInfoOpenAI: AxModelInfo[];
4583
- /**
4584
- * OpenAI: Model information
4585
- */
4586
- declare const axModelInfoOpenAIResponses: AxModelInfo[];
4587
-
4588
- type AxChatRequestMessage = AxChatRequest['chatPrompt'][number];
4589
- /**
4590
- * Validates a chat request message item to ensure it meets the required criteria
4591
- * @param item - The chat request message to validate
4592
- * @throws {Error} When validation fails with a descriptive error message
4593
- */
4594
- declare function axValidateChatRequestMessage(item: AxChatRequestMessage): void;
4595
- /**
4596
- * Validates a chat response result to ensure it meets the required criteria
4597
- * @param results - The chat response results to validate (single result or array)
4598
- * @throws {Error} When validation fails with a descriptive error message
4467
+ * Typed implementation of the sub-context for parallel execution with full type safety
4599
4468
  */
4600
- declare function axValidateChatResponseResult(results: Readonly<AxChatResponseResult[]> | Readonly<AxChatResponseResult>): void;
4601
-
4602
- declare class AxAIOpenAIResponsesImpl<TModel, TEmbedModel, // Kept for interface compatibility, but not used by this impl.
4603
- TResponsesReq extends AxAIOpenAIResponsesRequest<TModel>> implements AxAIServiceImpl<TModel, TEmbedModel, Readonly<AxAIOpenAIResponsesRequest<TModel>>, // ChatReq (now ResponsesReq)
4604
- Readonly<AxAIOpenAIEmbedRequest<TEmbedModel>>, // EmbedReq
4605
- Readonly<AxAIOpenAIResponsesResponse>, // ChatResp (now ResponsesResp)
4606
- Readonly<AxAIOpenAIResponsesResponseDelta>, // ChatRespDelta (now ResponsesRespDelta)
4607
- Readonly<AxAIOpenAIEmbedResponse>> {
4608
- private readonly config;
4609
- private readonly streamingUsage;
4610
- private readonly responsesReqUpdater?;
4611
- private tokensUsed;
4612
- constructor(config: Readonly<AxAIOpenAIResponsesConfig<TModel, TEmbedModel>>, streamingUsage: boolean, // If /v1/responses supports include_usage for streams
4613
- responsesReqUpdater?: ResponsesReqUpdater<TModel, TResponsesReq> | undefined);
4614
- getTokenUsage(): Readonly<AxTokenUsage> | undefined;
4615
- getModelConfig(): Readonly<AxModelConfig>;
4616
- private mapInternalContentToResponsesInput;
4617
- private createResponsesReqInternalInput;
4618
- createChatReq(req: Readonly<AxInternalChatRequest<TModel>>, config: Readonly<AxAIPromptConfig>): [Readonly<AxAPI>, Readonly<AxAIOpenAIResponsesRequest<TModel>>];
4619
- createChatResp(resp: Readonly<AxAIOpenAIResponsesResponse>): Readonly<AxChatResponse>;
4620
- createChatStreamResp(streamEvent: Readonly<AxAIOpenAIResponsesResponseDelta>): Readonly<AxChatResponse>;
4621
- createEmbedReq(req: Readonly<AxInternalEmbedRequest<TEmbedModel>>): [AxAPI, AxAIOpenAIEmbedRequest<TEmbedModel>];
4622
- }
4623
-
4624
- declare class AxBootstrapFewShot<IN extends AxGenIn = AxGenIn, OUT extends AxGenOut = AxGenOut> extends AxBaseOptimizer<IN, OUT> {
4625
- private maxRounds;
4626
- private maxDemos;
4627
- private maxExamples;
4628
- private batchSize;
4629
- private earlyStoppingPatience;
4630
- private costMonitoring;
4631
- private maxTokensPerGeneration;
4632
- private verboseMode;
4633
- private debugMode;
4634
- private traces;
4635
- constructor(args: Readonly<AxOptimizerArgs & {
4636
- options?: AxBootstrapOptimizerOptions;
4637
- }>);
4638
- private compileRound;
4639
- compile(program: Readonly<AxProgram<IN, OUT>>, metricFn: AxMetricFn, options?: AxBootstrapCompileOptions): Promise<AxOptimizerResult<OUT>>;
4469
+ declare class AxFlowTypedSubContextImpl<TNodes extends Record<string, AxGen<any, any>>, TState extends AxFlowState> implements AxFlowTypedSubContext<TNodes, TState> {
4470
+ private readonly nodeGenerators;
4471
+ private readonly steps;
4472
+ constructor(nodeGenerators: Map<string, AxGen<AxGenIn, AxGenOut> | AxProgram<AxGenIn, AxGenOut>>);
4473
+ execute<TNodeName extends keyof TNodes & string>(nodeName: TNodeName, mapping: (state: TState) => GetGenIn<TNodes[TNodeName]>, dynamicContext?: AxFlowDynamicContext): AxFlowTypedSubContext<TNodes, AddNodeResult<TState, TNodeName, GetGenOut<TNodes[TNodeName]>>>;
4474
+ map<TNewState extends AxFlowState>(transform: (state: TState) => TNewState): AxFlowTypedSubContext<TNodes, TNewState>;
4475
+ executeSteps(initialState: TState, context: Readonly<{
4476
+ mainAi: AxAIService;
4477
+ mainOptions?: AxProgramForwardOptions;
4478
+ }>): Promise<AxFlowState>;
4640
4479
  }
4641
4480
 
4642
- declare class AxChainOfThought<IN extends AxGenIn = AxGenIn, OUT extends AxGenOut = AxGenOut> extends AxGen<IN, OUT> {
4643
- constructor(signature: Readonly<AxSignature | string>, options?: Readonly<AxProgramForwardOptions & {
4644
- setVisibleReasoning?: boolean;
4645
- }>);
4481
+ interface AxDockerContainer {
4482
+ Id: string;
4483
+ Names: string[];
4484
+ Image: string;
4485
+ ImageID: string;
4486
+ Command: string;
4487
+ Created: number;
4488
+ State: {
4489
+ Status: string;
4490
+ Running: boolean;
4491
+ Paused: boolean;
4492
+ Restarting: boolean;
4493
+ OOMKilled: boolean;
4494
+ Dead: boolean;
4495
+ Pid: number;
4496
+ ExitCode: number;
4497
+ Error: string;
4498
+ StartedAt: Date;
4499
+ FinishedAt: Date;
4500
+ };
4501
+ Status: string;
4502
+ Ports: Array<{
4503
+ IP: string;
4504
+ PrivatePort: number;
4505
+ PublicPort: number;
4506
+ Type: string;
4507
+ }>;
4508
+ Labels: {
4509
+ [key: string]: string;
4510
+ };
4511
+ SizeRw: number;
4512
+ SizeRootFs: number;
4513
+ HostConfig: {
4514
+ NetworkMode: string;
4515
+ };
4516
+ NetworkSettings: {
4517
+ Networks: {
4518
+ [key: string]: {
4519
+ IPAddress: string;
4520
+ IPPrefixLen: number;
4521
+ Gateway: string;
4522
+ MacAddress: string;
4523
+ };
4524
+ };
4525
+ };
4526
+ Mounts: Array<{
4527
+ Type: string;
4528
+ Source: string;
4529
+ Destination: string;
4530
+ Mode: string;
4531
+ RW: boolean;
4532
+ Propagation: string;
4533
+ }>;
4646
4534
  }
4647
-
4648
- declare class AxDefaultResultReranker extends AxGen<AxRerankerIn, AxRerankerOut> {
4649
- constructor(options?: Readonly<AxProgramForwardOptions>);
4650
- forward: (ai: Readonly<AxAIService>, input: Readonly<AxRerankerIn>, options?: Readonly<AxProgramForwardOptions>) => Promise<AxRerankerOut>;
4535
+ declare class AxDockerSession {
4536
+ private readonly apiUrl;
4537
+ private containerId;
4538
+ constructor(apiUrl?: string);
4539
+ pullImage(imageName: string): Promise<void>;
4540
+ createContainer({ imageName, volumes, doNotPullImage, tag, }: Readonly<{
4541
+ imageName: string;
4542
+ volumes?: Array<{
4543
+ hostPath: string;
4544
+ containerPath: string;
4545
+ }>;
4546
+ doNotPullImage?: boolean;
4547
+ tag?: string;
4548
+ }>): Promise<{
4549
+ Id: string;
4550
+ }>;
4551
+ findOrCreateContainer({ imageName, volumes, doNotPullImage, tag, }: Readonly<{
4552
+ imageName: string;
4553
+ volumes?: Array<{
4554
+ hostPath: string;
4555
+ containerPath: string;
4556
+ }>;
4557
+ doNotPullImage?: boolean;
4558
+ tag: string;
4559
+ }>): Promise<{
4560
+ Id: string;
4561
+ isNew: boolean;
4562
+ }>;
4563
+ startContainer(): Promise<void>;
4564
+ connectToContainer(containerId: string): Promise<void>;
4565
+ stopContainers({ tag, remove, timeout, }: Readonly<{
4566
+ tag?: string;
4567
+ remove?: boolean;
4568
+ timeout?: number;
4569
+ }>): Promise<Array<{
4570
+ Id: string;
4571
+ Action: 'stopped' | 'removed';
4572
+ }>>;
4573
+ listContainers(all?: boolean): Promise<AxDockerContainer[]>;
4574
+ getContainerLogs(): Promise<string>;
4575
+ executeCommand(command: string): Promise<string>;
4576
+ private getContainerInfo;
4577
+ private waitForContainerToBeRunning;
4578
+ private fetchDockerAPI;
4579
+ toFunction(): AxFunction;
4651
4580
  }
4652
4581
 
4653
4582
  declare class AxEmbeddingAdapter {
@@ -4667,55 +4596,50 @@ declare class AxEmbeddingAdapter {
4667
4596
  toFunction(): AxFunction;
4668
4597
  }
4669
4598
 
4670
- /**
4671
- * Calculates the Exact Match (EM) score between a prediction and ground truth.
4672
- *
4673
- * The EM score is a strict metric used in machine learning to assess if the predicted
4674
- * answer matches the ground truth exactly, commonly used in tasks like question answering.
4675
- *
4676
- * @param prediction The predicted text.
4677
- * @param groundTruth The actual correct text.
4678
- * @returns A number (1.0 for exact match, 0.0 otherwise).
4679
- */
4680
- declare function emScore(prediction: string, groundTruth: string): number;
4681
- /**
4682
- * Calculates the F1 score between a prediction and ground truth.
4683
- *
4684
- * The F1 score is a harmonic mean of precision and recall, widely used in NLP to measure
4685
- * a model's accuracy in considering both false positives and false negatives, offering a
4686
- * balance for evaluating classification models.
4687
- *
4688
- * @param prediction The predicted text.
4689
- * @param groundTruth The actual correct text.
4690
- * @returns The F1 score as a number.
4691
- */
4692
- declare function f1Score(prediction: string, groundTruth: string): number;
4693
- /**
4694
- * Calculates a novel F1 score, taking into account a history of interaction and excluding stopwords.
4695
- *
4696
- * This metric extends the F1 score by considering contextual relevance and filtering out common words
4697
- * that might skew the assessment of the prediction's quality, especially in conversational models or
4698
- * when historical context is relevant.
4699
- *
4700
- * @param history The historical context or preceding interactions.
4701
- * @param prediction The predicted text.
4702
- * @param groundTruth The actual correct text.
4703
- * @param returnRecall Optionally return the recall score instead of F1.
4704
- * @returns The novel F1 or recall score as a number.
4705
- */
4706
- declare function novelF1ScoreOptimized(history: string, prediction: string, groundTruth: string, returnRecall?: boolean): number;
4707
- declare const AxEvalUtil: {
4708
- emScore: typeof emScore;
4709
- f1Score: typeof f1Score;
4710
- novelF1ScoreOptimized: typeof novelF1ScoreOptimized;
4711
- };
4599
+ interface JSONRPCRequest<T> {
4600
+ jsonrpc: '2.0';
4601
+ id: string | number;
4602
+ method: string;
4603
+ params?: T;
4604
+ }
4605
+ interface JSONRPCSuccessResponse<T = unknown> {
4606
+ jsonrpc: '2.0';
4607
+ id: string | number;
4608
+ result: T;
4609
+ }
4610
+ interface JSONRPCErrorResponse {
4611
+ jsonrpc: '2.0';
4612
+ id: string | number;
4613
+ error: {
4614
+ code: number;
4615
+ message: string;
4616
+ data?: unknown;
4617
+ };
4618
+ }
4619
+ type JSONRPCResponse<T = unknown> = JSONRPCSuccessResponse<T> | JSONRPCErrorResponse;
4620
+ interface JSONRPCNotification {
4621
+ jsonrpc: '2.0';
4622
+ method: string;
4623
+ params?: Record<string, unknown>;
4624
+ }
4712
4625
 
4713
- type AxInstanceRegistryItem<T extends AxTunable<IN, OUT>, IN extends AxGenIn, OUT extends AxGenOut> = T & AxUsable;
4714
- declare class AxInstanceRegistry<T extends AxTunable<IN, OUT>, IN extends AxGenIn, OUT extends AxGenOut> {
4715
- private reg;
4716
- constructor();
4717
- register(instance: AxInstanceRegistryItem<T, IN, OUT>): void;
4718
- [Symbol.iterator](): Generator<AxInstanceRegistryItem<T, IN, OUT> | undefined, void, unknown>;
4626
+ interface AxMCPTransport {
4627
+ /**
4628
+ * Sends a JSON-RPC request or notification and returns the response
4629
+ * @param message The JSON-RPC request or notification to send
4630
+ * @returns A Promise that resolves to the JSON-RPC response
4631
+ */
4632
+ send(message: Readonly<JSONRPCRequest<unknown>>): Promise<JSONRPCResponse<unknown>>;
4633
+ /**
4634
+ * Sends a JSON-RPC notification
4635
+ * @param message The JSON-RPC notification to send
4636
+ */
4637
+ sendNotification(message: Readonly<JSONRPCNotification>): Promise<void>;
4638
+ /**
4639
+ * Connects to the transport if needed
4640
+ * This method is optional and only required for transports that need connection setup
4641
+ */
4642
+ connect?(): Promise<void>;
4719
4643
  }
4720
4644
 
4721
4645
  /**
@@ -4777,89 +4701,173 @@ declare class AxMCPClient {
4777
4701
  private sendNotification;
4778
4702
  }
4779
4703
 
4780
- interface StdioTransportConfig {
4781
- command: string;
4782
- args?: string[];
4783
- env?: NodeJS.ProcessEnv;
4784
- }
4785
- declare class AxMCPStdioTransport implements AxMCPTransport {
4786
- private process;
4787
- private rl;
4788
- private pendingResponses;
4789
- constructor(config: Readonly<StdioTransportConfig>);
4790
- send(message: Readonly<JSONRPCRequest<unknown>>): Promise<JSONRPCResponse<unknown>>;
4791
- sendNotification(message: Readonly<JSONRPCNotification>): Promise<void>;
4704
+ declare class AxMCPHTTPSSETransport implements AxMCPTransport {
4705
+ private endpoint;
4706
+ private sseUrl;
4707
+ private eventSource?;
4708
+ constructor(sseUrl: string);
4792
4709
  connect(): Promise<void>;
4710
+ send(message: JSONRPCRequest<unknown> | JSONRPCNotification): Promise<JSONRPCResponse<unknown>>;
4711
+ sendNotification(message: Readonly<JSONRPCNotification>): Promise<void>;
4793
4712
  }
4794
-
4795
- type AxAIServiceListItem<TModel = unknown, TEmbedModel = unknown> = {
4796
- key: string;
4797
- service: AxAIService<TModel, TEmbedModel>;
4798
- description: string;
4799
- isInternal?: boolean;
4800
- };
4801
- declare class AxMultiServiceRouter implements AxAIService<string, string> {
4802
- private options?;
4803
- private lastUsedService?;
4804
- private services;
4713
+ interface AxMCPStreamableHTTPTransportOptions {
4805
4714
  /**
4806
- * Constructs a new multi-service router.
4807
- * It validates that each service provides a unique set of model keys,
4808
- * then builds a lookup (map) for routing the chat/embed requests.
4715
+ * Custom headers to include with all HTTP requests
4716
+ * Note: Content-Type, Accept, and Mcp-Session-Id are managed automatically
4809
4717
  */
4810
- constructor(services: (AxAIServiceListItem<string, string> | AxAIService<string, string>)[]);
4811
- getLastUsedChatModel(): string | undefined;
4812
- getLastUsedEmbedModel(): string | undefined;
4813
- getLastUsedModelConfig(): AxModelConfig | undefined;
4718
+ headers?: Record<string, string>;
4814
4719
  /**
4815
- * Delegates the chat call to the service matching the provided model key.
4720
+ * Authorization header value (convenience for common use case)
4721
+ * If provided, will be added to the headers as 'Authorization'
4816
4722
  */
4817
- chat(req: Readonly<AxChatRequest<string>>, options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions<string, string>>): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
4723
+ authorization?: string;
4724
+ }
4725
+ /**
4726
+ * AxMCPStreambleHTTPTransport implements the 2025-03-26 Streamable HTTP transport specification
4727
+ * This transport uses a single HTTP endpoint that supports both POST and GET methods
4728
+ */
4729
+ declare class AxMCPStreambleHTTPTransport implements AxMCPTransport {
4730
+ private mcpEndpoint;
4731
+ private sessionId?;
4732
+ private eventSource?;
4733
+ private pendingRequests;
4734
+ private messageHandler?;
4735
+ private customHeaders;
4736
+ constructor(mcpEndpoint: string, options?: AxMCPStreamableHTTPTransportOptions);
4818
4737
  /**
4819
- * Delegates the embed call to the service matching the provided embed model key.
4738
+ * Update custom headers (useful for refreshing tokens)
4820
4739
  */
4821
- embed(req: Readonly<AxEmbedRequest<string>>, options?: Readonly<AxAIServiceActionOptions<string, string>>): Promise<AxEmbedResponse>;
4740
+ setHeaders(headers: Record<string, string>): void;
4822
4741
  /**
4823
- * Returns a composite ID built from the IDs of the underlying services.
4742
+ * Update authorization header (convenience method)
4824
4743
  */
4825
- getId(): string;
4744
+ setAuthorization(authorization: string): void;
4826
4745
  /**
4827
- * Returns the name of this router.
4746
+ * Get a copy of the current custom headers
4828
4747
  */
4829
- getName(): string;
4748
+ getHeaders(): Record<string, string>;
4830
4749
  /**
4831
- * Aggregates all available models across the underlying services.
4750
+ * Build headers for HTTP requests, merging custom headers with required ones
4832
4751
  */
4833
- getModelList(): AxAIModelList;
4752
+ private buildHeaders;
4834
4753
  /**
4835
- * If a model key is provided, delegate to the corresponding service's features.
4836
- * Otherwise, returns a default feature set.
4754
+ * Set a handler for incoming server messages (requests/notifications)
4755
+ */
4756
+ setMessageHandler(handler: (message: JSONRPCRequest<unknown> | JSONRPCNotification) => void): void;
4757
+ connect(): Promise<void>;
4758
+ /**
4759
+ * Opens an SSE stream to listen for server-initiated messages
4760
+ */
4761
+ openListeningStream(): Promise<void>;
4762
+ /**
4763
+ * Opens an SSE stream using fetch API to support custom headers
4837
4764
  */
4838
- getFeatures(model?: string): {
4839
- functions: boolean;
4840
- streaming: boolean;
4841
- functionCot?: boolean;
4842
- };
4765
+ private openListeningStreamWithFetch;
4766
+ send(message: Readonly<JSONRPCRequest<unknown>>): Promise<JSONRPCResponse<unknown>>;
4767
+ private handleSSEResponse;
4768
+ sendNotification(message: Readonly<JSONRPCNotification>): Promise<void>;
4843
4769
  /**
4844
- * Returns aggregated metrics from the underlying service.
4845
- * Uses the metrics from the last service that was used,
4846
- * or falls back to the first service if none has been used.
4770
+ * Explicitly terminate the session (if supported by server)
4847
4771
  */
4848
- getMetrics(): AxAIServiceMetrics;
4772
+ terminateSession(): Promise<void>;
4849
4773
  /**
4850
- * Sets options on all underlying services.
4774
+ * Close any open connections
4851
4775
  */
4852
- setOptions(options: Readonly<AxAIServiceOptions>): void;
4776
+ close(): void;
4777
+ }
4778
+
4779
+ interface StdioTransportConfig {
4780
+ command: string;
4781
+ args?: string[];
4782
+ env?: NodeJS.ProcessEnv;
4783
+ }
4784
+ declare class AxMCPStdioTransport implements AxMCPTransport {
4785
+ private process;
4786
+ private rl;
4787
+ private pendingResponses;
4788
+ constructor(config: Readonly<StdioTransportConfig>);
4789
+ send(message: Readonly<JSONRPCRequest<unknown>>): Promise<JSONRPCResponse<unknown>>;
4790
+ sendNotification(message: Readonly<JSONRPCNotification>): Promise<void>;
4791
+ connect(): Promise<void>;
4792
+ }
4793
+
4794
+ /**
4795
+ * Interface for agents that can be used as child agents.
4796
+ * Provides methods to get the agent's function definition and features.
4797
+ */
4798
+ interface AxAgentic<IN extends AxGenIn, OUT extends AxGenOut> extends AxTunable<IN, OUT>, AxUsable {
4799
+ getFunction(): AxFunction;
4800
+ getFeatures(): AxAgentFeatures;
4801
+ }
4802
+ type AxAgentOptions = Omit<AxProgramForwardOptions, 'functions'> & {
4803
+ disableSmartModelRouting?: boolean;
4804
+ /** List of field names that should not be automatically passed from parent to child agents */
4805
+ excludeFieldsFromPassthrough?: string[];
4806
+ debug?: boolean;
4807
+ };
4808
+ interface AxAgentFeatures {
4809
+ /** Whether this agent can use smart model routing (requires an AI service) */
4810
+ canConfigureSmartModelRouting: boolean;
4811
+ /** List of fields that this agent excludes from parent->child value passing */
4812
+ excludeFieldsFromPassthrough: string[];
4813
+ }
4814
+ /**
4815
+ * An AI agent that can process inputs using an AI service and coordinate with child agents.
4816
+ * Supports features like smart model routing and automatic input field passing to child agents.
4817
+ */
4818
+ declare class AxAgent<IN extends AxGenIn, OUT extends AxGenOut> implements AxAgentic<IN, OUT> {
4819
+ private ai?;
4820
+ private program;
4821
+ private functions?;
4822
+ private agents?;
4823
+ private disableSmartModelRouting?;
4824
+ private excludeFieldsFromPassthrough;
4825
+ private debug?;
4826
+ private name;
4827
+ private func;
4828
+ constructor({ ai, name, description, definition, signature, agents, functions, }: Readonly<{
4829
+ ai?: Readonly<AxAIService>;
4830
+ name: string;
4831
+ description: string;
4832
+ definition?: string;
4833
+ signature: NonNullable<ConstructorParameters<typeof AxSignature>[0]>;
4834
+ agents?: AxAgentic<IN, OUT>[];
4835
+ functions?: AxInputFunctionType;
4836
+ }>, options?: Readonly<AxAgentOptions>);
4837
+ setExamples(examples: Readonly<AxProgramExamples<IN, OUT>>, options?: Readonly<AxSetExamplesOptions>): void;
4838
+ setId(id: string): void;
4839
+ setParentId(parentId: string): void;
4840
+ getTraces(): AxProgramTrace<IN, OUT>[];
4841
+ setDemos(demos: readonly AxProgramDemos<IN, OUT>[]): void;
4842
+ getUsage(): (AxModelUsage & {
4843
+ ai: string;
4844
+ model: string;
4845
+ })[];
4846
+ resetUsage(): void;
4847
+ getFunction(): AxFunction;
4848
+ getFeatures(): AxAgentFeatures;
4853
4849
  /**
4854
- * Returns the options from the last used service,
4855
- * or falls back to the first service if none has been used.
4850
+ * Initializes the agent's execution context, processing child agents and their functions.
4856
4851
  */
4857
- getOptions(): Readonly<AxAIServiceOptions>;
4852
+ private init;
4853
+ forward(parentAi: Readonly<AxAIService>, values: IN | AxMessage<IN>[], options?: Readonly<AxProgramForwardOptions>): Promise<OUT>;
4854
+ streamingForward(parentAi: Readonly<AxAIService>, values: IN | AxMessage<IN>[], options?: Readonly<AxProgramStreamingForwardOptions>): AxGenStreamingOut<OUT>;
4858
4855
  /**
4859
- * Returns the logger from the last used service,
4860
- * or falls back to the first service if none has been used.
4856
+ * Updates the agent's description.
4857
+ * This updates both the stored description and the function's description.
4858
+ *
4859
+ * @param description - New description for the agent (must be at least 20 characters)
4860
+ * @throws Error if description is too short
4861
4861
  */
4862
- getLogger(): AxLoggerFunction;
4862
+ setDescription(description: string): void;
4863
+ setDefinition(definition: string): void;
4864
+ private getDebug;
4865
+ }
4866
+
4867
+ declare class AxChainOfThought<IN extends AxGenIn = AxGenIn, OUT extends AxGenOut = AxGenOut> extends AxGen<IN, OUT> {
4868
+ constructor(signature: Readonly<AxSignature | string>, options?: Readonly<AxProgramForwardOptions & {
4869
+ setVisibleReasoning?: boolean;
4870
+ }>);
4863
4871
  }
4864
4872
 
4865
4873
  declare class AxRAG extends AxChainOfThought<{
@@ -4885,85 +4893,75 @@ declare class AxRAG extends AxChainOfThought<{
4885
4893
  }>;
4886
4894
  }
4887
4895
 
4888
- declare const AxStringUtil: {
4889
- trimNonAlphaNum: (str: string) => string;
4890
- splitIntoTwo: (str: string, separator: Readonly<RegExp | string>) => string[];
4891
- dedup: (seq: readonly string[]) => string[];
4892
- extractIdAndText: (input: string) => {
4893
- id: number;
4894
- text: string;
4895
- };
4896
- extractIndexPrefixedText: (input: string) => string;
4897
- batchArray: <T>(arr: readonly T[], size: number) => T[][];
4896
+ declare const axSpanAttributes: {
4897
+ LLM_SYSTEM: string;
4898
+ LLM_OPERATION_NAME: string;
4899
+ LLM_REQUEST_MODEL: string;
4900
+ LLM_REQUEST_MAX_TOKENS: string;
4901
+ LLM_REQUEST_TEMPERATURE: string;
4902
+ LLM_REQUEST_TOP_K: string;
4903
+ LLM_REQUEST_FREQUENCY_PENALTY: string;
4904
+ LLM_REQUEST_PRESENCE_PENALTY: string;
4905
+ LLM_REQUEST_STOP_SEQUENCES: string;
4906
+ LLM_REQUEST_LLM_IS_STREAMING: string;
4907
+ LLM_REQUEST_TOP_P: string;
4908
+ LLM_USAGE_INPUT_TOKENS: string;
4909
+ LLM_USAGE_OUTPUT_TOKENS: string;
4910
+ LLM_USAGE_TOTAL_TOKENS: string;
4911
+ LLM_USAGE_THOUGHTS_TOKENS: string;
4912
+ DB_SYSTEM: string;
4913
+ DB_TABLE: string;
4914
+ DB_NAMESPACE: string;
4915
+ DB_ID: string;
4916
+ DB_QUERY_TEXT: string;
4917
+ DB_VECTOR: string;
4918
+ DB_OPERATION_NAME: string;
4919
+ DB_VECTOR_QUERY_TOP_K: string;
4920
+ DB_QUERY_EMBEDDINGS: string;
4921
+ DB_QUERY_RESULT: string;
4922
+ DB_QUERY_EMBEDDINGS_VECTOR: string;
4923
+ DB_QUERY_RESULT_ID: string;
4924
+ DB_QUERY_RESULT_SCORE: string;
4925
+ DB_QUERY_RESULT_DISTANCE: string;
4926
+ DB_QUERY_RESULT_METADATA: string;
4927
+ DB_QUERY_RESULT_VECTOR: string;
4928
+ DB_QUERY_RESULT_DOCUMENT: string;
4898
4929
  };
4899
-
4900
- declare const axGlobals: {
4901
- signatureStrict: boolean;
4902
- tracer: Tracer | undefined;
4903
- meter: Meter | undefined;
4930
+ declare const axSpanEvents: {
4931
+ GEN_AI_USER_MESSAGE: string;
4932
+ GEN_AI_SYSTEM_MESSAGE: string;
4933
+ GEN_AI_ASSISTANT_MESSAGE: string;
4934
+ GEN_AI_TOOL_MESSAGE: string;
4935
+ GEN_AI_CHOICE: string;
4936
+ GEN_AI_USAGE: string;
4904
4937
  };
4905
-
4906
- declare const axModelInfoAnthropic: AxModelInfo[];
4907
-
4908
- declare const axModelInfoCohere: AxModelInfo[];
4909
-
4910
- declare const axModelInfoDeepSeek: AxModelInfo[];
4911
-
4912
- /**
4913
- * AxAIGoogleGemini: Model information
4914
- */
4915
- declare const axModelInfoGoogleGemini: AxModelInfo[];
4916
-
4917
- declare const axModelInfoGrok: AxModelInfo[];
4918
-
4919
- /**
4920
- * AxAIGroq: Model information
4921
- */
4922
- declare const axModelInfoGroq: AxModelInfo[];
4923
-
4924
- /**
4925
- * HuggingFace: Model information
4926
- */
4927
- declare const axModelInfoHuggingFace: AxModelInfo[];
4928
-
4929
- declare const axModelInfoMistral: AxModelInfo[];
4930
-
4931
- /**
4932
- * OpenAI: Model information
4933
- */
4934
- declare const axModelInfoReka: AxModelInfo[];
4935
-
4936
- declare const axModelInfoTogether: AxModelInfo[];
4937
-
4938
- interface AxAIMetricsInstruments {
4939
- latencyHistogram?: Histogram;
4940
- errorCounter?: Counter;
4941
- requestCounter?: Counter;
4942
- tokenCounter?: Counter;
4943
- inputTokenCounter?: Counter;
4944
- outputTokenCounter?: Counter;
4945
- errorRateGauge?: Gauge;
4946
- meanLatencyGauge?: Gauge;
4947
- p95LatencyGauge?: Gauge;
4948
- p99LatencyGauge?: Gauge;
4949
- streamingRequestsCounter?: Counter;
4950
- functionCallsCounter?: Counter;
4951
- functionCallLatencyHistogram?: Histogram;
4952
- requestSizeHistogram?: Histogram;
4953
- responseSizeHistogram?: Histogram;
4954
- temperatureGauge?: Gauge;
4955
- maxTokensGauge?: Gauge;
4956
- estimatedCostCounter?: Counter;
4957
- promptLengthHistogram?: Histogram;
4958
- contextWindowUsageGauge?: Gauge;
4959
- timeoutsCounter?: Counter;
4960
- abortsCounter?: Counter;
4961
- thinkingBudgetUsageCounter?: Counter;
4962
- multimodalRequestsCounter?: Counter;
4938
+ declare enum AxLLMRequestTypeValues {
4939
+ COMPLETION = "completion",
4940
+ CHAT = "chat",
4941
+ RERANK = "rerank",
4942
+ UNKNOWN = "unknown"
4943
+ }
4944
+ declare enum AxSpanKindValues {
4945
+ WORKFLOW = "workflow",
4946
+ TASK = "task",
4947
+ AGENT = "agent",
4948
+ TOOL = "tool",
4949
+ UNKNOWN = "unknown"
4963
4950
  }
4964
4951
 
4965
- interface AxSamplePickerOptions<OUT extends AxGenOut> {
4966
- resultPicker?: AxResultPickerFunction<OUT>;
4952
+ interface AxRateLimiterTokenUsageOptions {
4953
+ debug?: boolean;
4954
+ }
4955
+ declare class AxRateLimiterTokenUsage {
4956
+ private options?;
4957
+ private maxTokens;
4958
+ private refillRate;
4959
+ private currentTokens;
4960
+ private lastRefillTime;
4961
+ constructor(maxTokens: number, refillRate: number, options?: Readonly<AxRateLimiterTokenUsageOptions>);
4962
+ private refillTokens;
4963
+ private waitUntilTokensAvailable;
4964
+ acquire(tokens: number): Promise<void>;
4967
4965
  }
4968
4966
 
4969
- export { AxAI, AxAIAnthropic, type AxAIAnthropicArgs, type AxAIAnthropicChatError, type AxAIAnthropicChatRequest, type AxAIAnthropicChatRequestCacheParam, type AxAIAnthropicChatResponse, type AxAIAnthropicChatResponseDelta, type AxAIAnthropicConfig, type AxAIAnthropicContentBlockDeltaEvent, type AxAIAnthropicContentBlockStartEvent, type AxAIAnthropicContentBlockStopEvent, type AxAIAnthropicErrorEvent, type AxAIAnthropicMessageDeltaEvent, type AxAIAnthropicMessageStartEvent, type AxAIAnthropicMessageStopEvent, AxAIAnthropicModel, type AxAIAnthropicPingEvent, type AxAIAnthropicThinkingConfig, type AxAIAnthropicThinkingTokenBudgetLevels, AxAIAnthropicVertexModel, type AxAIArgs, AxAIAzureOpenAI, type AxAIAzureOpenAIArgs, type AxAIAzureOpenAIConfig, AxAICohere, type AxAICohereArgs, type AxAICohereChatRequest, type AxAICohereChatRequestToolResults, type AxAICohereChatResponse, type AxAICohereChatResponseDelta, type AxAICohereChatResponseToolCalls, type AxAICohereConfig, AxAICohereEmbedModel, type AxAICohereEmbedRequest, type AxAICohereEmbedResponse, AxAICohereModel, AxAIDeepSeek, type AxAIDeepSeekArgs, AxAIDeepSeekModel, type AxAIEmbedModels, type AxAIFeatures, AxAIGoogleGemini, type AxAIGoogleGeminiArgs, type AxAIGoogleGeminiBatchEmbedRequest, type AxAIGoogleGeminiBatchEmbedResponse, type AxAIGoogleGeminiChatRequest, type AxAIGoogleGeminiChatResponse, type AxAIGoogleGeminiChatResponseDelta, type AxAIGoogleGeminiConfig, type AxAIGoogleGeminiContent, type AxAIGoogleGeminiContentPart, AxAIGoogleGeminiEmbedModel, AxAIGoogleGeminiEmbedTypes, type AxAIGoogleGeminiGenerationConfig, AxAIGoogleGeminiModel, type AxAIGoogleGeminiOptionsTools, AxAIGoogleGeminiSafetyCategory, type AxAIGoogleGeminiSafetySettings, AxAIGoogleGeminiSafetyThreshold, type AxAIGoogleGeminiThinkingConfig, type AxAIGoogleGeminiThinkingTokenBudgetLevels, type AxAIGoogleGeminiTool, type AxAIGoogleGeminiToolConfig, type AxAIGoogleGeminiToolFunctionDeclaration, type AxAIGoogleGeminiToolGoogleSearchRetrieval, type AxAIGoogleVertexBatchEmbedRequest, type AxAIGoogleVertexBatchEmbedResponse, AxAIGrok, type AxAIGrokArgs, type AxAIGrokChatRequest, AxAIGrokEmbedModels, AxAIGrokModel, type AxAIGrokOptionsTools, type AxAIGrokSearchSource, AxAIGroq, type AxAIGroqArgs, AxAIGroqModel, AxAIHuggingFace, type AxAIHuggingFaceArgs, type AxAIHuggingFaceConfig, AxAIHuggingFaceModel, type AxAIHuggingFaceRequest, type AxAIHuggingFaceResponse, type AxAIInputModelList, type AxAIMemory, type AxAIMetricsInstruments, AxAIMistral, type AxAIMistralArgs, type AxAIMistralChatRequest, AxAIMistralEmbedModels, AxAIMistralModel, type AxAIModelList, type AxAIModelListBase, type AxAIModels, AxAIOllama, type AxAIOllamaAIConfig, type AxAIOllamaArgs, AxAIOpenAI, type AxAIOpenAIAnnotation, type AxAIOpenAIArgs, AxAIOpenAIBase, type AxAIOpenAIBaseArgs, type AxAIOpenAIChatRequest, type AxAIOpenAIChatResponse, type AxAIOpenAIChatResponseDelta, type AxAIOpenAIConfig, AxAIOpenAIEmbedModel, type AxAIOpenAIEmbedRequest, type AxAIOpenAIEmbedResponse, type AxAIOpenAILogprob, AxAIOpenAIModel, type AxAIOpenAIResponseDelta, AxAIOpenAIResponses, type AxAIOpenAIResponsesArgs, AxAIOpenAIResponsesBase, type AxAIOpenAIResponsesCodeInterpreterToolCall, type AxAIOpenAIResponsesComputerToolCall, type AxAIOpenAIResponsesConfig, type AxAIOpenAIResponsesContentPartAddedEvent, type AxAIOpenAIResponsesContentPartDoneEvent, type AxAIOpenAIResponsesDefineFunctionTool, type AxAIOpenAIResponsesErrorEvent, type AxAIOpenAIResponsesFileSearchCallCompletedEvent, type AxAIOpenAIResponsesFileSearchCallInProgressEvent, type AxAIOpenAIResponsesFileSearchCallSearchingEvent, type AxAIOpenAIResponsesFileSearchToolCall, type AxAIOpenAIResponsesFunctionCallArgumentsDeltaEvent, type AxAIOpenAIResponsesFunctionCallArgumentsDoneEvent, type AxAIOpenAIResponsesFunctionCallItem, type AxAIOpenAIResponsesImageGenerationCallCompletedEvent, type AxAIOpenAIResponsesImageGenerationCallGeneratingEvent, type AxAIOpenAIResponsesImageGenerationCallInProgressEvent, type AxAIOpenAIResponsesImageGenerationCallPartialImageEvent, type AxAIOpenAIResponsesImageGenerationToolCall, AxAIOpenAIResponsesImpl, type AxAIOpenAIResponsesInputAudioContentPart, type AxAIOpenAIResponsesInputContentPart, type AxAIOpenAIResponsesInputFunctionCallItem, type AxAIOpenAIResponsesInputFunctionCallOutputItem, type AxAIOpenAIResponsesInputImageUrlContentPart, type AxAIOpenAIResponsesInputItem, type AxAIOpenAIResponsesInputMessageItem, type AxAIOpenAIResponsesInputTextContentPart, type AxAIOpenAIResponsesLocalShellToolCall, type AxAIOpenAIResponsesMCPCallArgumentsDeltaEvent, type AxAIOpenAIResponsesMCPCallArgumentsDoneEvent, type AxAIOpenAIResponsesMCPCallCompletedEvent, type AxAIOpenAIResponsesMCPCallFailedEvent, type AxAIOpenAIResponsesMCPCallInProgressEvent, type AxAIOpenAIResponsesMCPListToolsCompletedEvent, type AxAIOpenAIResponsesMCPListToolsFailedEvent, type AxAIOpenAIResponsesMCPListToolsInProgressEvent, type AxAIOpenAIResponsesMCPToolCall, AxAIOpenAIResponsesModel, type AxAIOpenAIResponsesOutputItem, type AxAIOpenAIResponsesOutputItemAddedEvent, type AxAIOpenAIResponsesOutputItemDoneEvent, type AxAIOpenAIResponsesOutputMessageItem, type AxAIOpenAIResponsesOutputRefusalContentPart, type AxAIOpenAIResponsesOutputTextAnnotationAddedEvent, type AxAIOpenAIResponsesOutputTextContentPart, type AxAIOpenAIResponsesOutputTextDeltaEvent, type AxAIOpenAIResponsesOutputTextDoneEvent, type AxAIOpenAIResponsesReasoningDeltaEvent, type AxAIOpenAIResponsesReasoningDoneEvent, type AxAIOpenAIResponsesReasoningItem, type AxAIOpenAIResponsesReasoningSummaryDeltaEvent, type AxAIOpenAIResponsesReasoningSummaryDoneEvent, type AxAIOpenAIResponsesReasoningSummaryPart, type AxAIOpenAIResponsesReasoningSummaryPartAddedEvent, type AxAIOpenAIResponsesReasoningSummaryPartDoneEvent, type AxAIOpenAIResponsesReasoningSummaryTextDeltaEvent, type AxAIOpenAIResponsesReasoningSummaryTextDoneEvent, type AxAIOpenAIResponsesRefusalDeltaEvent, type AxAIOpenAIResponsesRefusalDoneEvent, type AxAIOpenAIResponsesRequest, type AxAIOpenAIResponsesResponse, type AxAIOpenAIResponsesResponseCompletedEvent, type AxAIOpenAIResponsesResponseCreatedEvent, type AxAIOpenAIResponsesResponseDelta, type AxAIOpenAIResponsesResponseFailedEvent, type AxAIOpenAIResponsesResponseInProgressEvent, type AxAIOpenAIResponsesResponseIncompleteEvent, type AxAIOpenAIResponsesResponseQueuedEvent, type AxAIOpenAIResponsesStreamEvent, type AxAIOpenAIResponsesStreamEventBase, type AxAIOpenAIResponsesToolCall, type AxAIOpenAIResponsesToolCallBase, type AxAIOpenAIResponsesToolChoice, type AxAIOpenAIResponsesToolDefinition, type AxAIOpenAIResponsesWebSearchCallCompletedEvent, type AxAIOpenAIResponsesWebSearchCallInProgressEvent, type AxAIOpenAIResponsesWebSearchCallSearchingEvent, type AxAIOpenAIResponsesWebSearchToolCall, type AxAIOpenAIUrlCitation, type AxAIOpenAIUsage, type AxAIPromptConfig, AxAIRefusalError, AxAIReka, type AxAIRekaArgs, type AxAIRekaChatRequest, type AxAIRekaChatResponse, type AxAIRekaChatResponseDelta, type AxAIRekaConfig, AxAIRekaModel, type AxAIRekaUsage, type AxAIService, AxAIServiceAbortedError, type AxAIServiceActionOptions, AxAIServiceAuthenticationError, AxAIServiceError, type AxAIServiceImpl, type AxAIServiceMetrics, AxAIServiceNetworkError, type AxAIServiceOptions, AxAIServiceResponseError, AxAIServiceStatusError, AxAIServiceStreamTerminatedError, AxAIServiceTimeoutError, AxAITogether, type AxAITogetherArgs, type AxAPI, type AxAPIConfig, AxAgent, type AxAgentFeatures, type AxAgentOptions, type AxAgentic, AxApacheTika, type AxApacheTikaArgs, type AxApacheTikaConvertOptions, type AxAssertion, AxAssertionError, AxBalancer, type AxBalancerOptions, AxBaseAI, type AxBaseAIArgs, AxBaseOptimizer, type AxBootstrapCompileOptions, AxBootstrapFewShot, type AxBootstrapOptimizerOptions, AxChainOfThought, type AxChatRequest, type AxChatResponse, type AxChatResponseFunctionCall, type AxChatResponseResult, type AxCheckpointLoadFn, type AxCheckpointSaveFn, type AxCompileOptions, type AxCostTracker, type AxCostTrackerOptions, AxDB, type AxDBArgs, AxDBBase, type AxDBBaseArgs, type AxDBBaseOpOptions, AxDBCloudflare, type AxDBCloudflareArgs, type AxDBCloudflareOpOptions, type AxDBLoaderOptions, AxDBManager, type AxDBManagerArgs, type AxDBMatch, AxDBMemory, type AxDBMemoryArgs, type AxDBMemoryOpOptions, AxDBPinecone, type AxDBPineconeArgs, type AxDBPineconeOpOptions, type AxDBQueryRequest, type AxDBQueryResponse, type AxDBQueryService, type AxDBService, type AxDBState, type AxDBUpsertRequest, type AxDBUpsertResponse, AxDBWeaviate, type AxDBWeaviateArgs, type AxDBWeaviateOpOptions, type AxDataRow, AxDefaultCostTracker, AxDefaultResultReranker, type AxDockerContainer, AxDockerSession, type AxEmbedRequest, type AxEmbedResponse, AxEmbeddingAdapter, type AxErrorCategory, AxEvalUtil, type AxEvaluateArgs, type AxExample, type AxField, type AxFieldDescriptor, type AxFieldProcessor, type AxFieldProcessorProcess, type AxFieldTemplateFn, type AxFieldType, type AxFieldValue, AxFlow, AxFlowTypedSubContextImpl, type AxFunction, AxFunctionError, type AxFunctionHandler, type AxFunctionJSONSchema, AxFunctionProcessor, type AxFunctionResult, AxGen, type AxGenDeltaOut, type AxGenIn, type AxGenMetricsInstruments, type AxGenOut, type AxGenStreamingOut, AxGenerateError, type AxGenerateErrorDetails, type AxGenerateResult, AxHFDataLoader, type AxIField, type AxInputFunctionType, AxInstanceRegistry, type AxInternalChatRequest, type AxInternalEmbedRequest, AxJSInterpreter, AxJSInterpreterPermission, AxLLMRequestTypeValues, type AxLoggerFunction, type AxLoggerTag, AxMCPClient, AxMCPHTTPSSETransport, AxMCPStdioTransport, type AxMCPStreamableHTTPTransportOptions, AxMCPStreambleHTTPTransport, type AxMCPTransport, AxMemory, type AxMemoryData, type AxMessage, type AxMetricFn, type AxMetricFnArgs, type AxMetricsConfig, AxMiPRO, type AxMiPROCompileOptions, type AxMiPROOptimizerOptions, type AxMiPROResult, AxMockAIService, type AxMockAIServiceConfig, type AxModelConfig, type AxModelInfo, type AxModelInfoWithProvider, type AxModelUsage, type AxMultiMetricFn, AxMultiServiceRouter, type AxOptimizationCheckpoint, type AxOptimizationProgress, type AxOptimizationStats, type AxOptimizer, type AxOptimizerArgs, type AxOptimizerMetricsConfig, type AxOptimizerMetricsInstruments, type AxOptimizerResult, type AxParetoResult, AxProgram, type AxProgramDemos, type AxProgramExamples, type AxProgramForwardOptions, type AxProgramOptions, type AxProgramStreamingForwardOptions, type AxProgramTrace, type AxProgramUsage, AxPromptTemplate, type AxPromptTemplateOptions, AxRAG, type AxRateLimiterFunction, AxRateLimiterTokenUsage, type AxRateLimiterTokenUsageOptions, type AxRerankerIn, type AxRerankerOut, type AxResponseHandlerArgs, type AxResultPickerFunction, type AxResultPickerFunctionFieldResults, type AxResultPickerFunctionFunctionResults, type AxRewriteIn, type AxRewriteOut, type AxSamplePickerOptions, type AxSetExamplesOptions, AxSignature, type AxSignatureConfig, type AxSignatureTemplateValue, AxSimpleClassifier, AxSimpleClassifierClass, type AxSimpleClassifierForwardOptions, AxSpanKindValues, type AxStreamingAssertion, type AxStreamingEvent, type AxStreamingFieldProcessorProcess, AxStringUtil, AxTestPrompt, type AxTokenUsage, type AxTunable, type AxUsable, ax, axAIAnthropicDefaultConfig, axAIAnthropicVertexDefaultConfig, axAIAzureOpenAIBestConfig, axAIAzureOpenAICreativeConfig, axAIAzureOpenAIDefaultConfig, axAIAzureOpenAIFastConfig, axAICohereCreativeConfig, axAICohereDefaultConfig, axAIDeepSeekCodeConfig, axAIDeepSeekDefaultConfig, axAIGoogleGeminiDefaultConfig, axAIGoogleGeminiDefaultCreativeConfig, axAIGrokBestConfig, axAIGrokDefaultConfig, axAIHuggingFaceCreativeConfig, axAIHuggingFaceDefaultConfig, axAIMistralBestConfig, axAIMistralDefaultConfig, axAIOllamaDefaultConfig, axAIOllamaDefaultCreativeConfig, axAIOpenAIBestConfig, axAIOpenAICreativeConfig, axAIOpenAIDefaultConfig, axAIOpenAIFastConfig, axAIOpenAIResponsesBestConfig, axAIOpenAIResponsesCreativeConfig, axAIOpenAIResponsesDefaultConfig, axAIRekaBestConfig, axAIRekaCreativeConfig, axAIRekaDefaultConfig, axAIRekaFastConfig, axAITogetherDefaultConfig, axBaseAIDefaultConfig, axBaseAIDefaultCreativeConfig, axCheckMetricsHealth, axCreateDefaultLogger, axCreateDefaultTextLogger, axCreateOptimizerLogger, axDefaultMetricsConfig, axDefaultOptimizerLogger, axDefaultOptimizerMetricsConfig, axGetMetricsConfig, axGetOptimizerMetricsConfig, axGlobals, axModelInfoAnthropic, axModelInfoCohere, axModelInfoDeepSeek, axModelInfoGoogleGemini, axModelInfoGrok, axModelInfoGroq, axModelInfoHuggingFace, axModelInfoMistral, axModelInfoOpenAI, axModelInfoOpenAIResponses, axModelInfoReka, axModelInfoTogether, axSpanAttributes, axSpanEvents, axUpdateMetricsConfig, axUpdateOptimizerMetricsConfig, axValidateChatRequestMessage, axValidateChatResponseResult, f, s };
4967
+ export { AxAI, AxAIAnthropic, type AxAIAnthropicArgs, type AxAIAnthropicChatError, type AxAIAnthropicChatRequest, type AxAIAnthropicChatRequestCacheParam, type AxAIAnthropicChatResponse, type AxAIAnthropicChatResponseDelta, type AxAIAnthropicConfig, type AxAIAnthropicContentBlockDeltaEvent, type AxAIAnthropicContentBlockStartEvent, type AxAIAnthropicContentBlockStopEvent, type AxAIAnthropicErrorEvent, type AxAIAnthropicMessageDeltaEvent, type AxAIAnthropicMessageStartEvent, type AxAIAnthropicMessageStopEvent, AxAIAnthropicModel, type AxAIAnthropicPingEvent, type AxAIAnthropicThinkingConfig, type AxAIAnthropicThinkingTokenBudgetLevels, AxAIAnthropicVertexModel, type AxAIArgs, AxAIAzureOpenAI, type AxAIAzureOpenAIArgs, type AxAIAzureOpenAIConfig, AxAICohere, type AxAICohereArgs, type AxAICohereChatRequest, type AxAICohereChatRequestToolResults, type AxAICohereChatResponse, type AxAICohereChatResponseDelta, type AxAICohereChatResponseToolCalls, type AxAICohereConfig, AxAICohereEmbedModel, type AxAICohereEmbedRequest, type AxAICohereEmbedResponse, AxAICohereModel, AxAIDeepSeek, type AxAIDeepSeekArgs, AxAIDeepSeekModel, type AxAIEmbedModels, type AxAIFeatures, AxAIGoogleGemini, type AxAIGoogleGeminiArgs, type AxAIGoogleGeminiBatchEmbedRequest, type AxAIGoogleGeminiBatchEmbedResponse, type AxAIGoogleGeminiChatRequest, type AxAIGoogleGeminiChatResponse, type AxAIGoogleGeminiChatResponseDelta, type AxAIGoogleGeminiConfig, type AxAIGoogleGeminiContent, type AxAIGoogleGeminiContentPart, AxAIGoogleGeminiEmbedModel, AxAIGoogleGeminiEmbedTypes, type AxAIGoogleGeminiGenerationConfig, AxAIGoogleGeminiModel, type AxAIGoogleGeminiOptionsTools, AxAIGoogleGeminiSafetyCategory, type AxAIGoogleGeminiSafetySettings, AxAIGoogleGeminiSafetyThreshold, type AxAIGoogleGeminiThinkingConfig, type AxAIGoogleGeminiThinkingTokenBudgetLevels, type AxAIGoogleGeminiTool, type AxAIGoogleGeminiToolConfig, type AxAIGoogleGeminiToolFunctionDeclaration, type AxAIGoogleGeminiToolGoogleSearchRetrieval, type AxAIGoogleVertexBatchEmbedRequest, type AxAIGoogleVertexBatchEmbedResponse, AxAIGrok, type AxAIGrokArgs, type AxAIGrokChatRequest, AxAIGrokEmbedModels, AxAIGrokModel, type AxAIGrokOptionsTools, type AxAIGrokSearchSource, AxAIGroq, type AxAIGroqArgs, AxAIGroqModel, AxAIHuggingFace, type AxAIHuggingFaceArgs, type AxAIHuggingFaceConfig, AxAIHuggingFaceModel, type AxAIHuggingFaceRequest, type AxAIHuggingFaceResponse, type AxAIInputModelList, type AxAIMemory, type AxAIMetricsInstruments, AxAIMistral, type AxAIMistralArgs, type AxAIMistralChatRequest, AxAIMistralEmbedModels, AxAIMistralModel, type AxAIModelList, type AxAIModelListBase, type AxAIModels, AxAIOllama, type AxAIOllamaAIConfig, type AxAIOllamaArgs, AxAIOpenAI, type AxAIOpenAIAnnotation, type AxAIOpenAIArgs, AxAIOpenAIBase, type AxAIOpenAIBaseArgs, type AxAIOpenAIChatRequest, type AxAIOpenAIChatResponse, type AxAIOpenAIChatResponseDelta, type AxAIOpenAIConfig, AxAIOpenAIEmbedModel, type AxAIOpenAIEmbedRequest, type AxAIOpenAIEmbedResponse, type AxAIOpenAILogprob, AxAIOpenAIModel, type AxAIOpenAIResponseDelta, AxAIOpenAIResponses, type AxAIOpenAIResponsesArgs, AxAIOpenAIResponsesBase, type AxAIOpenAIResponsesCodeInterpreterToolCall, type AxAIOpenAIResponsesComputerToolCall, type AxAIOpenAIResponsesConfig, type AxAIOpenAIResponsesContentPartAddedEvent, type AxAIOpenAIResponsesContentPartDoneEvent, type AxAIOpenAIResponsesDefineFunctionTool, type AxAIOpenAIResponsesErrorEvent, type AxAIOpenAIResponsesFileSearchCallCompletedEvent, type AxAIOpenAIResponsesFileSearchCallInProgressEvent, type AxAIOpenAIResponsesFileSearchCallSearchingEvent, type AxAIOpenAIResponsesFileSearchToolCall, type AxAIOpenAIResponsesFunctionCallArgumentsDeltaEvent, type AxAIOpenAIResponsesFunctionCallArgumentsDoneEvent, type AxAIOpenAIResponsesFunctionCallItem, type AxAIOpenAIResponsesImageGenerationCallCompletedEvent, type AxAIOpenAIResponsesImageGenerationCallGeneratingEvent, type AxAIOpenAIResponsesImageGenerationCallInProgressEvent, type AxAIOpenAIResponsesImageGenerationCallPartialImageEvent, type AxAIOpenAIResponsesImageGenerationToolCall, AxAIOpenAIResponsesImpl, type AxAIOpenAIResponsesInputAudioContentPart, type AxAIOpenAIResponsesInputContentPart, type AxAIOpenAIResponsesInputFunctionCallItem, type AxAIOpenAIResponsesInputFunctionCallOutputItem, type AxAIOpenAIResponsesInputImageUrlContentPart, type AxAIOpenAIResponsesInputItem, type AxAIOpenAIResponsesInputMessageItem, type AxAIOpenAIResponsesInputTextContentPart, type AxAIOpenAIResponsesLocalShellToolCall, type AxAIOpenAIResponsesMCPCallArgumentsDeltaEvent, type AxAIOpenAIResponsesMCPCallArgumentsDoneEvent, type AxAIOpenAIResponsesMCPCallCompletedEvent, type AxAIOpenAIResponsesMCPCallFailedEvent, type AxAIOpenAIResponsesMCPCallInProgressEvent, type AxAIOpenAIResponsesMCPListToolsCompletedEvent, type AxAIOpenAIResponsesMCPListToolsFailedEvent, type AxAIOpenAIResponsesMCPListToolsInProgressEvent, type AxAIOpenAIResponsesMCPToolCall, AxAIOpenAIResponsesModel, type AxAIOpenAIResponsesOutputItem, type AxAIOpenAIResponsesOutputItemAddedEvent, type AxAIOpenAIResponsesOutputItemDoneEvent, type AxAIOpenAIResponsesOutputMessageItem, type AxAIOpenAIResponsesOutputRefusalContentPart, type AxAIOpenAIResponsesOutputTextAnnotationAddedEvent, type AxAIOpenAIResponsesOutputTextContentPart, type AxAIOpenAIResponsesOutputTextDeltaEvent, type AxAIOpenAIResponsesOutputTextDoneEvent, type AxAIOpenAIResponsesReasoningDeltaEvent, type AxAIOpenAIResponsesReasoningDoneEvent, type AxAIOpenAIResponsesReasoningItem, type AxAIOpenAIResponsesReasoningSummaryDeltaEvent, type AxAIOpenAIResponsesReasoningSummaryDoneEvent, type AxAIOpenAIResponsesReasoningSummaryPart, type AxAIOpenAIResponsesReasoningSummaryPartAddedEvent, type AxAIOpenAIResponsesReasoningSummaryPartDoneEvent, type AxAIOpenAIResponsesReasoningSummaryTextDeltaEvent, type AxAIOpenAIResponsesReasoningSummaryTextDoneEvent, type AxAIOpenAIResponsesRefusalDeltaEvent, type AxAIOpenAIResponsesRefusalDoneEvent, type AxAIOpenAIResponsesRequest, type AxAIOpenAIResponsesResponse, type AxAIOpenAIResponsesResponseCompletedEvent, type AxAIOpenAIResponsesResponseCreatedEvent, type AxAIOpenAIResponsesResponseDelta, type AxAIOpenAIResponsesResponseFailedEvent, type AxAIOpenAIResponsesResponseInProgressEvent, type AxAIOpenAIResponsesResponseIncompleteEvent, type AxAIOpenAIResponsesResponseQueuedEvent, type AxAIOpenAIResponsesStreamEvent, type AxAIOpenAIResponsesStreamEventBase, type AxAIOpenAIResponsesToolCall, type AxAIOpenAIResponsesToolCallBase, type AxAIOpenAIResponsesToolChoice, type AxAIOpenAIResponsesToolDefinition, type AxAIOpenAIResponsesWebSearchCallCompletedEvent, type AxAIOpenAIResponsesWebSearchCallInProgressEvent, type AxAIOpenAIResponsesWebSearchCallSearchingEvent, type AxAIOpenAIResponsesWebSearchToolCall, type AxAIOpenAIUrlCitation, type AxAIOpenAIUsage, type AxAIPromptConfig, AxAIRefusalError, AxAIReka, type AxAIRekaArgs, type AxAIRekaChatRequest, type AxAIRekaChatResponse, type AxAIRekaChatResponseDelta, type AxAIRekaConfig, AxAIRekaModel, type AxAIRekaUsage, type AxAIService, AxAIServiceAbortedError, type AxAIServiceActionOptions, AxAIServiceAuthenticationError, AxAIServiceError, type AxAIServiceImpl, type AxAIServiceMetrics, AxAIServiceNetworkError, type AxAIServiceOptions, AxAIServiceResponseError, AxAIServiceStatusError, AxAIServiceStreamTerminatedError, AxAIServiceTimeoutError, AxAITogether, type AxAITogetherArgs, type AxAPI, type AxAPIConfig, AxAgent, type AxAgentFeatures, type AxAgentOptions, type AxAgentic, AxApacheTika, type AxApacheTikaArgs, type AxApacheTikaConvertOptions, type AxAssertion, AxAssertionError, AxBalancer, type AxBalancerOptions, AxBaseAI, type AxBaseAIArgs, AxBaseOptimizer, type AxBootstrapCompileOptions, AxBootstrapFewShot, type AxBootstrapOptimizerOptions, AxChainOfThought, type AxChatRequest, type AxChatResponse, type AxChatResponseFunctionCall, type AxChatResponseResult, type AxCheckpointLoadFn, type AxCheckpointSaveFn, type AxCompileOptions, type AxCostTracker, type AxCostTrackerOptions, AxDB, type AxDBArgs, AxDBBase, type AxDBBaseArgs, type AxDBBaseOpOptions, AxDBCloudflare, type AxDBCloudflareArgs, type AxDBCloudflareOpOptions, type AxDBLoaderOptions, AxDBManager, type AxDBManagerArgs, type AxDBMatch, AxDBMemory, type AxDBMemoryArgs, type AxDBMemoryOpOptions, AxDBPinecone, type AxDBPineconeArgs, type AxDBPineconeOpOptions, type AxDBQueryRequest, type AxDBQueryResponse, type AxDBQueryService, type AxDBService, type AxDBState, type AxDBUpsertRequest, type AxDBUpsertResponse, AxDBWeaviate, type AxDBWeaviateArgs, type AxDBWeaviateOpOptions, type AxDataRow, AxDefaultCostTracker, AxDefaultResultReranker, type AxDockerContainer, AxDockerSession, type AxEmbedRequest, type AxEmbedResponse, AxEmbeddingAdapter, type AxErrorCategory, AxEvalUtil, type AxEvaluateArgs, type AxExample, type AxField, type AxFieldDescriptor, type AxFieldProcessor, type AxFieldProcessorProcess, type AxFieldTemplateFn, type AxFieldType, type AxFieldValue, AxFlow, AxFlowTypedSubContextImpl, type AxFunction, AxFunctionError, type AxFunctionHandler, type AxFunctionJSONSchema, AxFunctionProcessor, type AxFunctionResult, type AxFunctionResultFormatter, AxGen, type AxGenDeltaOut, type AxGenIn, type AxGenMetricsInstruments, type AxGenOut, type AxGenStreamingOut, AxGenerateError, type AxGenerateErrorDetails, type AxGenerateResult, AxHFDataLoader, type AxIField, type AxInputFunctionType, AxInstanceRegistry, type AxInternalChatRequest, type AxInternalEmbedRequest, AxLLMRequestTypeValues, type AxLoggerFunction, type AxLoggerTag, AxMCPClient, AxMCPHTTPSSETransport, AxMCPStdioTransport, type AxMCPStreamableHTTPTransportOptions, AxMCPStreambleHTTPTransport, type AxMCPTransport, AxMemory, type AxMemoryData, type AxMessage, type AxMetricFn, type AxMetricFnArgs, type AxMetricsConfig, AxMiPRO, type AxMiPROCompileOptions, type AxMiPROOptimizerOptions, type AxMiPROResult, AxMockAIService, type AxMockAIServiceConfig, type AxModelConfig, type AxModelInfo, type AxModelInfoWithProvider, type AxModelUsage, type AxMultiMetricFn, AxMultiServiceRouter, type AxOptimizationCheckpoint, type AxOptimizationProgress, type AxOptimizationStats, type AxOptimizer, type AxOptimizerArgs, type AxOptimizerMetricsConfig, type AxOptimizerMetricsInstruments, type AxOptimizerResult, type AxParetoResult, AxProgram, type AxProgramDemos, type AxProgramExamples, type AxProgramForwardOptions, type AxProgramOptions, type AxProgramStreamingForwardOptions, type AxProgramTrace, type AxProgramUsage, AxPromptTemplate, type AxPromptTemplateOptions, AxRAG, type AxRateLimiterFunction, AxRateLimiterTokenUsage, type AxRateLimiterTokenUsageOptions, type AxRerankerIn, type AxRerankerOut, type AxResponseHandlerArgs, type AxResultPickerFunction, type AxResultPickerFunctionFieldResults, type AxResultPickerFunctionFunctionResults, type AxRewriteIn, type AxRewriteOut, type AxSamplePickerOptions, type AxSetExamplesOptions, AxSignature, type AxSignatureConfig, type AxSignatureTemplateValue, AxSimpleClassifier, AxSimpleClassifierClass, type AxSimpleClassifierForwardOptions, AxSpanKindValues, type AxStreamingAssertion, type AxStreamingEvent, type AxStreamingFieldProcessorProcess, AxStringUtil, AxTestPrompt, type AxTokenUsage, type AxTunable, type AxUsable, ax, axAIAnthropicDefaultConfig, axAIAnthropicVertexDefaultConfig, axAIAzureOpenAIBestConfig, axAIAzureOpenAICreativeConfig, axAIAzureOpenAIDefaultConfig, axAIAzureOpenAIFastConfig, axAICohereCreativeConfig, axAICohereDefaultConfig, axAIDeepSeekCodeConfig, axAIDeepSeekDefaultConfig, axAIGoogleGeminiDefaultConfig, axAIGoogleGeminiDefaultCreativeConfig, axAIGrokBestConfig, axAIGrokDefaultConfig, axAIHuggingFaceCreativeConfig, axAIHuggingFaceDefaultConfig, axAIMistralBestConfig, axAIMistralDefaultConfig, axAIOllamaDefaultConfig, axAIOllamaDefaultCreativeConfig, axAIOpenAIBestConfig, axAIOpenAICreativeConfig, axAIOpenAIDefaultConfig, axAIOpenAIFastConfig, axAIOpenAIResponsesBestConfig, axAIOpenAIResponsesCreativeConfig, axAIOpenAIResponsesDefaultConfig, axAIRekaBestConfig, axAIRekaCreativeConfig, axAIRekaDefaultConfig, axAIRekaFastConfig, axAITogetherDefaultConfig, axBaseAIDefaultConfig, axBaseAIDefaultCreativeConfig, axCheckMetricsHealth, axCreateDefaultColorLogger, axCreateDefaultTextLogger, axCreateOptimizerLogger, axDefaultMetricsConfig, axDefaultOptimizerLogger, axDefaultOptimizerMetricsConfig, axGetMetricsConfig, axGetOptimizerMetricsConfig, axGlobals, axModelInfoAnthropic, axModelInfoCohere, axModelInfoDeepSeek, axModelInfoGoogleGemini, axModelInfoGrok, axModelInfoGroq, axModelInfoHuggingFace, axModelInfoMistral, axModelInfoOpenAI, axModelInfoOpenAIResponses, axModelInfoReka, axModelInfoTogether, axSpanAttributes, axSpanEvents, axUpdateMetricsConfig, axUpdateOptimizerMetricsConfig, axValidateChatRequestMessage, axValidateChatResponseResult, f, s };