@ax-llm/ax 12.0.24 → 13.0.2

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 +13759 -13694
  2. package/index.cjs.map +1 -1
  3. package/index.d.cts +1750 -1756
  4. package/index.d.ts +1750 -1756
  5. package/index.js +13646 -13587
  6. package/index.js.map +1 -1
  7. package/package.json +1 -2
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' | 'firstFunction' | 'multipleFunctions' | 'responseStart' | 'responseContent' | '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' | 'functionEnd' | '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;
@@ -422,21 +328,113 @@ interface AxAIService<TModel = unknown, TEmbedModel = unknown> {
422
328
  getLastUsedChatModel(): TModel | undefined;
423
329
  getLastUsedEmbedModel(): TEmbedModel | undefined;
424
330
  getLastUsedModelConfig(): AxModelConfig | undefined;
425
- chat(req: Readonly<AxChatRequest<TModel>>, options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions<TModel, TEmbedModel>>): Promise<AxChatResponse | ReadableStream$1<AxChatResponse>>;
331
+ chat(req: Readonly<AxChatRequest<TModel>>, options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions<TModel, TEmbedModel>>): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
426
332
  embed(req: Readonly<AxEmbedRequest<TEmbedModel>>, options?: Readonly<AxAIServiceActionOptions<TModel, TEmbedModel>>): Promise<AxEmbedResponse>;
427
333
  setOptions(options: Readonly<AxAIServiceOptions>): void;
428
334
  getOptions(): Readonly<AxAIServiceOptions>;
429
335
  }
430
336
  interface AxAIServiceImpl<TModel, TEmbedModel, TChatRequest, TEmbedRequest, TChatResponse, TChatResponseDelta, TEmbedResponse> {
431
- createChatReq(req: Readonly<AxInternalChatRequest<TModel>>, config: Readonly<AxAIPromptConfig>): [AxAPI, TChatRequest];
337
+ createChatReq(req: Readonly<AxInternalChatRequest<TModel>>, config: Readonly<AxAIPromptConfig>): Promise<[AxAPI, TChatRequest]> | [AxAPI, TChatRequest];
432
338
  createChatResp(resp: Readonly<TChatResponse>): AxChatResponse;
433
339
  createChatStreamResp?(resp: Readonly<TChatResponseDelta>, state: object): AxChatResponse;
434
- createEmbedReq?(req: Readonly<AxInternalEmbedRequest<TEmbedModel>>): [AxAPI, TEmbedRequest];
340
+ createEmbedReq?(req: Readonly<AxInternalEmbedRequest<TEmbedModel>>): Promise<[AxAPI, TEmbedRequest]> | [AxAPI, TEmbedRequest];
435
341
  createEmbedResp?(resp: Readonly<TEmbedResponse>): AxEmbedResponse;
436
342
  getModelConfig(): AxModelConfig;
437
343
  getTokenUsage(): AxTokenUsage | undefined;
438
344
  }
439
345
 
346
+ interface AxAIFeatures {
347
+ functions: boolean;
348
+ streaming: boolean;
349
+ functionCot?: boolean;
350
+ hasThinkingBudget?: boolean;
351
+ hasShowThoughts?: boolean;
352
+ }
353
+ interface AxBaseAIArgs<TModel, TEmbedModel> {
354
+ name: string;
355
+ apiURL: string;
356
+ headers: () => Promise<Record<string, string>>;
357
+ modelInfo: Readonly<AxModelInfo[]>;
358
+ defaults: Readonly<{
359
+ model: TModel;
360
+ embedModel?: TEmbedModel;
361
+ }>;
362
+ options?: Readonly<AxAIServiceOptions>;
363
+ supportFor: AxAIFeatures | ((model: TModel) => AxAIFeatures);
364
+ models?: AxAIInputModelList<TModel, TEmbedModel>;
365
+ }
366
+ declare const axBaseAIDefaultConfig: () => AxModelConfig;
367
+ declare const axBaseAIDefaultCreativeConfig: () => AxModelConfig;
368
+ declare class AxBaseAI<TModel, TEmbedModel, TChatRequest, TEmbedRequest, TChatResponse, TChatResponseDelta, TEmbedResponse> implements AxAIService<TModel, TEmbedModel> {
369
+ private readonly aiImpl;
370
+ private debug;
371
+ private rt?;
372
+ private fetch?;
373
+ private tracer?;
374
+ private meter?;
375
+ private timeout?;
376
+ private excludeContentFromTrace?;
377
+ private models?;
378
+ private abortSignal?;
379
+ private logger;
380
+ private modelInfo;
381
+ private modelUsage?;
382
+ private embedModelUsage?;
383
+ private defaults;
384
+ private lastUsedModelConfig?;
385
+ private lastUsedChatModel?;
386
+ private lastUsedEmbedModel?;
387
+ protected apiURL: string;
388
+ protected name: string;
389
+ protected id: string;
390
+ protected headers: () => Promise<Record<string, string>>;
391
+ protected supportFor: AxAIFeatures | ((model: TModel) => AxAIFeatures);
392
+ private metrics;
393
+ constructor(aiImpl: Readonly<AxAIServiceImpl<TModel, TEmbedModel, TChatRequest, TEmbedRequest, TChatResponse, TChatResponseDelta, TEmbedResponse>>, { name, apiURL, headers, modelInfo, defaults, options, supportFor, models, }: Readonly<AxBaseAIArgs<TModel, TEmbedModel>>);
394
+ private getMetricsInstruments;
395
+ setName(name: string): void;
396
+ getId(): string;
397
+ setAPIURL(apiURL: string): void;
398
+ setHeaders(headers: () => Promise<Record<string, string>>): void;
399
+ setOptions(options: Readonly<AxAIServiceOptions>): void;
400
+ getOptions(): Readonly<AxAIServiceOptions>;
401
+ getLogger(): AxLoggerFunction;
402
+ getModelList(): AxAIModelList | undefined;
403
+ getName(): string;
404
+ getFeatures(model?: TModel): AxAIFeatures;
405
+ getLastUsedChatModel(): TModel | undefined;
406
+ getLastUsedEmbedModel(): TEmbedModel | undefined;
407
+ getLastUsedModelConfig(): AxModelConfig | undefined;
408
+ private calculatePercentile;
409
+ private updateLatencyMetrics;
410
+ private updateErrorMetrics;
411
+ private recordTokenUsage;
412
+ private calculateRequestSize;
413
+ private calculateResponseSize;
414
+ private detectMultimodalContent;
415
+ private calculatePromptLength;
416
+ private calculateContextWindowUsage;
417
+ private estimateCost;
418
+ private estimateCostByName;
419
+ private recordFunctionCallMetrics;
420
+ private recordTimeoutMetric;
421
+ private recordAbortMetric;
422
+ private recordChatMetrics;
423
+ private recordEmbedMetrics;
424
+ getMetrics(): AxAIServiceMetrics;
425
+ chat(req: Readonly<AxChatRequest<TModel>>, options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions<TModel, TEmbedModel>>): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
426
+ private _chat1;
427
+ private cleanupFunctionSchema;
428
+ private _chat2;
429
+ embed(req: Readonly<AxEmbedRequest<TEmbedModel>>, options?: Readonly<AxAIServiceActionOptions<TModel, TEmbedModel>>): Promise<AxEmbedResponse>;
430
+ private _embed1;
431
+ private _embed2;
432
+ private buildHeaders;
433
+ private getModelByKey;
434
+ private getModel;
435
+ private getEmbedModel;
436
+ }
437
+
440
438
  declare enum AxAIAnthropicModel {
441
439
  Claude4Opus = "claude-opus-4-20250514",
442
440
  Claude4Sonnet = "claude-sonnet-4-20250514",
@@ -673,7 +671,7 @@ declare const axAIAnthropicDefaultConfig: () => AxAIAnthropicConfig;
673
671
  declare const axAIAnthropicVertexDefaultConfig: () => AxAIAnthropicConfig;
674
672
  interface AxAIAnthropicArgs {
675
673
  name: 'anthropic';
676
- apiKey?: string;
674
+ apiKey?: string | (() => Promise<string>);
677
675
  projectId?: string;
678
676
  region?: string;
679
677
  config?: Readonly<Partial<AxAIAnthropicConfig>>;
@@ -684,6 +682,8 @@ declare class AxAIAnthropic extends AxBaseAI<AxAIAnthropicModel | AxAIAnthropicV
684
682
  constructor({ apiKey, projectId, region, config, options, models, }: Readonly<Omit<AxAIAnthropicArgs, 'name'>>);
685
683
  }
686
684
 
685
+ declare const axModelInfoAnthropic: AxModelInfo[];
686
+
687
687
  declare enum AxAIOpenAIModel {
688
688
  GPT4 = "gpt-4",
689
689
  GPT41 = "gpt-4.1",
@@ -969,6 +969,57 @@ declare class AxAIAzureOpenAI extends AxAIOpenAIBase<AxAIOpenAIModel, AxAIOpenAI
969
969
  constructor({ apiKey, resourceName, deploymentName, version, config, options, models, modelInfo, }: Readonly<Omit<AxAIAzureOpenAIArgs, 'name'>>);
970
970
  }
971
971
 
972
+ /**
973
+ * Options for the balancer.
974
+ */
975
+ type AxBalancerOptions = {
976
+ comparator?: (a: AxAIService, b: AxAIService) => number;
977
+ debug?: boolean;
978
+ initialBackoffMs?: number;
979
+ maxBackoffMs?: number;
980
+ maxRetries?: number;
981
+ };
982
+ /**
983
+ * Balancer that rotates through services.
984
+ */
985
+ declare class AxBalancer implements AxAIService<unknown, unknown> {
986
+ private services;
987
+ private currentServiceIndex;
988
+ private currentService;
989
+ private debug;
990
+ private initialBackoffMs;
991
+ private maxBackoffMs;
992
+ private maxRetries;
993
+ private serviceFailures;
994
+ constructor(services: readonly AxAIService[], options?: AxBalancerOptions);
995
+ getLastUsedChatModel(): unknown;
996
+ getLastUsedEmbedModel(): unknown;
997
+ getLastUsedModelConfig(): AxModelConfig | undefined;
998
+ /**
999
+ * Service comparator that respects the input order of services.
1000
+ */
1001
+ static inputOrderComparator: () => number;
1002
+ /**
1003
+ * Service comparator that sorts services by cost.
1004
+ */
1005
+ static metricComparator: (a: AxAIService, b: AxAIService) => number;
1006
+ getModelList(): AxAIModelList | undefined;
1007
+ private getNextService;
1008
+ private reset;
1009
+ getName(): string;
1010
+ getId(): string;
1011
+ getFeatures(model?: string): AxAIFeatures;
1012
+ getMetrics(): AxAIServiceMetrics;
1013
+ private canRetryService;
1014
+ private handleFailure;
1015
+ private handleSuccess;
1016
+ chat(req: Readonly<AxChatRequest>, options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions> | undefined): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
1017
+ embed(req: Readonly<AxEmbedRequest>, options?: Readonly<AxAIServiceActionOptions> | undefined): Promise<AxEmbedResponse>;
1018
+ setOptions(options: Readonly<AxAIServiceOptions>): void;
1019
+ getOptions(): Readonly<AxAIServiceOptions>;
1020
+ getLogger(): AxLoggerFunction;
1021
+ }
1022
+
972
1023
  /**
973
1024
  * Cohere: Models for text generation
974
1025
  */
@@ -1081,6 +1132,8 @@ declare class AxAICohere extends AxBaseAI<AxAICohereModel, AxAICohereEmbedModel,
1081
1132
  constructor({ apiKey, config, options, models, }: Readonly<Omit<AxAICohereArgs, 'name'>>);
1082
1133
  }
1083
1134
 
1135
+ declare const axModelInfoCohere: AxModelInfo[];
1136
+
1084
1137
  /**
1085
1138
  * DeepSeek: Models for text generation
1086
1139
  */
@@ -1098,6 +1151,8 @@ declare class AxAIDeepSeek extends AxAIOpenAIBase<AxAIDeepSeekModel, undefined>
1098
1151
  constructor({ apiKey, config, options, models, modelInfo, }: Readonly<Omit<AxAIDeepSeekArgs, 'name'>>);
1099
1152
  }
1100
1153
 
1154
+ declare const axModelInfoDeepSeek: AxModelInfo[];
1155
+
1101
1156
  declare enum AxAIGoogleGeminiModel {
1102
1157
  Gemini25Pro = "gemini-2.5-pro",
1103
1158
  Gemini25Flash = "gemini-2.5-flash",
@@ -1228,7 +1283,7 @@ type AxAIGoogleGeminiChatRequest = {
1228
1283
  type AxAIGoogleGeminiChatResponse = {
1229
1284
  candidates: {
1230
1285
  content: AxAIGoogleGeminiContent;
1231
- finishReason: 'STOP' | 'MAX_TOKENS' | 'SAFETY' | 'RECITATION' | 'OTHER' | 'MALFORMED_FUNCTION_CALL';
1286
+ finishReason: 'STOP' | 'MAX_TOKENS' | 'SAFETY' | 'RECITATION' | 'OTHER' | 'BLOCKLIST' | 'PROHIBITED_CONTENT' | 'SPII' | 'MALFORMED_FUNCTION_CALL' | 'UNEXPECTED_TOOL_CALL' | 'FINISH_REASON_UNSPECIFIED';
1232
1287
  citationMetadata: {
1233
1288
  citations: {
1234
1289
  startIndex: number;
@@ -1338,7 +1393,7 @@ interface AxAIGoogleGeminiOptionsTools {
1338
1393
  }
1339
1394
  interface AxAIGoogleGeminiArgs {
1340
1395
  name: 'google-gemini';
1341
- apiKey?: string;
1396
+ apiKey?: string | (() => Promise<string>);
1342
1397
  projectId?: string;
1343
1398
  region?: string;
1344
1399
  endpointId?: string;
@@ -1354,6 +1409,11 @@ declare class AxAIGoogleGemini extends AxBaseAI<AxAIGoogleGeminiModel, AxAIGoogl
1354
1409
  constructor({ apiKey, projectId, region, endpointId, config, options, models, modelInfo, }: Readonly<Omit<AxAIGoogleGeminiArgs, 'name'>>);
1355
1410
  }
1356
1411
 
1412
+ /**
1413
+ * AxAIGoogleGemini: Model information
1414
+ */
1415
+ declare const axModelInfoGoogleGemini: AxModelInfo[];
1416
+
1357
1417
  declare enum AxAIGroqModel {
1358
1418
  Llama3_8B = "llama3-8b-8192",
1359
1419
  Llama33_70B = "llama-3.3-70b-versatile",
@@ -1373,6 +1433,11 @@ declare class AxAIGroq extends AxAIOpenAIBase<AxAIGroqModel, undefined> {
1373
1433
  private newRateLimiter;
1374
1434
  }
1375
1435
 
1436
+ /**
1437
+ * AxAIGroq: Model information
1438
+ */
1439
+ declare const axModelInfoGroq: AxModelInfo[];
1440
+
1376
1441
  declare enum AxAIHuggingFaceModel {
1377
1442
  MetaLlama270BChatHF = "meta-llama/Llama-2-70b-chat-hf"
1378
1443
  }
@@ -1420,10 +1485,42 @@ declare class AxAIHuggingFace extends AxBaseAI<AxAIHuggingFaceModel, unknown, Ax
1420
1485
  constructor({ apiKey, config, options, models, }: Readonly<Omit<AxAIHuggingFaceArgs, 'name'>>);
1421
1486
  }
1422
1487
 
1423
- declare enum AxAIMistralModel {
1424
- Mistral7B = "open-mistral-7b",
1425
- Mistral8x7B = "open-mixtral-8x7b",
1426
- MistralSmall = "mistral-small-latest",
1488
+ /**
1489
+ * HuggingFace: Model information
1490
+ */
1491
+ declare const axModelInfoHuggingFace: AxModelInfo[];
1492
+
1493
+ interface AxAIMetricsInstruments {
1494
+ latencyHistogram?: Histogram;
1495
+ errorCounter?: Counter;
1496
+ requestCounter?: Counter;
1497
+ tokenCounter?: Counter;
1498
+ inputTokenCounter?: Counter;
1499
+ outputTokenCounter?: Counter;
1500
+ errorRateGauge?: Gauge;
1501
+ meanLatencyGauge?: Gauge;
1502
+ p95LatencyGauge?: Gauge;
1503
+ p99LatencyGauge?: Gauge;
1504
+ streamingRequestsCounter?: Counter;
1505
+ functionCallsCounter?: Counter;
1506
+ functionCallLatencyHistogram?: Histogram;
1507
+ requestSizeHistogram?: Histogram;
1508
+ responseSizeHistogram?: Histogram;
1509
+ temperatureGauge?: Gauge;
1510
+ maxTokensGauge?: Gauge;
1511
+ estimatedCostCounter?: Counter;
1512
+ promptLengthHistogram?: Histogram;
1513
+ contextWindowUsageGauge?: Gauge;
1514
+ timeoutsCounter?: Counter;
1515
+ abortsCounter?: Counter;
1516
+ thinkingBudgetUsageCounter?: Counter;
1517
+ multimodalRequestsCounter?: Counter;
1518
+ }
1519
+
1520
+ declare enum AxAIMistralModel {
1521
+ Mistral7B = "open-mistral-7b",
1522
+ Mistral8x7B = "open-mixtral-8x7b",
1523
+ MistralSmall = "mistral-small-latest",
1427
1524
  MistralNemo = "mistral-nemo-latest",
1428
1525
  MistralLarge = "mistral-large-latest",
1429
1526
  Codestral = "codestral-latest",
@@ -1480,6 +1577,130 @@ declare class AxAIMistral extends AxAIOpenAIBase<AxAIMistralModel, AxAIMistralEm
1480
1577
  private updateMessages;
1481
1578
  }
1482
1579
 
1580
+ declare const axModelInfoMistral: AxModelInfo[];
1581
+
1582
+ type AxMockAIServiceConfig = {
1583
+ name?: string;
1584
+ id?: string;
1585
+ modelInfo?: Partial<AxModelInfoWithProvider>;
1586
+ embedModelInfo?: AxModelInfoWithProvider;
1587
+ features?: {
1588
+ functions?: boolean;
1589
+ streaming?: boolean;
1590
+ };
1591
+ models?: AxAIModelList;
1592
+ options?: AxAIServiceOptions;
1593
+ chatResponse?: AxChatResponse | ReadableStream<AxChatResponse> | (() => Promise<AxChatResponse | ReadableStream<AxChatResponse>>) | ((req: Readonly<AxChatRequest<unknown>>, options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions<unknown, unknown>>) => Promise<AxChatResponse | ReadableStream<AxChatResponse>>);
1594
+ embedResponse?: AxEmbedResponse | ((req: Readonly<AxEmbedRequest>) => AxEmbedResponse | Promise<AxEmbedResponse>);
1595
+ shouldError?: boolean;
1596
+ errorMessage?: string;
1597
+ latencyMs?: number;
1598
+ };
1599
+ declare class AxMockAIService implements AxAIService {
1600
+ private readonly config;
1601
+ private metrics;
1602
+ constructor(config?: AxMockAIServiceConfig);
1603
+ getLastUsedChatModel(): unknown;
1604
+ getLastUsedEmbedModel(): unknown;
1605
+ getLastUsedModelConfig(): AxModelConfig | undefined;
1606
+ getName(): string;
1607
+ getId(): string;
1608
+ getFeatures(_model?: string): {
1609
+ functions: boolean;
1610
+ streaming: boolean;
1611
+ };
1612
+ getModelList(): AxAIModelList | undefined;
1613
+ getMetrics(): AxAIServiceMetrics;
1614
+ chat(req: Readonly<AxChatRequest<unknown>>, _options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions<unknown, unknown>>): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
1615
+ embed(req: Readonly<AxEmbedRequest>, _options?: Readonly<AxAIServiceActionOptions>): Promise<AxEmbedResponse>;
1616
+ setOptions(options: Readonly<AxAIServiceOptions>): void;
1617
+ getOptions(): Readonly<AxAIServiceOptions>;
1618
+ getLogger(): AxLoggerFunction;
1619
+ private updateMetrics;
1620
+ }
1621
+
1622
+ type AxAIServiceListItem<TModel = unknown, TEmbedModel = unknown> = {
1623
+ key: string;
1624
+ service: AxAIService<TModel, TEmbedModel>;
1625
+ description: string;
1626
+ isInternal?: boolean;
1627
+ };
1628
+ declare class AxMultiServiceRouter implements AxAIService<string, string> {
1629
+ private options?;
1630
+ private lastUsedService?;
1631
+ private services;
1632
+ /**
1633
+ * Constructs a new multi-service router.
1634
+ * It validates that each service provides a unique set of model keys,
1635
+ * then builds a lookup (map) for routing the chat/embed requests.
1636
+ */
1637
+ constructor(services: (AxAIServiceListItem<string, string> | AxAIService<string, string>)[]);
1638
+ getLastUsedChatModel(): string | undefined;
1639
+ getLastUsedEmbedModel(): string | undefined;
1640
+ getLastUsedModelConfig(): AxModelConfig | undefined;
1641
+ /**
1642
+ * Delegates the chat call to the service matching the provided model key.
1643
+ */
1644
+ chat(req: Readonly<AxChatRequest<string>>, options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions<string, string>>): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
1645
+ /**
1646
+ * Delegates the embed call to the service matching the provided embed model key.
1647
+ */
1648
+ embed(req: Readonly<AxEmbedRequest<string>>, options?: Readonly<AxAIServiceActionOptions<string, string>>): Promise<AxEmbedResponse>;
1649
+ /**
1650
+ * Returns a composite ID built from the IDs of the underlying services.
1651
+ */
1652
+ getId(): string;
1653
+ /**
1654
+ * Returns the name of this router.
1655
+ */
1656
+ getName(): string;
1657
+ /**
1658
+ * Aggregates all available models across the underlying services.
1659
+ */
1660
+ getModelList(): AxAIModelList;
1661
+ /**
1662
+ * If a model key is provided, delegate to the corresponding service's features.
1663
+ * Otherwise, returns a default feature set.
1664
+ */
1665
+ getFeatures(model?: string): {
1666
+ functions: boolean;
1667
+ streaming: boolean;
1668
+ functionCot?: boolean;
1669
+ };
1670
+ /**
1671
+ * Returns aggregated metrics from the underlying service.
1672
+ * Uses the metrics from the last service that was used,
1673
+ * or falls back to the first service if none has been used.
1674
+ */
1675
+ getMetrics(): AxAIServiceMetrics;
1676
+ /**
1677
+ * Sets options on all underlying services.
1678
+ */
1679
+ setOptions(options: Readonly<AxAIServiceOptions>): void;
1680
+ /**
1681
+ * Returns the options from the last used service,
1682
+ * or falls back to the first service if none has been used.
1683
+ */
1684
+ getOptions(): Readonly<AxAIServiceOptions>;
1685
+ /**
1686
+ * Returns the logger from the last used service,
1687
+ * or falls back to the first service if none has been used.
1688
+ */
1689
+ getLogger(): AxLoggerFunction;
1690
+ /**
1691
+ * Sets a service entry for a given key. This method is intended for testing purposes.
1692
+ * @param key - The model key
1693
+ * @param entry - The service entry to set
1694
+ */
1695
+ setServiceEntry(key: string, entry: {
1696
+ isInternal?: boolean;
1697
+ description: string;
1698
+ model?: string;
1699
+ embedModel?: string;
1700
+ service: AxAIService<string, string>;
1701
+ }): void;
1702
+ }
1703
+
1483
1704
  type AxAIOllamaAIConfig = AxAIOpenAIConfig<string, string>;
1484
1705
  declare const axAIOllamaDefaultConfig: () => AxAIOllamaAIConfig;
1485
1706
  declare const axAIOllamaDefaultCreativeConfig: () => AxAIOllamaAIConfig;
@@ -1495,6 +1716,15 @@ declare class AxAIOllama extends AxAIOpenAIBase<string, string> {
1495
1716
  constructor({ apiKey, url, config, options, models, }: Readonly<Omit<AxAIOllamaArgs, 'name'>>);
1496
1717
  }
1497
1718
 
1719
+ /**
1720
+ * OpenAI: Model information
1721
+ */
1722
+ declare const axModelInfoOpenAI: AxModelInfo[];
1723
+ /**
1724
+ * OpenAI: Model information
1725
+ */
1726
+ declare const axModelInfoOpenAIResponses: AxModelInfo[];
1727
+
1498
1728
  declare enum AxAIOpenAIResponsesModel {
1499
1729
  GPT4 = "gpt-4",
1500
1730
  GPT41 = "gpt-4.1",
@@ -1987,6 +2217,28 @@ interface AxAIOpenAIResponsesMCPToolCall extends AxAIOpenAIResponsesToolCallBase
1987
2217
  }
1988
2218
  type AxAIOpenAIResponsesToolCall = AxAIOpenAIResponsesFunctionCallItem | AxAIOpenAIResponsesFileSearchToolCall | AxAIOpenAIResponsesWebSearchToolCall | AxAIOpenAIResponsesComputerToolCall | AxAIOpenAIResponsesCodeInterpreterToolCall | AxAIOpenAIResponsesImageGenerationToolCall | AxAIOpenAIResponsesLocalShellToolCall | AxAIOpenAIResponsesMCPToolCall;
1989
2219
 
2220
+ declare class AxAIOpenAIResponsesImpl<TModel, TEmbedModel, // Kept for interface compatibility, but not used by this impl.
2221
+ TResponsesReq extends AxAIOpenAIResponsesRequest<TModel>> implements AxAIServiceImpl<TModel, TEmbedModel, Readonly<AxAIOpenAIResponsesRequest<TModel>>, // ChatReq (now ResponsesReq)
2222
+ Readonly<AxAIOpenAIEmbedRequest<TEmbedModel>>, // EmbedReq
2223
+ Readonly<AxAIOpenAIResponsesResponse>, // ChatResp (now ResponsesResp)
2224
+ Readonly<AxAIOpenAIResponsesResponseDelta>, // ChatRespDelta (now ResponsesRespDelta)
2225
+ Readonly<AxAIOpenAIEmbedResponse>> {
2226
+ private readonly config;
2227
+ private readonly streamingUsage;
2228
+ private readonly responsesReqUpdater?;
2229
+ private tokensUsed;
2230
+ constructor(config: Readonly<AxAIOpenAIResponsesConfig<TModel, TEmbedModel>>, streamingUsage: boolean, // If /v1/responses supports include_usage for streams
2231
+ responsesReqUpdater?: ResponsesReqUpdater<TModel, TResponsesReq> | undefined);
2232
+ getTokenUsage(): Readonly<AxTokenUsage> | undefined;
2233
+ getModelConfig(): Readonly<AxModelConfig>;
2234
+ private mapInternalContentToResponsesInput;
2235
+ private createResponsesReqInternalInput;
2236
+ createChatReq(req: Readonly<AxInternalChatRequest<TModel>>, config: Readonly<AxAIPromptConfig>): [Readonly<AxAPI>, Readonly<AxAIOpenAIResponsesRequest<TModel>>];
2237
+ createChatResp(resp: Readonly<AxAIOpenAIResponsesResponse>): Readonly<AxChatResponse>;
2238
+ createChatStreamResp(streamEvent: Readonly<AxAIOpenAIResponsesResponseDelta>): Readonly<AxChatResponse>;
2239
+ createEmbedReq(req: Readonly<AxInternalEmbedRequest<TEmbedModel>>): [AxAPI, AxAIOpenAIEmbedRequest<TEmbedModel>];
2240
+ }
2241
+
1990
2242
  declare const axAIOpenAIResponsesDefaultConfig: () => AxAIOpenAIResponsesConfig<AxAIOpenAIResponsesModel, AxAIOpenAIEmbedModel>;
1991
2243
  declare const axAIOpenAIResponsesBestConfig: () => AxAIOpenAIResponsesConfig<AxAIOpenAIResponsesModel, AxAIOpenAIEmbedModel>;
1992
2244
  declare const axAIOpenAIResponsesCreativeConfig: () => AxAIOpenAIResponsesConfig<AxAIOpenAIResponsesModel, AxAIOpenAIEmbedModel>;
@@ -2107,6 +2359,11 @@ declare class AxAIReka extends AxBaseAI<AxAIRekaModel, undefined, AxAIRekaChatRe
2107
2359
  constructor({ apiKey, config, options, apiURL, modelInfo, models, }: Readonly<Omit<AxAIRekaArgs, 'name'>>);
2108
2360
  }
2109
2361
 
2362
+ /**
2363
+ * OpenAI: Model information
2364
+ */
2365
+ declare const axModelInfoReka: AxModelInfo[];
2366
+
2110
2367
  type TogetherAIConfig = AxAIOpenAIConfig<string, unknown>;
2111
2368
  declare const axAITogetherDefaultConfig: () => TogetherAIConfig;
2112
2369
  type AxAITogetherArgs = AxAIOpenAIArgs<'together', string, unknown>;
@@ -2114,6 +2371,22 @@ declare class AxAITogether extends AxAIOpenAIBase<string, unknown> {
2114
2371
  constructor({ apiKey, config, options, models, modelInfo, }: Readonly<Omit<AxAITogetherArgs, 'name'>>);
2115
2372
  }
2116
2373
 
2374
+ declare const axModelInfoTogether: AxModelInfo[];
2375
+
2376
+ type AxChatRequestMessage = AxChatRequest['chatPrompt'][number];
2377
+ /**
2378
+ * Validates a chat request message item to ensure it meets the required criteria
2379
+ * @param item - The chat request message to validate
2380
+ * @throws {Error} When validation fails with a descriptive error message
2381
+ */
2382
+ declare function axValidateChatRequestMessage(item: AxChatRequestMessage): void;
2383
+ /**
2384
+ * Validates a chat response result to ensure it meets the required criteria
2385
+ * @param results - The chat response results to validate (single result or array)
2386
+ * @throws {Error} When validation fails with a descriptive error message
2387
+ */
2388
+ declare function axValidateChatResponseResult(results: Readonly<AxChatResponseResult[]> | Readonly<AxChatResponseResult>): void;
2389
+
2117
2390
  type AxAIArgs = AxAIOpenAIArgs | AxAIOpenAIResponsesArgs | AxAIAzureOpenAIArgs | AxAITogetherArgs | AxAIAnthropicArgs | AxAIGroqArgs | AxAIGoogleGeminiArgs | AxAICohereArgs | AxAIHuggingFaceArgs | AxAIMistralArgs | AxAIDeepSeekArgs | AxAIOllamaArgs | AxAIRekaArgs;
2118
2391
  type AxAIModels = AxAIOpenAIModel | AxAIAnthropicModel | AxAIGroqModel | AxAIGoogleGeminiModel | AxAICohereModel | AxAIHuggingFaceModel | AxAIMistralModel | AxAIDeepSeekModel;
2119
2392
  type AxAIEmbedModels = AxAIOpenAIEmbedModel | AxAIGoogleGeminiEmbedModel | AxAICohereEmbedModel;
@@ -2189,54 +2462,199 @@ declare class AxAIGrok extends AxAIOpenAIBase<AxAIGrokModel, AxAIGrokEmbedModels
2189
2462
  constructor({ apiKey, config, options, models, modelInfo, }: Readonly<Omit<AxAIGrokArgs, 'name'>>);
2190
2463
  }
2191
2464
 
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
- }
2465
+ declare const axModelInfoGrok: AxModelInfo[];
2214
2466
 
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;
2467
+ type AxDBUpsertRequest = {
2468
+ id: string;
2469
+ text?: string;
2470
+ values?: readonly number[];
2471
+ metadata?: Record<string, string>;
2472
+ table: string;
2473
+ namespace?: string;
2229
2474
  };
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;
2475
+ type AxDBUpsertResponse = {
2476
+ ids: string[];
2477
+ };
2478
+ type AxDBQueryRequest = {
2479
+ id?: string;
2480
+ text?: string;
2481
+ values?: readonly number[];
2482
+ table: string;
2483
+ columns?: string[];
2484
+ limit?: number;
2485
+ namespace?: string;
2486
+ };
2487
+ type AxDBQueryResponse = {
2488
+ matches: {
2489
+ id: string;
2490
+ score: number;
2491
+ metadata?: Record<string, string>;
2492
+ table?: string;
2493
+ }[];
2494
+ };
2495
+ interface AxDBService extends AxDBQueryService {
2496
+ upsert(req: Readonly<AxDBUpsertRequest>, update?: boolean): Promise<AxDBUpsertResponse>;
2497
+ batchUpsert(batchReq: Readonly<AxDBUpsertRequest[]>, update?: boolean): Promise<AxDBUpsertResponse>;
2498
+ }
2499
+ interface AxDBQueryService {
2500
+ query(req: Readonly<AxDBQueryRequest>): Promise<AxDBQueryResponse>;
2501
+ }
2502
+
2503
+ interface AxDBBaseArgs {
2504
+ fetch?: typeof fetch;
2505
+ tracer?: Tracer;
2506
+ }
2507
+ interface AxDBBaseOpOptions {
2508
+ span?: Span;
2509
+ }
2510
+ declare class AxDBBase implements AxDBService {
2511
+ protected name: string;
2512
+ protected fetch?: typeof fetch;
2513
+ private tracer?;
2514
+ _upsert?: (req: Readonly<AxDBUpsertRequest>, update?: boolean, options?: Readonly<AxDBBaseOpOptions>) => Promise<AxDBUpsertResponse>;
2515
+ _batchUpsert?: (batchReq: Readonly<AxDBUpsertRequest[]>, update?: boolean, options?: Readonly<AxDBBaseOpOptions>) => Promise<AxDBUpsertResponse>;
2516
+ _query?: (req: Readonly<AxDBQueryRequest>, options?: Readonly<AxDBBaseOpOptions>) => Promise<AxDBQueryResponse>;
2517
+ constructor({ name, fetch, tracer, }: Readonly<AxDBBaseArgs & {
2518
+ name: string;
2519
+ }>);
2520
+ upsert(req: Readonly<AxDBUpsertRequest>, update?: boolean): Promise<AxDBUpsertResponse>;
2521
+ batchUpsert(req: Readonly<AxDBUpsertRequest[]>, update?: boolean): Promise<AxDBUpsertResponse>;
2522
+ query(req: Readonly<AxDBQueryRequest>): Promise<AxDBQueryResponse>;
2523
+ }
2524
+
2525
+ type AxDBCloudflareOpOptions = AxDBBaseOpOptions;
2526
+ interface AxDBCloudflareArgs extends AxDBBaseArgs {
2527
+ name: 'cloudflare';
2528
+ apiKey: string;
2529
+ accountId: string;
2530
+ fetch?: typeof fetch;
2531
+ }
2532
+ /**
2533
+ * Cloudflare: DB Service
2534
+ */
2535
+ declare class AxDBCloudflare extends AxDBBase {
2536
+ private apiKey;
2537
+ private accountId;
2538
+ constructor({ apiKey, accountId, fetch, tracer, }: Readonly<Omit<AxDBCloudflareArgs, 'name'>>);
2539
+ _upsert: (req: Readonly<AxDBUpsertRequest>, _update?: boolean, options?: Readonly<AxDBCloudflareOpOptions>) => Promise<AxDBUpsertResponse>;
2540
+ batchUpsert: (batchReq: Readonly<AxDBUpsertRequest[]>, update?: boolean, options?: Readonly<AxDBCloudflareOpOptions>) => Promise<AxDBUpsertResponse>;
2541
+ query: (req: Readonly<AxDBQueryRequest>, options?: Readonly<AxDBCloudflareOpOptions>) => Promise<AxDBQueryResponse>;
2542
+ }
2543
+
2544
+ type AxDBMemoryOpOptions = AxDBBaseOpOptions;
2545
+ interface AxDBMemoryArgs extends AxDBBaseArgs {
2546
+ name: 'memory';
2547
+ }
2548
+ type AxDBState = Record<string, Record<string, AxDBUpsertRequest>>;
2549
+ /**
2550
+ * MemoryDB: DB Service
2551
+ */
2552
+ declare class AxDBMemory extends AxDBBase {
2553
+ private state;
2554
+ constructor({ tracer }?: Readonly<Omit<AxDBMemoryArgs, 'name'>>);
2555
+ _upsert: (req: Readonly<AxDBUpsertRequest>, _update?: boolean, _options?: Readonly<AxDBMemoryOpOptions>) => Promise<AxDBUpsertResponse>;
2556
+ _batchUpsert: (batchReq: Readonly<AxDBUpsertRequest[]>, update?: boolean, _options?: Readonly<AxDBMemoryOpOptions>) => Promise<AxDBUpsertResponse>;
2557
+ _query: (req: Readonly<AxDBQueryRequest>, _options?: Readonly<AxDBMemoryOpOptions>) => Promise<AxDBQueryResponse>;
2558
+ getDB: () => AxDBState;
2559
+ setDB: (state: AxDBState) => void;
2560
+ clearDB: () => void;
2561
+ }
2562
+
2563
+ type AxDBPineconeOpOptions = AxDBBaseOpOptions;
2564
+ interface AxDBPineconeArgs extends AxDBBaseArgs {
2565
+ name: 'pinecone';
2566
+ apiKey: string;
2567
+ host: string;
2568
+ fetch?: typeof fetch;
2569
+ }
2570
+ /**
2571
+ * Pinecone: DB Service
2572
+ */
2573
+ declare class AxDBPinecone extends AxDBBase {
2574
+ private apiKey;
2575
+ private apiURL;
2576
+ constructor({ apiKey, host, fetch, tracer, }: Readonly<Omit<AxDBPineconeArgs, 'name'>>);
2577
+ _upsert: (req: Readonly<AxDBUpsertRequest>, update?: boolean, options?: Readonly<AxDBPineconeOpOptions>) => Promise<AxDBUpsertResponse>;
2578
+ _batchUpsert: (batchReq: Readonly<AxDBUpsertRequest[]>, _update?: boolean, options?: Readonly<AxDBPineconeOpOptions>) => Promise<AxDBUpsertResponse>;
2579
+ query: (req: Readonly<AxDBQueryRequest>, options?: Readonly<AxDBPineconeOpOptions>) => Promise<AxDBQueryResponse>;
2580
+ }
2581
+
2582
+ type AxDBWeaviateOpOptions = AxDBBaseOpOptions;
2583
+ interface AxDBWeaviateArgs extends AxDBBaseArgs {
2584
+ name: 'weaviate';
2585
+ apiKey: string;
2586
+ host: string;
2587
+ fetch?: typeof fetch;
2588
+ }
2589
+ /**
2590
+ * Weaviate: DB Service
2591
+ */
2592
+ declare class AxDBWeaviate extends AxDBBase {
2593
+ private apiKey;
2594
+ private apiURL;
2595
+ constructor({ apiKey, host, fetch, tracer, }: Readonly<Omit<AxDBWeaviateArgs, 'name'>>);
2596
+ _upsert: (req: Readonly<AxDBUpsertRequest>, update?: boolean, options?: Readonly<AxDBWeaviateOpOptions>) => Promise<AxDBUpsertResponse>;
2597
+ _batchUpsert: (batchReq: Readonly<AxDBUpsertRequest[]>, update?: boolean, options?: Readonly<AxDBWeaviateOpOptions>) => Promise<AxDBUpsertResponse>;
2598
+ _query: (req: Readonly<AxDBQueryRequest>, options?: Readonly<AxDBWeaviateOpOptions>) => Promise<AxDBQueryResponse>;
2599
+ }
2600
+
2601
+ type AxDBArgs = AxDBCloudflareArgs | AxDBPineconeArgs | AxDBWeaviateArgs | AxDBMemoryArgs;
2602
+ declare class AxDB implements AxDBService {
2603
+ private db;
2604
+ constructor(args: Readonly<AxDBArgs>);
2605
+ upsert(req: Readonly<AxDBUpsertRequest>, update?: boolean): Promise<AxDBUpsertResponse>;
2606
+ batchUpsert(batchReq: Readonly<AxDBUpsertRequest[]>, update?: boolean): Promise<AxDBUpsertResponse>;
2607
+ query(req: Readonly<AxDBQueryRequest>): Promise<AxDBQueryResponse>;
2608
+ }
2609
+
2610
+ type AxMemoryData = {
2611
+ tags?: string[];
2612
+ role: AxChatRequest['chatPrompt'][number]['role'];
2613
+ updatable?: boolean;
2614
+ chat: {
2615
+ index: number;
2616
+ value: Omit<AxChatRequest['chatPrompt'][number], 'role'>;
2617
+ }[];
2618
+ }[];
2619
+ interface AxAIMemory {
2620
+ addRequest(result: AxChatRequest['chatPrompt'], sessionId?: string): void;
2621
+ addResponse(results: Readonly<AxChatResponseResult[]>, sessionId?: string): void;
2622
+ updateResult(results: Readonly<AxChatResponseResult> & {
2623
+ delta?: string;
2624
+ }, sessionId?: string): void;
2625
+ addFunctionResults(results: Readonly<AxFunctionResult[]>, sessionId?: string): void;
2626
+ history(index: number, sessionId?: string): AxChatRequest['chatPrompt'];
2627
+ reset(sessionId?: string): void;
2628
+ getLast(sessionId?: string): AxMemoryData[number] | undefined;
2629
+ addTag(name: string, sessionId?: string): void;
2630
+ rewindToTag(name: string, sessionId?: string): AxMemoryData;
2631
+ }
2632
+
2633
+ interface AxField {
2634
+ name: string;
2635
+ title?: string;
2636
+ description?: string;
2637
+ type?: {
2638
+ name: 'string' | 'number' | 'boolean' | 'json' | 'image' | 'audio' | 'date' | 'datetime' | 'class' | 'code';
2639
+ isArray?: boolean;
2640
+ options?: string[];
2641
+ };
2642
+ isOptional?: boolean;
2643
+ isInternal?: boolean;
2644
+ }
2645
+ type AxIField = Omit<AxField, 'title'> & {
2646
+ title: string;
2647
+ };
2648
+ interface AxSignatureConfig {
2649
+ description?: string;
2650
+ inputs: readonly AxField[];
2651
+ outputs: readonly AxField[];
2652
+ }
2653
+ declare class AxSignature {
2654
+ private description?;
2655
+ private inputFields;
2656
+ private outputFields;
2657
+ private sigHash;
2240
2658
  private sigString;
2241
2659
  private validatedAtHash?;
2242
2660
  constructor(signature?: Readonly<AxSignature | string | AxSignatureConfig>);
@@ -2579,77 +2997,148 @@ declare class AxProgram<IN extends AxGenIn, OUT extends AxGenOut> implements AxT
2579
2997
  setDemos(demos: readonly AxProgramDemos<IN, OUT>[]): void;
2580
2998
  }
2581
2999
 
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;
3000
+ type AxRewriteIn = {
3001
+ query: string;
2595
3002
  };
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[];
3003
+ type AxRewriteOut = {
3004
+ rewrittenQuery: string;
3005
+ };
3006
+ type AxRerankerIn = {
3007
+ query: string;
3008
+ items: string[];
3009
+ };
3010
+ type AxRerankerOut = {
3011
+ rankedItems: string[];
3012
+ };
3013
+ interface AxDBLoaderOptions {
3014
+ chunker?: (text: string) => string[];
3015
+ rewriter?: AxProgram<AxRewriteIn, AxRewriteOut>;
3016
+ reranker?: AxProgram<AxRerankerIn, AxRerankerOut>;
2601
3017
  }
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>;
3018
+ interface AxDBManagerArgs {
3019
+ ai: AxAIService;
3020
+ db: AxDBService;
3021
+ config?: AxDBLoaderOptions;
3022
+ }
3023
+ interface AxDBMatch {
3024
+ score: number;
3025
+ text: string;
3026
+ }
3027
+ declare class AxDBManager {
3028
+ private ai;
3029
+ private db;
3030
+ private chunker;
3031
+ private rewriter?;
3032
+ private reranker?;
3033
+ constructor({ ai, db, config }: Readonly<AxDBManagerArgs>);
3034
+ private defaultChunker;
3035
+ insert: (text: Readonly<string | string[]>, options?: Readonly<{
3036
+ batchSize?: number;
3037
+ maxWordsPerChunk?: number;
3038
+ minWordsPerChunk?: number;
3039
+ abortSignal?: AbortSignal;
3040
+ }>) => Promise<void>;
3041
+ query: (query: Readonly<string | string[] | number | number[]>, { topPercent, abortSignal, }?: Readonly<{
3042
+ topPercent?: number;
3043
+ abortSignal?: AbortSignal;
3044
+ }> | undefined) => Promise<AxDBMatch[][]>;
3045
+ }
3046
+
3047
+ type AxFieldProcessorProcess = (value: AxFieldValue, context?: Readonly<{
3048
+ values?: AxGenOut;
3049
+ sessionId?: string;
3050
+ done?: boolean;
3051
+ }>) => unknown | Promise<unknown>;
3052
+ type AxStreamingFieldProcessorProcess = (value: string, context?: Readonly<{
3053
+ values?: AxGenOut;
3054
+ sessionId?: string;
3055
+ done?: boolean;
3056
+ }>) => unknown | Promise<unknown>;
3057
+ interface AxFieldProcessor {
3058
+ field: Readonly<AxField>;
2643
3059
  /**
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
3060
+ * Process the field value and return a new value (or undefined if no update is needed).
3061
+ * The returned value may be merged back into memory.
3062
+ * @param value - The current field value.
3063
+ * @param context - Additional context (e.g. memory and session id).
2649
3064
  */
2650
- setDescription(description: string): void;
2651
- setDefinition(definition: string): void;
2652
- private getDebug;
3065
+ process: AxFieldProcessorProcess | AxStreamingFieldProcessorProcess;
3066
+ }
3067
+
3068
+ type AxGenerateResult<OUT extends AxGenOut> = OUT & {
3069
+ thought?: string;
3070
+ };
3071
+ interface AxResponseHandlerArgs<T> {
3072
+ ai: Readonly<AxAIService>;
3073
+ model?: string;
3074
+ res: T;
3075
+ mem: AxAIMemory;
3076
+ sessionId?: string;
3077
+ traceId?: string;
3078
+ functions: Readonly<AxFunction[]>;
3079
+ strictMode?: boolean;
3080
+ span?: Span;
3081
+ }
3082
+ interface AxStreamingEvent<T> {
3083
+ event: 'delta' | 'done' | 'error';
3084
+ data: {
3085
+ contentDelta?: string;
3086
+ partialValues?: Partial<T>;
3087
+ error?: string;
3088
+ functions?: AxChatResponseFunctionCall[];
3089
+ };
3090
+ }
3091
+ declare class AxGen<IN extends AxGenIn = AxGenIn, OUT extends AxGenOut = AxGenOut> extends AxProgram<IN, OUT> {
3092
+ private promptTemplate;
3093
+ private asserts;
3094
+ private streamingAsserts;
3095
+ private options?;
3096
+ private functions?;
3097
+ private fieldProcessors;
3098
+ private streamingFieldProcessors;
3099
+ private excludeContentFromTrace;
3100
+ private thoughtFieldName;
3101
+ constructor(signature: NonNullable<ConstructorParameters<typeof AxSignature>[0]>, options?: Readonly<AxProgramForwardOptions>);
3102
+ private getSignatureName;
3103
+ private getMetricsInstruments;
3104
+ updateMeter(meter?: Meter): void;
3105
+ private createStates;
3106
+ addAssert: (fn: AxAssertion["fn"], message?: string) => void;
3107
+ addStreamingAssert: (fieldName: string, fn: AxStreamingAssertion["fn"], message?: string) => void;
3108
+ private addFieldProcessorInternal;
3109
+ addStreamingFieldProcessor: (fieldName: string, fn: AxFieldProcessor["process"]) => void;
3110
+ addFieldProcessor: (fieldName: string, fn: AxFieldProcessor["process"]) => void;
3111
+ private forwardSendRequest;
3112
+ private forwardCore;
3113
+ private _forward2;
3114
+ _forward1(ai: Readonly<AxAIService>, values: IN | AxMessage<IN>[], options: Readonly<AxProgramForwardOptions>): AxGenStreamingOut<OUT>;
3115
+ forward(ai: Readonly<AxAIService>, values: IN | AxMessage<IN>[], options?: Readonly<AxProgramForwardOptions>): Promise<OUT>;
3116
+ streamingForward(ai: Readonly<AxAIService>, values: IN | AxMessage<IN>[], options?: Readonly<AxProgramStreamingForwardOptions>): AxGenStreamingOut<OUT>;
3117
+ setExamples(examples: Readonly<AxProgramExamples<IN, OUT>>, options?: Readonly<AxSetExamplesOptions>): void;
3118
+ private isDebug;
3119
+ private getLogger;
3120
+ }
3121
+ type AxGenerateErrorDetails = {
3122
+ model?: string;
3123
+ maxTokens?: number;
3124
+ streaming: boolean;
3125
+ signature: {
3126
+ input: Readonly<AxIField[]>;
3127
+ output: Readonly<AxIField[]>;
3128
+ description?: string;
3129
+ };
3130
+ };
3131
+ type ErrorOptions = {
3132
+ cause?: Error;
3133
+ };
3134
+ declare class AxGenerateError extends Error {
3135
+ readonly details: AxGenerateErrorDetails;
3136
+ constructor(message: string, details: Readonly<AxGenerateErrorDetails>, options?: ErrorOptions);
3137
+ }
3138
+
3139
+ declare class AxDefaultResultReranker extends AxGen<AxRerankerIn, AxRerankerOut> {
3140
+ constructor(options?: Readonly<AxProgramForwardOptions>);
3141
+ forward: (ai: Readonly<AxAIService>, input: Readonly<AxRerankerIn>, options?: Readonly<AxProgramForwardOptions>) => Promise<AxRerankerOut>;
2653
3142
  }
2654
3143
 
2655
3144
  interface AxApacheTikaArgs {
@@ -2670,56 +3159,75 @@ declare class AxApacheTika {
2670
3159
  }>): Promise<string[]>;
2671
3160
  }
2672
3161
 
3162
+ interface AxSimpleClassifierForwardOptions {
3163
+ cutoff?: number;
3164
+ abortSignal?: AbortSignal;
3165
+ }
3166
+ declare class AxSimpleClassifierClass {
3167
+ private readonly name;
3168
+ private readonly context;
3169
+ constructor(name: string, context: readonly string[]);
3170
+ getName(): string;
3171
+ getContext(): readonly string[];
3172
+ }
3173
+ declare class AxSimpleClassifier {
3174
+ private readonly ai;
3175
+ private db;
3176
+ private debug?;
3177
+ constructor(ai: AxAIService);
3178
+ getState(): AxDBState | undefined;
3179
+ setState(state: AxDBState): void;
3180
+ setClasses: (classes: readonly AxSimpleClassifierClass[], options?: Readonly<{
3181
+ abortSignal?: AbortSignal;
3182
+ }>) => Promise<void>;
3183
+ forward(text: string, options?: Readonly<AxSimpleClassifierForwardOptions>): Promise<string>;
3184
+ setOptions(options: Readonly<{
3185
+ debug?: boolean;
3186
+ }>): void;
3187
+ }
3188
+
2673
3189
  /**
2674
- * Options for the balancer.
3190
+ * Calculates the Exact Match (EM) score between a prediction and ground truth.
3191
+ *
3192
+ * The EM score is a strict metric used in machine learning to assess if the predicted
3193
+ * answer matches the ground truth exactly, commonly used in tasks like question answering.
3194
+ *
3195
+ * @param prediction The predicted text.
3196
+ * @param groundTruth The actual correct text.
3197
+ * @returns A number (1.0 for exact match, 0.0 otherwise).
2675
3198
  */
2676
- type AxBalancerOptions = {
2677
- comparator?: (a: AxAIService, b: AxAIService) => number;
2678
- debug?: boolean;
2679
- initialBackoffMs?: number;
2680
- maxBackoffMs?: number;
2681
- maxRetries?: number;
2682
- };
3199
+ declare function emScore(prediction: string, groundTruth: string): number;
2683
3200
  /**
2684
- * Balancer that rotates through services.
3201
+ * Calculates the F1 score between a prediction and ground truth.
3202
+ *
3203
+ * The F1 score is a harmonic mean of precision and recall, widely used in NLP to measure
3204
+ * a model's accuracy in considering both false positives and false negatives, offering a
3205
+ * balance for evaluating classification models.
3206
+ *
3207
+ * @param prediction The predicted text.
3208
+ * @param groundTruth The actual correct text.
3209
+ * @returns The F1 score as a number.
2685
3210
  */
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
- }
3211
+ declare function f1Score(prediction: string, groundTruth: string): number;
3212
+ /**
3213
+ * Calculates a novel F1 score, taking into account a history of interaction and excluding stopwords.
3214
+ *
3215
+ * This metric extends the F1 score by considering contextual relevance and filtering out common words
3216
+ * that might skew the assessment of the prediction's quality, especially in conversational models or
3217
+ * when historical context is relevant.
3218
+ *
3219
+ * @param history The historical context or preceding interactions.
3220
+ * @param prediction The predicted text.
3221
+ * @param groundTruth The actual correct text.
3222
+ * @param returnRecall Optionally return the recall score instead of F1.
3223
+ * @returns The novel F1 or recall score as a number.
3224
+ */
3225
+ declare function novelF1ScoreOptimized(history: string, prediction: string, groundTruth: string, returnRecall?: boolean): number;
3226
+ declare const AxEvalUtil: {
3227
+ emScore: typeof emScore;
3228
+ f1Score: typeof f1Score;
3229
+ novelF1ScoreOptimized: typeof novelF1ScoreOptimized;
3230
+ };
2723
3231
 
2724
3232
  type AxExample = Record<string, AxFieldValue>;
2725
3233
  type AxMetricFn = <T extends AxGenOut = AxGenOut>(arg0: Readonly<{
@@ -3243,1411 +3751,828 @@ declare abstract class AxBaseOptimizer<IN extends AxGenIn = AxGenIn, OUT extends
3243
3751
  protected recordPerformanceMetrics(metricType: 'evaluation' | 'demo_generation' | 'metric_computation', duration: number, optimizerType: string): void;
3244
3752
  }
3245
3753
 
3246
- type AxDBUpsertRequest = {
3247
- id: string;
3248
- text?: string;
3249
- values?: readonly number[];
3250
- metadata?: Record<string, string>;
3251
- table: string;
3252
- namespace?: string;
3754
+ type AxEvaluateArgs<IN extends AxGenIn, OUT extends AxGenOut> = {
3755
+ ai: AxAIService;
3756
+ program: Readonly<AxProgram<IN, OUT>>;
3757
+ examples: Readonly<AxExample[]>;
3253
3758
  };
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>;
3759
+ declare class AxTestPrompt<IN extends AxGenIn = AxGenIn, OUT extends AxGenOut = AxGenOut> {
3760
+ private ai;
3761
+ private program;
3762
+ private examples;
3763
+ constructor({ ai, program, examples, }: Readonly<AxEvaluateArgs<IN, OUT>>);
3764
+ run(metricFn: AxMetricFn): Promise<void>;
3280
3765
  }
3281
3766
 
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
- }
3767
+ declare const axGlobals: {
3768
+ signatureStrict: boolean;
3769
+ tracer: Tracer | undefined;
3770
+ meter: Meter | undefined;
3771
+ };
3303
3772
 
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>;
3773
+ type AxDataRow = {
3774
+ row: Record<string, AxFieldValue>;
3775
+ };
3776
+ declare class AxHFDataLoader {
3777
+ private rows;
3778
+ private baseUrl;
3779
+ private dataset;
3780
+ private split;
3781
+ private config;
3782
+ private options?;
3783
+ constructor({ dataset, split, config, options, }: Readonly<{
3784
+ dataset: string;
3785
+ split: string;
3786
+ config: string;
3787
+ options?: Readonly<{
3788
+ offset?: number;
3789
+ length?: number;
3790
+ }>;
3791
+ }>);
3792
+ private fetchDataFromAPI;
3793
+ loadData(): Promise<AxDataRow[]>;
3794
+ setData(rows: AxDataRow[]): void;
3795
+ getData(): AxDataRow[];
3796
+ getRows<T>({ count, fields, renameMap, }: Readonly<{
3797
+ count: number;
3798
+ fields: readonly string[];
3799
+ renameMap?: Record<string, string>;
3800
+ }>): Promise<T[]>;
3321
3801
  }
3322
3802
 
3323
- type AxDBMemoryOpOptions = AxDBBaseOpOptions;
3324
- interface AxDBMemoryArgs extends AxDBBaseArgs {
3325
- name: 'memory';
3326
- }
3327
- type AxDBState = Record<string, Record<string, AxDBUpsertRequest>>;
3803
+ declare const axCreateDefaultColorLogger: (output?: (message: string) => void) => AxLoggerFunction;
3804
+ declare const axCreateDefaultTextLogger: (output?: (message: string) => void) => AxLoggerFunction;
3328
3805
  /**
3329
- * MemoryDB: DB Service
3806
+ * Factory function to create an enhanced optimizer logger with clean visual formatting
3807
+ * that works for all optimizer types using semantic tags for proper categorization
3330
3808
  */
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
- }
3809
+ declare const axCreateOptimizerLogger: (output?: (message: string) => void) => AxLoggerFunction;
3349
3810
  /**
3350
- * Pinecone: DB Service
3811
+ * Default optimizer logger instance
3351
3812
  */
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
- }
3813
+ declare const axDefaultOptimizerLogger: AxLoggerFunction;
3360
3814
 
3361
- type AxDBWeaviateOpOptions = AxDBBaseOpOptions;
3362
- interface AxDBWeaviateArgs extends AxDBBaseArgs {
3363
- name: 'weaviate';
3364
- apiKey: string;
3365
- host: string;
3366
- fetch?: typeof fetch;
3815
+ interface AxMetricsConfig {
3816
+ enabled: boolean;
3817
+ enabledCategories: ('generation' | 'streaming' | 'functions' | 'errors' | 'performance')[];
3818
+ maxLabelLength: number;
3819
+ samplingRate: number;
3367
3820
  }
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>;
3821
+ declare const axDefaultMetricsConfig: AxMetricsConfig;
3822
+ type AxErrorCategory = 'validation_error' | 'assertion_error' | 'timeout_error' | 'abort_error' | 'network_error' | 'auth_error' | 'rate_limit_error' | 'function_error' | 'parsing_error' | 'unknown_error';
3823
+ interface AxGenMetricsInstruments {
3824
+ generationLatencyHistogram?: Histogram;
3825
+ generationRequestsCounter?: Counter;
3826
+ generationErrorsCounter?: Counter;
3827
+ multiStepGenerationsCounter?: Counter;
3828
+ stepsPerGenerationHistogram?: Histogram;
3829
+ maxStepsReachedCounter?: Counter;
3830
+ validationErrorsCounter?: Counter;
3831
+ assertionErrorsCounter?: Counter;
3832
+ errorCorrectionAttemptsHistogram?: Histogram;
3833
+ errorCorrectionSuccessCounter?: Counter;
3834
+ errorCorrectionFailureCounter?: Counter;
3835
+ maxRetriesReachedCounter?: Counter;
3836
+ functionsEnabledGenerationsCounter?: Counter;
3837
+ functionCallStepsCounter?: Counter;
3838
+ functionsExecutedPerGenerationHistogram?: Histogram;
3839
+ functionErrorCorrectionCounter?: Counter;
3840
+ fieldProcessorsExecutedCounter?: Counter;
3841
+ streamingFieldProcessorsExecutedCounter?: Counter;
3842
+ streamingGenerationsCounter?: Counter;
3843
+ streamingDeltasEmittedCounter?: Counter;
3844
+ streamingFinalizationLatencyHistogram?: Histogram;
3845
+ samplesGeneratedHistogram?: Histogram;
3846
+ resultPickerUsageCounter?: Counter;
3847
+ resultPickerLatencyHistogram?: Histogram;
3848
+ inputFieldsGauge?: Gauge;
3849
+ outputFieldsGauge?: Gauge;
3850
+ examplesUsedGauge?: Gauge;
3851
+ demosUsedGauge?: Gauge;
3852
+ promptRenderLatencyHistogram?: Histogram;
3853
+ extractionLatencyHistogram?: Histogram;
3854
+ assertionLatencyHistogram?: Histogram;
3855
+ stateCreationLatencyHistogram?: Histogram;
3856
+ memoryUpdateLatencyHistogram?: Histogram;
3378
3857
  }
3858
+ declare const axCheckMetricsHealth: () => {
3859
+ healthy: boolean;
3860
+ issues: string[];
3861
+ };
3862
+ declare const axUpdateMetricsConfig: (config: Readonly<Partial<AxMetricsConfig>>) => void;
3863
+ declare const axGetMetricsConfig: () => AxMetricsConfig;
3379
3864
 
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>;
3865
+ declare class AxBootstrapFewShot<IN extends AxGenIn = AxGenIn, OUT extends AxGenOut = AxGenOut> extends AxBaseOptimizer<IN, OUT> {
3866
+ private maxRounds;
3867
+ private maxDemos;
3868
+ private maxExamples;
3869
+ private batchSize;
3870
+ private earlyStoppingPatience;
3871
+ private costMonitoring;
3872
+ private maxTokensPerGeneration;
3873
+ private verboseMode;
3874
+ private debugMode;
3875
+ private traces;
3876
+ constructor(args: Readonly<AxOptimizerArgs & {
3877
+ options?: AxBootstrapOptimizerOptions;
3878
+ }>);
3879
+ private compileRound;
3880
+ compile(program: Readonly<AxProgram<IN, OUT>>, metricFn: AxMetricFn, options?: AxBootstrapCompileOptions): Promise<AxOptimizerResult<OUT>>;
3387
3881
  }
3388
3882
 
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;
3883
+ interface AxMiPROResult<IN extends AxGenIn, OUT extends AxGenOut> extends AxOptimizerResult<OUT> {
3884
+ optimizedGen?: AxGen<IN, OUT>;
3415
3885
  }
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
- }>;
3886
+ declare class AxMiPRO<IN extends AxGenIn = AxGenIn, OUT extends AxGenOut = AxGenOut> extends AxBaseOptimizer<IN, OUT> {
3887
+ private maxBootstrappedDemos;
3888
+ private maxLabeledDemos;
3889
+ private numCandidates;
3890
+ private initTemperature;
3891
+ private numTrials;
3892
+ private minibatch;
3893
+ private minibatchSize;
3894
+ private minibatchFullEvalSteps;
3895
+ private programAwareProposer;
3896
+ private dataAwareProposer;
3897
+ private viewDataBatchSize;
3898
+ private tipAwareProposer;
3899
+ private fewshotAwareProposer;
3900
+ private earlyStoppingTrials;
3901
+ private minImprovementThreshold;
3902
+ private bayesianOptimization;
3903
+ private acquisitionFunction;
3904
+ private explorationWeight;
3905
+ private sampleCount;
3906
+ private miproConfigHistory;
3907
+ private surrogateModel;
3908
+ constructor(args: Readonly<AxOptimizerArgs & {
3909
+ options?: AxMiPROOptimizerOptions;
4046
3910
  }>);
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
3911
  /**
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
3912
+ * Configures the optimizer for light, medium, or heavy optimization
3913
+ * @param level The optimization level: "light", "medium", or "heavy"
4162
3914
  */
4163
- send(message: Readonly<JSONRPCRequest<unknown>>): Promise<JSONRPCResponse<unknown>>;
3915
+ configureAuto(level: 'light' | 'medium' | 'heavy'): void;
4164
3916
  /**
4165
- * Sends a JSON-RPC notification
4166
- * @param message The JSON-RPC notification to send
3917
+ * Generates creative tips for instruction generation
4167
3918
  */
4168
- sendNotification(message: Readonly<JSONRPCNotification>): Promise<void>;
3919
+ private generateTips;
4169
3920
  /**
4170
- * Connects to the transport if needed
4171
- * This method is optional and only required for transports that need connection setup
3921
+ * Generates program summary for context-aware instruction generation
4172
3922
  */
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 {
3923
+ private generateProgramSummary;
4186
3924
  /**
4187
- * Custom headers to include with all HTTP requests
4188
- * Note: Content-Type, Accept, and Mcp-Session-Id are managed automatically
3925
+ * Generates dataset summary for context-aware instruction generation
4189
3926
  */
4190
- headers?: Record<string, string>;
3927
+ private generateDatasetSummary;
4191
3928
  /**
4192
- * Authorization header value (convenience for common use case)
4193
- * If provided, will be added to the headers as 'Authorization'
3929
+ * Enhanced instruction generation using AI with program and data awareness
4194
3930
  */
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);
3931
+ private generateInstruction;
4209
3932
  /**
4210
- * Update custom headers (useful for refreshing tokens)
3933
+ * Generates instruction candidates using enhanced AI-powered generation
3934
+ * @param options Optional compile options that may override teacher AI
3935
+ * @returns Array of generated instruction candidates
4211
3936
  */
4212
- setHeaders(headers: Record<string, string>): void;
3937
+ private proposeInstructionCandidates;
4213
3938
  /**
4214
- * Update authorization header (convenience method)
3939
+ * Bootstraps few-shot examples for the program
4215
3940
  */
4216
- setAuthorization(authorization: string): void;
3941
+ private bootstrapFewShotExamples;
4217
3942
  /**
4218
- * Get a copy of the current custom headers
3943
+ * Selects labeled examples directly from the training set
4219
3944
  */
4220
- getHeaders(): Record<string, string>;
3945
+ private selectLabeledExamples;
4221
3946
  /**
4222
- * Build headers for HTTP requests, merging custom headers with required ones
3947
+ * Runs optimization to find the best combination of few-shot examples and instructions
4223
3948
  */
4224
- private buildHeaders;
3949
+ private runOptimization;
3950
+ private evaluateConfig;
4225
3951
  /**
4226
- * Set a handler for incoming server messages (requests/notifications)
3952
+ * Fisher-Yates shuffle for stochastic evaluation
4227
3953
  */
4228
- setMessageHandler(handler: (message: JSONRPCRequest<unknown> | JSONRPCNotification) => void): void;
4229
- connect(): Promise<void>;
3954
+ private shuffleArray;
3955
+ private applyConfigToProgram;
4230
3956
  /**
4231
- * Opens an SSE stream to listen for server-initiated messages
3957
+ * The main compile method to run MIPROv2 optimization
4232
3958
  */
4233
- openListeningStream(): Promise<void>;
3959
+ compile(program: Readonly<AxProgram<IN, OUT>>, metricFn: AxMetricFn, options?: AxCompileOptions): Promise<AxMiPROResult<IN, OUT>>;
4234
3960
  /**
4235
- * Opens an SSE stream using fetch API to support custom headers
3961
+ * Applies a configuration to an AxGen instance
4236
3962
  */
4237
- private openListeningStreamWithFetch;
4238
- send(message: Readonly<JSONRPCRequest<unknown>>): Promise<JSONRPCResponse<unknown>>;
4239
- private handleSSEResponse;
4240
- sendNotification(message: Readonly<JSONRPCNotification>): Promise<void>;
3963
+ private applyConfigToAxGen;
4241
3964
  /**
4242
- * Explicitly terminate the session (if supported by server)
3965
+ * Get optimizer-specific configuration
3966
+ * @returns Current optimizer configuration
4243
3967
  */
4244
- terminateSession(): Promise<void>;
3968
+ getConfiguration(): Record<string, unknown>;
4245
3969
  /**
4246
- * Close any open connections
3970
+ * Update optimizer configuration
3971
+ * @param config New configuration to merge with existing
4247
3972
  */
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
- }>);
3973
+ updateConfiguration(config: Readonly<Record<string, unknown>>): void;
3974
+ /**
3975
+ * Reset optimizer state for reuse with different programs
3976
+ */
3977
+ reset(): void;
3978
+ /**
3979
+ * Validate that the optimizer can handle the given program
3980
+ * @param program Program to validate
3981
+ * @returns Validation result with any issues found
3982
+ */
3983
+ validateProgram(program: Readonly<AxProgram<IN, OUT>>): {
3984
+ isValid: boolean;
3985
+ issues: string[];
3986
+ suggestions: string[];
3987
+ };
3988
+ /**
3989
+ * Encodes a configuration into a string key for surrogate model lookup
3990
+ */
3991
+ private encodeConfiguration;
3992
+ /**
3993
+ * Updates the surrogate model with a new configuration-score pair
3994
+ */
3995
+ private updateSurrogateModel;
4279
3996
  /**
4280
- * Configures the optimizer for light, medium, or heavy optimization
4281
- * @param level The optimization level: "light", "medium", or "heavy"
3997
+ * Predicts performance using the surrogate model
4282
3998
  */
4283
- configureAuto(level: 'light' | 'medium' | 'heavy'): void;
3999
+ private predictPerformance;
4284
4000
  /**
4285
- * Generates creative tips for instruction generation
4001
+ * Calculates acquisition function value for Bayesian optimization
4286
4002
  */
4287
- private generateTips;
4003
+ private calculateAcquisitionValue;
4288
4004
  /**
4289
- * Generates program summary for context-aware instruction generation
4005
+ * Error function approximation for acquisition function calculations
4290
4006
  */
4291
- private generateProgramSummary;
4007
+ private erf;
4292
4008
  /**
4293
- * Generates dataset summary for context-aware instruction generation
4009
+ * Selects the next configuration to evaluate using Bayesian optimization
4294
4010
  */
4295
- private generateDatasetSummary;
4011
+ private selectConfigurationViaBayesianOptimization;
4012
+ }
4013
+
4014
+ type AxInstanceRegistryItem<T extends AxTunable<IN, OUT>, IN extends AxGenIn, OUT extends AxGenOut> = T & AxUsable;
4015
+ declare class AxInstanceRegistry<T extends AxTunable<IN, OUT>, IN extends AxGenIn, OUT extends AxGenOut> {
4016
+ private reg;
4017
+ constructor();
4018
+ register(instance: AxInstanceRegistryItem<T, IN, OUT>): void;
4019
+ [Symbol.iterator](): Generator<AxInstanceRegistryItem<T, IN, OUT>, void, unknown>;
4020
+ }
4021
+
4022
+ interface AxSamplePickerOptions<OUT extends AxGenOut> {
4023
+ resultPicker?: AxResultPickerFunction<OUT>;
4024
+ }
4025
+
4026
+ declare const AxStringUtil: {
4027
+ trimNonAlphaNum: (str: string) => string;
4028
+ splitIntoTwo: (str: string, separator: Readonly<RegExp | string>) => string[];
4029
+ dedup: (seq: readonly string[]) => string[];
4030
+ extractIdAndText: (input: string) => {
4031
+ id: number;
4032
+ text: string;
4033
+ };
4034
+ extractIndexPrefixedText: (input: string) => string;
4035
+ batchArray: <T>(arr: readonly T[], size: number) => T[][];
4036
+ };
4037
+
4038
+ type AxSignatureTemplateValue = string | AxFieldType | AxFieldDescriptor | AxSignature;
4039
+ interface AxFieldType {
4040
+ readonly type: 'string' | 'number' | 'boolean' | 'json' | 'image' | 'audio' | 'date' | 'datetime' | 'class' | 'code';
4041
+ readonly isArray?: boolean;
4042
+ readonly options?: readonly string[];
4043
+ readonly description?: string;
4044
+ readonly isOptional?: boolean;
4045
+ readonly isInternal?: boolean;
4046
+ }
4047
+ interface AxFieldDescriptor {
4048
+ readonly name: string;
4049
+ readonly type?: AxFieldType;
4050
+ readonly description?: string;
4051
+ readonly isOptional?: boolean;
4052
+ readonly isInternal?: boolean;
4053
+ }
4054
+ declare function s(strings: TemplateStringsArray, ...values: readonly AxSignatureTemplateValue[]): AxSignature;
4055
+ declare function ax<IN extends AxGenIn = AxGenIn, OUT extends AxGenerateResult<AxGenOut> = AxGenerateResult<AxGenOut>>(strings: TemplateStringsArray, ...values: readonly AxSignatureTemplateValue[]): AxGen<IN, OUT>;
4056
+ declare const f: {
4057
+ string: (desc?: string) => AxFieldType;
4058
+ number: (desc?: string) => AxFieldType;
4059
+ boolean: (desc?: string) => AxFieldType;
4060
+ date: (desc?: string) => AxFieldType;
4061
+ datetime: (desc?: string) => AxFieldType;
4062
+ json: (desc?: string) => AxFieldType;
4063
+ image: (desc?: string) => AxFieldType;
4064
+ audio: (desc?: string) => AxFieldType;
4065
+ class: (options: readonly string[], desc?: string) => AxFieldType;
4066
+ code: (language: string, desc?: string) => AxFieldType;
4067
+ array: <T extends AxFieldType>(baseType: T) => T & {
4068
+ readonly isArray: true;
4069
+ };
4070
+ optional: <T extends AxFieldType>(baseType: T) => T & {
4071
+ readonly isOptional: true;
4072
+ };
4073
+ internal: <T extends AxFieldType>(baseType: T) => T & {
4074
+ readonly isInternal: true;
4075
+ };
4076
+ };
4077
+
4078
+ type AxFlowState = Record<string, unknown>;
4079
+ type AxFlowStepFunction = (state: AxFlowState, context: Readonly<{
4080
+ mainAi: AxAIService;
4081
+ mainOptions?: AxProgramForwardOptions;
4082
+ }>) => Promise<AxFlowState> | AxFlowState;
4083
+ interface AxFlowDynamicContext {
4084
+ ai?: AxAIService;
4085
+ options?: AxProgramForwardOptions;
4086
+ }
4087
+ type GetGenIn<T extends AxGen<AxGenIn, AxGenOut>> = T extends AxGen<infer IN, AxGenOut> ? IN : never;
4088
+ type GetGenOut<T extends AxGen<AxGenIn, AxGenOut>> = T extends AxGen<AxGenIn, infer OUT> ? OUT : never;
4089
+ type InferAxGen<TSig extends string> = TSig extends string ? AxGen<AxGenIn, AxGenOut> : never;
4090
+ type NodeResultKey<TNodeName extends string> = `${TNodeName}Result`;
4091
+ type AddNodeResult<TState extends AxFlowState, TNodeName extends string, TNodeOut extends AxGenOut> = TState & {
4092
+ [K in NodeResultKey<TNodeName>]: TNodeOut;
4093
+ };
4094
+ type AxFlowTypedParallelBranch<TNodes extends Record<string, AxGen<any, any>>, TState extends AxFlowState> = (subFlow: AxFlowTypedSubContext<TNodes, TState>) => AxFlowTypedSubContext<TNodes, AxFlowState>;
4095
+ interface AxFlowTypedSubContext<TNodes extends Record<string, AxGen<any, any>>, TState extends AxFlowState> {
4096
+ execute<TNodeName extends keyof TNodes & string>(nodeName: TNodeName, mapping: (state: TState) => GetGenIn<TNodes[TNodeName]>, dynamicContext?: AxFlowDynamicContext): AxFlowTypedSubContext<TNodes, AddNodeResult<TState, TNodeName, GetGenOut<TNodes[TNodeName]>>>;
4097
+ map<TNewState extends AxFlowState>(transform: (state: TState) => TNewState): AxFlowTypedSubContext<TNodes, TNewState>;
4098
+ executeSteps(initialState: TState, context: Readonly<{
4099
+ mainAi: AxAIService;
4100
+ mainOptions?: AxProgramForwardOptions;
4101
+ }>): Promise<AxFlowState>;
4102
+ }
4103
+ type AxFlowParallelBranch = (subFlow: AxFlowSubContext) => AxFlowSubContext;
4104
+ interface AxFlowSubContext {
4105
+ execute(nodeName: string, mapping: (state: AxFlowState) => Record<string, AxFieldValue>, dynamicContext?: AxFlowDynamicContext): this;
4106
+ map(transform: (state: AxFlowState) => AxFlowState): this;
4107
+ executeSteps(initialState: AxFlowState, context: Readonly<{
4108
+ mainAi: AxAIService;
4109
+ mainOptions?: AxProgramForwardOptions;
4110
+ }>): Promise<AxFlowState>;
4111
+ }
4112
+ interface AxFlowExecutionStep {
4113
+ type: 'execute' | 'map' | 'other';
4114
+ nodeName?: string;
4115
+ dependencies: string[];
4116
+ produces: string[];
4117
+ stepFunction: AxFlowStepFunction;
4118
+ stepIndex: number;
4119
+ }
4120
+ interface AxFlowParallelGroup {
4121
+ level: number;
4122
+ steps: AxFlowExecutionStep[];
4123
+ }
4124
+ /**
4125
+ * AxFlow - A fluent, chainable API for building and orchestrating complex, stateful AI programs.
4126
+ *
4127
+ * Now with advanced type-safe chaining where each method call evolves the type information,
4128
+ * providing compile-time type safety and superior IntelliSense.
4129
+ *
4130
+ * @example
4131
+ * ```typescript
4132
+ * const flow = new AxFlow<{ topic: string }, { finalAnswer: string }>()
4133
+ * .node('summarizer', 'text:string -> summary:string')
4134
+ * .node('critic', 'summary:string -> critique:string')
4135
+ * .execute('summarizer', state => ({ text: `About ${state.topic}` })) // state is { topic: string }
4136
+ * .execute('critic', state => ({ summary: state.summarizerResult.summary })) // state evolves!
4137
+ * .map(state => ({ finalAnswer: state.criticResult.critique })) // fully typed!
4138
+ *
4139
+ * const result = await flow.forward(ai, { topic: "AI safety" })
4140
+ * ```
4141
+ */
4142
+ declare class AxFlow<IN extends AxGenIn, OUT extends AxGenOut, TNodes extends Record<string, AxGen<any, any>> = Record<string, never>, // Node registry for type tracking
4143
+ TState extends AxFlowState = IN> extends AxProgram<IN, OUT> {
4144
+ private readonly nodes;
4145
+ private readonly flowDefinition;
4146
+ private readonly nodeGenerators;
4147
+ private readonly loopStack;
4148
+ private readonly stepLabels;
4149
+ private branchContext;
4150
+ private readonly autoParallelConfig;
4151
+ private readonly executionPlanner;
4152
+ constructor(signature?: NonNullable<ConstructorParameters<typeof AxSignature>[0]>, options?: {
4153
+ autoParallel?: boolean;
4154
+ });
4296
4155
  /**
4297
- * Enhanced instruction generation using AI with program and data awareness
4156
+ * Declares a reusable computational node using a signature string.
4157
+ * Returns a new AxFlow type that tracks this node in the TNodes registry.
4158
+ *
4159
+ * @param name - The name of the node
4160
+ * @param signature - Signature string in the same format as AxSignature
4161
+ * @param options - Optional program forward options (same as AxGen)
4162
+ * @returns New AxFlow instance with updated TNodes type
4163
+ *
4164
+ * @example
4165
+ * ```typescript
4166
+ * flow.node('summarizer', 'text:string -> summary:string')
4167
+ * flow.node('analyzer', 'text:string -> analysis:string, confidence:number', { debug: true })
4168
+ * ```
4298
4169
  */
4299
- private generateInstruction;
4170
+ node<TName extends string, TSig extends string>(name: TName, signature: TSig, options?: Readonly<AxProgramForwardOptions>): AxFlow<IN, OUT, TNodes & {
4171
+ [K in TName]: InferAxGen<TSig>;
4172
+ }, // Add new node to registry
4173
+ TState>;
4300
4174
  /**
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
4175
+ * Declares a reusable computational node using an AxSignature instance.
4176
+ * This allows using pre-configured signatures in the flow.
4177
+ *
4178
+ * @param name - The name of the node
4179
+ * @param signature - AxSignature instance to use for this node
4180
+ * @param options - Optional program forward options (same as AxGen)
4181
+ * @returns New AxFlow instance with updated TNodes type
4182
+ *
4183
+ * @example
4184
+ * ```typescript
4185
+ * const sig = new AxSignature('text:string -> summary:string')
4186
+ * flow.node('summarizer', sig, { temperature: 0.1 })
4187
+ * ```
4304
4188
  */
4305
- private proposeInstructionCandidates;
4189
+ node<TName extends string>(name: TName, signature: AxSignature, options?: Readonly<AxProgramForwardOptions>): AxFlow<IN, OUT, TNodes & {
4190
+ [K in TName]: AxGen<AxGenIn, AxGenOut>;
4191
+ }, // Add new node to registry
4192
+ TState>;
4306
4193
  /**
4307
- * Bootstraps few-shot examples for the program
4194
+ * Declares a reusable computational node using an existing AxGen instance.
4195
+ * This allows reusing pre-configured generators in the flow.
4196
+ *
4197
+ * @param name - The name of the node
4198
+ * @param axgenInstance - Existing AxGen instance to use for this node
4199
+ * @returns New AxFlow instance with updated TNodes type
4200
+ *
4201
+ * @example
4202
+ * ```typescript
4203
+ * const summarizer = new AxGen('text:string -> summary:string', { temperature: 0.1 })
4204
+ * flow.node('summarizer', summarizer)
4205
+ * ```
4308
4206
  */
4309
- private bootstrapFewShotExamples;
4207
+ node<TName extends string, TGen extends AxGen<any, any>>(name: TName, axgenInstance: TGen): AxFlow<IN, OUT, TNodes & {
4208
+ [K in TName]: TGen;
4209
+ }, // Add new node to registry with exact type
4210
+ TState>;
4310
4211
  /**
4311
- * Selects labeled examples directly from the training set
4212
+ * Declares a reusable computational node using a class that extends AxProgram.
4213
+ * This allows using custom program classes in the flow.
4214
+ *
4215
+ * @param name - The name of the node
4216
+ * @param programClass - Class that extends AxProgram to use for this node
4217
+ * @returns New AxFlow instance with updated TNodes type
4218
+ *
4219
+ * @example
4220
+ * ```typescript
4221
+ * class CustomProgram extends AxProgram<{ input: string }, { output: string }> {
4222
+ * async forward(ai, values) { return { output: values.input.toUpperCase() } }
4223
+ * }
4224
+ * flow.node('custom', CustomProgram)
4225
+ * ```
4312
4226
  */
4313
- private selectLabeledExamples;
4227
+ node<TName extends string, TProgram extends new () => AxProgram<any, any>>(name: TName, programClass: TProgram): AxFlow<IN, OUT, TNodes & {
4228
+ [K in TName]: InstanceType<TProgram>;
4229
+ }, // Add new node to registry with exact type
4230
+ TState>;
4314
4231
  /**
4315
- * Runs optimization to find the best combination of few-shot examples and instructions
4232
+ * Short alias for node() - supports signature strings, AxSignature instances, AxGen instances, and program classes
4316
4233
  */
4317
- private runOptimization;
4318
- private evaluateConfig;
4234
+ n<TName extends string, TSig extends string>(name: TName, signature: TSig, options?: Readonly<AxProgramForwardOptions>): AxFlow<IN, OUT, TNodes & {
4235
+ [K in TName]: InferAxGen<TSig>;
4236
+ }, TState>;
4237
+ n<TName extends string>(name: TName, signature: AxSignature, options?: Readonly<AxProgramForwardOptions>): AxFlow<IN, OUT, TNodes & {
4238
+ [K in TName]: AxGen<AxGenIn, AxGenOut>;
4239
+ }, TState>;
4240
+ n<TName extends string, TGen extends AxGen<any, any>>(name: TName, axgenInstance: TGen): AxFlow<IN, OUT, TNodes & {
4241
+ [K in TName]: TGen;
4242
+ }, TState>;
4243
+ n<TName extends string, TProgram extends new () => AxProgram<any, any>>(name: TName, programClass: TProgram): AxFlow<IN, OUT, TNodes & {
4244
+ [K in TName]: InstanceType<TProgram>;
4245
+ }, TState>;
4319
4246
  /**
4320
- * Fisher-Yates shuffle for stochastic evaluation
4247
+ * Applies a synchronous transformation to the state object.
4248
+ * Returns a new AxFlow type with the evolved state.
4249
+ *
4250
+ * @param transform - Function that takes the current state and returns a new state
4251
+ * @returns New AxFlow instance with updated TState type
4252
+ *
4253
+ * @example
4254
+ * ```typescript
4255
+ * flow.map(state => ({ ...state, processedText: state.text.toLowerCase() }))
4256
+ * ```
4321
4257
  */
4322
- private shuffleArray;
4323
- private applyConfigToProgram;
4258
+ map<TNewState extends AxFlowState>(transform: (state: TState) => TNewState): AxFlow<IN, OUT, TNodes, TNewState>;
4324
4259
  /**
4325
- * The main compile method to run MIPROv2 optimization
4260
+ * Short alias for map()
4326
4261
  */
4327
- compile(program: Readonly<AxProgram<IN, OUT>>, metricFn: AxMetricFn, options?: AxCompileOptions): Promise<AxMiPROResult<IN, OUT>>;
4262
+ m<TNewState extends AxFlowState>(transform: (state: TState) => TNewState): AxFlow<IN, OUT, TNodes, TNewState>;
4328
4263
  /**
4329
- * Applies a configuration to an AxGen instance
4264
+ * Labels a step for later reference (useful for feedback loops).
4265
+ *
4266
+ * @param label - The label to assign to the current step position
4267
+ * @returns this (for chaining, no type change)
4268
+ *
4269
+ * @example
4270
+ * ```typescript
4271
+ * flow.label('retry-point')
4272
+ * .execute('queryGen', ...)
4273
+ * ```
4330
4274
  */
4331
- private applyConfigToAxGen;
4275
+ label(label: string): this;
4332
4276
  /**
4333
- * Get optimizer-specific configuration
4334
- * @returns Current optimizer configuration
4277
+ * Short alias for label()
4335
4278
  */
4336
- getConfiguration(): Record<string, unknown>;
4279
+ l(label: string): this;
4337
4280
  /**
4338
- * Update optimizer configuration
4339
- * @param config New configuration to merge with existing
4281
+ * Executes a previously defined node with full type safety.
4282
+ * The node name must exist in TNodes, and the mapping function is typed based on the node's signature.
4283
+ *
4284
+ * @param nodeName - The name of the node to execute (must exist in TNodes)
4285
+ * @param mapping - Typed function that takes the current state and returns the input for the node
4286
+ * @param dynamicContext - Optional object to override the AI service or options for this specific step
4287
+ * @returns New AxFlow instance with TState augmented with the node's result
4288
+ *
4289
+ * @example
4290
+ * ```typescript
4291
+ * flow.execute('summarizer', state => ({ text: state.originalText }), { ai: cheapAI })
4292
+ * ```
4340
4293
  */
4341
- updateConfiguration(config: Readonly<Record<string, unknown>>): void;
4294
+ 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
4295
  /**
4343
- * Reset optimizer state for reuse with different programs
4296
+ * Short alias for execute()
4344
4297
  */
4345
- reset(): void;
4298
+ 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
4299
  /**
4347
- * Validate that the optimizer can handle the given program
4348
- * @param program Program to validate
4349
- * @returns Validation result with any issues found
4300
+ * Starts a conditional branch based on a predicate function.
4301
+ *
4302
+ * @param predicate - Function that takes state and returns a value to branch on
4303
+ * @returns this (for chaining)
4304
+ *
4305
+ * @example
4306
+ * ```typescript
4307
+ * flow.branch(state => state.qualityResult.needsMoreInfo)
4308
+ * .when(true)
4309
+ * .execute('queryGen', ...)
4310
+ * .when(false)
4311
+ * .execute('answer', ...)
4312
+ * .merge()
4313
+ * ```
4350
4314
  */
4351
- validateProgram(program: Readonly<AxProgram<IN, OUT>>): {
4352
- isValid: boolean;
4353
- issues: string[];
4354
- suggestions: string[];
4355
- };
4315
+ branch(predicate: (state: TState) => unknown): this;
4356
4316
  /**
4357
- * Encodes a configuration into a string key for surrogate model lookup
4317
+ * Short alias for branch()
4358
4318
  */
4359
- private encodeConfiguration;
4319
+ b(predicate: (state: TState) => unknown): this;
4360
4320
  /**
4361
- * Updates the surrogate model with a new configuration-score pair
4321
+ * Defines a branch case for the current branch context.
4322
+ *
4323
+ * @param value - The value to match against the branch predicate result
4324
+ * @returns this (for chaining)
4362
4325
  */
4363
- private updateSurrogateModel;
4326
+ when(value: unknown): this;
4364
4327
  /**
4365
- * Predicts performance using the surrogate model
4328
+ * Short alias for when()
4366
4329
  */
4367
- private predictPerformance;
4330
+ w(value: unknown): this;
4368
4331
  /**
4369
- * Calculates acquisition function value for Bayesian optimization
4332
+ * Ends the current branch and merges all branch paths back into the main flow.
4333
+ * Optionally specify the explicit merged state type for better type safety.
4334
+ *
4335
+ * @param explicitMergedType - Optional type hint for the merged state (defaults to current TState)
4336
+ * @returns AxFlow instance with the merged state type
4337
+ *
4338
+ * @example
4339
+ * ```typescript
4340
+ * // Default behavior - preserves current TState
4341
+ * flow.branch(state => state.type)
4342
+ * .when('simple').execute('simpleProcessor', ...)
4343
+ * .when('complex').execute('complexProcessor', ...)
4344
+ * .merge()
4345
+ *
4346
+ * // Explicit type - specify exact merged state shape
4347
+ * flow.branch(state => state.type)
4348
+ * .when('simple').map(state => ({ result: state.simpleResult, method: 'simple' }))
4349
+ * .when('complex').map(state => ({ result: state.complexResult, method: 'complex' }))
4350
+ * .merge<{ result: string; method: string }>()
4351
+ * ```
4370
4352
  */
4371
- private calculateAcquisitionValue;
4353
+ merge<TMergedState extends AxFlowState = TState>(): AxFlow<IN, OUT, TNodes, TMergedState>;
4372
4354
  /**
4373
- * Error function approximation for acquisition function calculations
4355
+ * Short alias for merge()
4374
4356
  */
4375
- private erf;
4357
+ mg<TMergedState extends AxFlowState = TState>(): AxFlow<IN, OUT, TNodes, TMergedState>;
4376
4358
  /**
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;
4359
+ * Executes multiple operations in parallel and merges their results.
4360
+ * Both typed and legacy untyped branches are supported.
4361
+ *
4362
+ * @param branches - Array of functions that define parallel operations
4363
+ * @returns Object with merge method for combining results
4364
+ *
4365
+ * @example
4366
+ * ```typescript
4367
+ * flow.parallel([
4368
+ * subFlow => subFlow.execute('retrieve1', state => ({ query: state.query1 })),
4369
+ * subFlow => subFlow.execute('retrieve2', state => ({ query: state.query2 })),
4370
+ * subFlow => subFlow.execute('retrieve3', state => ({ query: state.query3 }))
4371
+ * ]).merge('documents', (docs1, docs2, docs3) => [...docs1, ...docs2, ...docs3])
4372
+ * ```
4373
+ */
4374
+ parallel(branches: (AxFlowParallelBranch | AxFlowTypedParallelBranch<TNodes, TState>)[]): {
4375
+ merge<T, TResultKey extends string>(resultKey: TResultKey, mergeFunction: (...results: unknown[]) => T): AxFlow<IN, OUT, TNodes, TState & {
4376
+ [K in TResultKey]: T;
4377
+ }>;
4508
4378
  };
4509
- optional: <T extends AxFieldType>(baseType: T) => T & {
4510
- readonly isOptional: true;
4379
+ /**
4380
+ * Short alias for parallel()
4381
+ */
4382
+ p(branches: (AxFlowParallelBranch | AxFlowTypedParallelBranch<TNodes, TState>)[]): {
4383
+ merge<T, TResultKey extends string>(resultKey: TResultKey, mergeFunction: (...results: unknown[]) => T): AxFlow<IN, OUT, TNodes, TState & {
4384
+ [K in TResultKey]: T;
4385
+ }>;
4511
4386
  };
4512
- internal: <T extends AxFieldType>(baseType: T) => T & {
4513
- readonly isInternal: true;
4387
+ /**
4388
+ * Creates a feedback loop that jumps back to a labeled step if a condition is met.
4389
+ *
4390
+ * @param condition - Function that returns true to trigger the feedback loop
4391
+ * @param targetLabel - The label to jump back to
4392
+ * @param maxIterations - Maximum number of iterations to prevent infinite loops (default: 10)
4393
+ * @returns this (for chaining)
4394
+ *
4395
+ * @example
4396
+ * ```typescript
4397
+ * flow.label('retry-point')
4398
+ * .execute('answer', ...)
4399
+ * .execute('qualityCheck', ...)
4400
+ * .feedback(state => state.qualityCheckResult.confidence < 0.7, 'retry-point')
4401
+ * ```
4402
+ */
4403
+ feedback(condition: (state: TState) => boolean, targetLabel: string, maxIterations?: number): this;
4404
+ /**
4405
+ * Short alias for feedback()
4406
+ */
4407
+ fb(condition: (state: TState) => boolean, targetLabel: string, maxIterations?: number): this;
4408
+ /**
4409
+ * Marks the beginning of a loop block.
4410
+ *
4411
+ * @param condition - Function that takes the current state and returns a boolean
4412
+ * @param maxIterations - Maximum number of iterations to prevent infinite loops (default: 100)
4413
+ * @returns this (for chaining)
4414
+ *
4415
+ * @example
4416
+ * ```typescript
4417
+ * flow.while(state => state.iterations < 3, 10)
4418
+ * .map(state => ({ ...state, iterations: (state.iterations || 0) + 1 }))
4419
+ * .endWhile()
4420
+ * ```
4421
+ */
4422
+ while(condition: (state: TState) => boolean, maxIterations?: number): this;
4423
+ /**
4424
+ * Short alias for while()
4425
+ */
4426
+ wh(condition: (state: TState) => boolean, maxIterations?: number): this;
4427
+ /**
4428
+ * Marks the end of a loop block.
4429
+ *
4430
+ * @returns this (for chaining)
4431
+ */
4432
+ endWhile(): this;
4433
+ /**
4434
+ * Short alias for endWhile()
4435
+ */
4436
+ end(): this;
4437
+ /**
4438
+ * Executes the flow with the given AI service and input values.
4439
+ *
4440
+ * @param ai - The AI service to use as the default for all steps
4441
+ * @param values - The input values for the flow
4442
+ * @param options - Optional forward options to use as defaults (includes autoParallel override)
4443
+ * @returns Promise that resolves to the final output
4444
+ */
4445
+ forward(ai: Readonly<AxAIService>, values: IN, options?: Readonly<AxProgramForwardOptions & {
4446
+ autoParallel?: boolean;
4447
+ }>): Promise<OUT>;
4448
+ /**
4449
+ * Gets execution plan information for debugging automatic parallelization
4450
+ *
4451
+ * @returns Object with execution plan details
4452
+ */
4453
+ getExecutionPlan(): {
4454
+ totalSteps: number;
4455
+ parallelGroups: number;
4456
+ maxParallelism: number;
4457
+ autoParallelEnabled: boolean;
4458
+ steps?: AxFlowExecutionStep[];
4459
+ groups?: AxFlowParallelGroup[];
4514
4460
  };
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
4461
  }
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
4462
  /**
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
4463
+ * Typed implementation of the sub-context for parallel execution with full type safety
4599
4464
  */
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>>;
4465
+ declare class AxFlowTypedSubContextImpl<TNodes extends Record<string, AxGen<any, any>>, TState extends AxFlowState> implements AxFlowTypedSubContext<TNodes, TState> {
4466
+ private readonly nodeGenerators;
4467
+ private readonly steps;
4468
+ constructor(nodeGenerators: Map<string, AxGen<AxGenIn, AxGenOut> | AxProgram<AxGenIn, AxGenOut>>);
4469
+ execute<TNodeName extends keyof TNodes & string>(nodeName: TNodeName, mapping: (state: TState) => GetGenIn<TNodes[TNodeName]>, dynamicContext?: AxFlowDynamicContext): AxFlowTypedSubContext<TNodes, AddNodeResult<TState, TNodeName, GetGenOut<TNodes[TNodeName]>>>;
4470
+ map<TNewState extends AxFlowState>(transform: (state: TState) => TNewState): AxFlowTypedSubContext<TNodes, TNewState>;
4471
+ executeSteps(initialState: TState, context: Readonly<{
4472
+ mainAi: AxAIService;
4473
+ mainOptions?: AxProgramForwardOptions;
4474
+ }>): Promise<AxFlowState>;
4640
4475
  }
4641
4476
 
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
- }>);
4477
+ interface AxDockerContainer {
4478
+ Id: string;
4479
+ Names: string[];
4480
+ Image: string;
4481
+ ImageID: string;
4482
+ Command: string;
4483
+ Created: number;
4484
+ State: {
4485
+ Status: string;
4486
+ Running: boolean;
4487
+ Paused: boolean;
4488
+ Restarting: boolean;
4489
+ OOMKilled: boolean;
4490
+ Dead: boolean;
4491
+ Pid: number;
4492
+ ExitCode: number;
4493
+ Error: string;
4494
+ StartedAt: Date;
4495
+ FinishedAt: Date;
4496
+ };
4497
+ Status: string;
4498
+ Ports: Array<{
4499
+ IP: string;
4500
+ PrivatePort: number;
4501
+ PublicPort: number;
4502
+ Type: string;
4503
+ }>;
4504
+ Labels: {
4505
+ [key: string]: string;
4506
+ };
4507
+ SizeRw: number;
4508
+ SizeRootFs: number;
4509
+ HostConfig: {
4510
+ NetworkMode: string;
4511
+ };
4512
+ NetworkSettings: {
4513
+ Networks: {
4514
+ [key: string]: {
4515
+ IPAddress: string;
4516
+ IPPrefixLen: number;
4517
+ Gateway: string;
4518
+ MacAddress: string;
4519
+ };
4520
+ };
4521
+ };
4522
+ Mounts: Array<{
4523
+ Type: string;
4524
+ Source: string;
4525
+ Destination: string;
4526
+ Mode: string;
4527
+ RW: boolean;
4528
+ Propagation: string;
4529
+ }>;
4646
4530
  }
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>;
4531
+ declare class AxDockerSession {
4532
+ private readonly apiUrl;
4533
+ private containerId;
4534
+ constructor(apiUrl?: string);
4535
+ pullImage(imageName: string): Promise<void>;
4536
+ createContainer({ imageName, volumes, doNotPullImage, tag, }: Readonly<{
4537
+ imageName: string;
4538
+ volumes?: Array<{
4539
+ hostPath: string;
4540
+ containerPath: string;
4541
+ }>;
4542
+ doNotPullImage?: boolean;
4543
+ tag?: string;
4544
+ }>): Promise<{
4545
+ Id: string;
4546
+ }>;
4547
+ findOrCreateContainer({ imageName, volumes, doNotPullImage, tag, }: Readonly<{
4548
+ imageName: string;
4549
+ volumes?: Array<{
4550
+ hostPath: string;
4551
+ containerPath: string;
4552
+ }>;
4553
+ doNotPullImage?: boolean;
4554
+ tag: string;
4555
+ }>): Promise<{
4556
+ Id: string;
4557
+ isNew: boolean;
4558
+ }>;
4559
+ startContainer(): Promise<void>;
4560
+ connectToContainer(containerId: string): Promise<void>;
4561
+ stopContainers({ tag, remove, timeout, }: Readonly<{
4562
+ tag?: string;
4563
+ remove?: boolean;
4564
+ timeout?: number;
4565
+ }>): Promise<Array<{
4566
+ Id: string;
4567
+ Action: 'stopped' | 'removed';
4568
+ }>>;
4569
+ listContainers(all?: boolean): Promise<AxDockerContainer[]>;
4570
+ getContainerLogs(): Promise<string>;
4571
+ executeCommand(command: string): Promise<string>;
4572
+ private getContainerInfo;
4573
+ private waitForContainerToBeRunning;
4574
+ private fetchDockerAPI;
4575
+ toFunction(): AxFunction;
4651
4576
  }
4652
4577
 
4653
4578
  declare class AxEmbeddingAdapter {
@@ -4667,55 +4592,50 @@ declare class AxEmbeddingAdapter {
4667
4592
  toFunction(): AxFunction;
4668
4593
  }
4669
4594
 
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
- };
4595
+ interface JSONRPCRequest<T> {
4596
+ jsonrpc: '2.0';
4597
+ id: string | number;
4598
+ method: string;
4599
+ params?: T;
4600
+ }
4601
+ interface JSONRPCSuccessResponse<T = unknown> {
4602
+ jsonrpc: '2.0';
4603
+ id: string | number;
4604
+ result: T;
4605
+ }
4606
+ interface JSONRPCErrorResponse {
4607
+ jsonrpc: '2.0';
4608
+ id: string | number;
4609
+ error: {
4610
+ code: number;
4611
+ message: string;
4612
+ data?: unknown;
4613
+ };
4614
+ }
4615
+ type JSONRPCResponse<T = unknown> = JSONRPCSuccessResponse<T> | JSONRPCErrorResponse;
4616
+ interface JSONRPCNotification {
4617
+ jsonrpc: '2.0';
4618
+ method: string;
4619
+ params?: Record<string, unknown>;
4620
+ }
4712
4621
 
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>;
4622
+ interface AxMCPTransport {
4623
+ /**
4624
+ * Sends a JSON-RPC request or notification and returns the response
4625
+ * @param message The JSON-RPC request or notification to send
4626
+ * @returns A Promise that resolves to the JSON-RPC response
4627
+ */
4628
+ send(message: Readonly<JSONRPCRequest<unknown>>): Promise<JSONRPCResponse<unknown>>;
4629
+ /**
4630
+ * Sends a JSON-RPC notification
4631
+ * @param message The JSON-RPC notification to send
4632
+ */
4633
+ sendNotification(message: Readonly<JSONRPCNotification>): Promise<void>;
4634
+ /**
4635
+ * Connects to the transport if needed
4636
+ * This method is optional and only required for transports that need connection setup
4637
+ */
4638
+ connect?(): Promise<void>;
4719
4639
  }
4720
4640
 
4721
4641
  /**
@@ -4777,89 +4697,173 @@ declare class AxMCPClient {
4777
4697
  private sendNotification;
4778
4698
  }
4779
4699
 
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>;
4700
+ declare class AxMCPHTTPSSETransport implements AxMCPTransport {
4701
+ private endpoint;
4702
+ private sseUrl;
4703
+ private eventSource?;
4704
+ constructor(sseUrl: string);
4792
4705
  connect(): Promise<void>;
4706
+ send(message: JSONRPCRequest<unknown> | JSONRPCNotification): Promise<JSONRPCResponse<unknown>>;
4707
+ sendNotification(message: Readonly<JSONRPCNotification>): Promise<void>;
4793
4708
  }
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;
4709
+ interface AxMCPStreamableHTTPTransportOptions {
4805
4710
  /**
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.
4711
+ * Custom headers to include with all HTTP requests
4712
+ * Note: Content-Type, Accept, and Mcp-Session-Id are managed automatically
4809
4713
  */
4810
- constructor(services: (AxAIServiceListItem<string, string> | AxAIService<string, string>)[]);
4811
- getLastUsedChatModel(): string | undefined;
4812
- getLastUsedEmbedModel(): string | undefined;
4813
- getLastUsedModelConfig(): AxModelConfig | undefined;
4714
+ headers?: Record<string, string>;
4814
4715
  /**
4815
- * Delegates the chat call to the service matching the provided model key.
4716
+ * Authorization header value (convenience for common use case)
4717
+ * If provided, will be added to the headers as 'Authorization'
4816
4718
  */
4817
- chat(req: Readonly<AxChatRequest<string>>, options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions<string, string>>): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
4719
+ authorization?: string;
4720
+ }
4721
+ /**
4722
+ * AxMCPStreambleHTTPTransport implements the 2025-03-26 Streamable HTTP transport specification
4723
+ * This transport uses a single HTTP endpoint that supports both POST and GET methods
4724
+ */
4725
+ declare class AxMCPStreambleHTTPTransport implements AxMCPTransport {
4726
+ private mcpEndpoint;
4727
+ private sessionId?;
4728
+ private eventSource?;
4729
+ private pendingRequests;
4730
+ private messageHandler?;
4731
+ private customHeaders;
4732
+ constructor(mcpEndpoint: string, options?: AxMCPStreamableHTTPTransportOptions);
4818
4733
  /**
4819
- * Delegates the embed call to the service matching the provided embed model key.
4734
+ * Update custom headers (useful for refreshing tokens)
4820
4735
  */
4821
- embed(req: Readonly<AxEmbedRequest<string>>, options?: Readonly<AxAIServiceActionOptions<string, string>>): Promise<AxEmbedResponse>;
4736
+ setHeaders(headers: Record<string, string>): void;
4822
4737
  /**
4823
- * Returns a composite ID built from the IDs of the underlying services.
4738
+ * Update authorization header (convenience method)
4824
4739
  */
4825
- getId(): string;
4740
+ setAuthorization(authorization: string): void;
4826
4741
  /**
4827
- * Returns the name of this router.
4742
+ * Get a copy of the current custom headers
4828
4743
  */
4829
- getName(): string;
4744
+ getHeaders(): Record<string, string>;
4830
4745
  /**
4831
- * Aggregates all available models across the underlying services.
4746
+ * Build headers for HTTP requests, merging custom headers with required ones
4832
4747
  */
4833
- getModelList(): AxAIModelList;
4748
+ private buildHeaders;
4834
4749
  /**
4835
- * If a model key is provided, delegate to the corresponding service's features.
4836
- * Otherwise, returns a default feature set.
4750
+ * Set a handler for incoming server messages (requests/notifications)
4751
+ */
4752
+ setMessageHandler(handler: (message: JSONRPCRequest<unknown> | JSONRPCNotification) => void): void;
4753
+ connect(): Promise<void>;
4754
+ /**
4755
+ * Opens an SSE stream to listen for server-initiated messages
4756
+ */
4757
+ openListeningStream(): Promise<void>;
4758
+ /**
4759
+ * Opens an SSE stream using fetch API to support custom headers
4837
4760
  */
4838
- getFeatures(model?: string): {
4839
- functions: boolean;
4840
- streaming: boolean;
4841
- functionCot?: boolean;
4842
- };
4761
+ private openListeningStreamWithFetch;
4762
+ send(message: Readonly<JSONRPCRequest<unknown>>): Promise<JSONRPCResponse<unknown>>;
4763
+ private handleSSEResponse;
4764
+ sendNotification(message: Readonly<JSONRPCNotification>): Promise<void>;
4843
4765
  /**
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.
4766
+ * Explicitly terminate the session (if supported by server)
4847
4767
  */
4848
- getMetrics(): AxAIServiceMetrics;
4768
+ terminateSession(): Promise<void>;
4849
4769
  /**
4850
- * Sets options on all underlying services.
4770
+ * Close any open connections
4851
4771
  */
4852
- setOptions(options: Readonly<AxAIServiceOptions>): void;
4772
+ close(): void;
4773
+ }
4774
+
4775
+ interface StdioTransportConfig {
4776
+ command: string;
4777
+ args?: string[];
4778
+ env?: NodeJS.ProcessEnv;
4779
+ }
4780
+ declare class AxMCPStdioTransport implements AxMCPTransport {
4781
+ private process;
4782
+ private rl;
4783
+ private pendingResponses;
4784
+ constructor(config: Readonly<StdioTransportConfig>);
4785
+ send(message: Readonly<JSONRPCRequest<unknown>>): Promise<JSONRPCResponse<unknown>>;
4786
+ sendNotification(message: Readonly<JSONRPCNotification>): Promise<void>;
4787
+ connect(): Promise<void>;
4788
+ }
4789
+
4790
+ /**
4791
+ * Interface for agents that can be used as child agents.
4792
+ * Provides methods to get the agent's function definition and features.
4793
+ */
4794
+ interface AxAgentic<IN extends AxGenIn, OUT extends AxGenOut> extends AxTunable<IN, OUT>, AxUsable {
4795
+ getFunction(): AxFunction;
4796
+ getFeatures(): AxAgentFeatures;
4797
+ }
4798
+ type AxAgentOptions = Omit<AxProgramForwardOptions, 'functions'> & {
4799
+ disableSmartModelRouting?: boolean;
4800
+ /** List of field names that should not be automatically passed from parent to child agents */
4801
+ excludeFieldsFromPassthrough?: string[];
4802
+ debug?: boolean;
4803
+ };
4804
+ interface AxAgentFeatures {
4805
+ /** Whether this agent can use smart model routing (requires an AI service) */
4806
+ canConfigureSmartModelRouting: boolean;
4807
+ /** List of fields that this agent excludes from parent->child value passing */
4808
+ excludeFieldsFromPassthrough: string[];
4809
+ }
4810
+ /**
4811
+ * An AI agent that can process inputs using an AI service and coordinate with child agents.
4812
+ * Supports features like smart model routing and automatic input field passing to child agents.
4813
+ */
4814
+ declare class AxAgent<IN extends AxGenIn, OUT extends AxGenOut> implements AxAgentic<IN, OUT> {
4815
+ private ai?;
4816
+ private program;
4817
+ private functions?;
4818
+ private agents?;
4819
+ private disableSmartModelRouting?;
4820
+ private excludeFieldsFromPassthrough;
4821
+ private debug?;
4822
+ private name;
4823
+ private func;
4824
+ constructor({ ai, name, description, definition, signature, agents, functions, }: Readonly<{
4825
+ ai?: Readonly<AxAIService>;
4826
+ name: string;
4827
+ description: string;
4828
+ definition?: string;
4829
+ signature: NonNullable<ConstructorParameters<typeof AxSignature>[0]>;
4830
+ agents?: AxAgentic<IN, OUT>[];
4831
+ functions?: AxInputFunctionType;
4832
+ }>, options?: Readonly<AxAgentOptions>);
4833
+ setExamples(examples: Readonly<AxProgramExamples<IN, OUT>>, options?: Readonly<AxSetExamplesOptions>): void;
4834
+ setId(id: string): void;
4835
+ setParentId(parentId: string): void;
4836
+ getTraces(): AxProgramTrace<IN, OUT>[];
4837
+ setDemos(demos: readonly AxProgramDemos<IN, OUT>[]): void;
4838
+ getUsage(): (AxModelUsage & {
4839
+ ai: string;
4840
+ model: string;
4841
+ })[];
4842
+ resetUsage(): void;
4843
+ getFunction(): AxFunction;
4844
+ getFeatures(): AxAgentFeatures;
4853
4845
  /**
4854
- * Returns the options from the last used service,
4855
- * or falls back to the first service if none has been used.
4846
+ * Initializes the agent's execution context, processing child agents and their functions.
4856
4847
  */
4857
- getOptions(): Readonly<AxAIServiceOptions>;
4848
+ private init;
4849
+ forward(parentAi: Readonly<AxAIService>, values: IN | AxMessage<IN>[], options?: Readonly<AxProgramForwardOptions>): Promise<OUT>;
4850
+ streamingForward(parentAi: Readonly<AxAIService>, values: IN | AxMessage<IN>[], options?: Readonly<AxProgramStreamingForwardOptions>): AxGenStreamingOut<OUT>;
4858
4851
  /**
4859
- * Returns the logger from the last used service,
4860
- * or falls back to the first service if none has been used.
4852
+ * Updates the agent's description.
4853
+ * This updates both the stored description and the function's description.
4854
+ *
4855
+ * @param description - New description for the agent (must be at least 20 characters)
4856
+ * @throws Error if description is too short
4861
4857
  */
4862
- getLogger(): AxLoggerFunction;
4858
+ setDescription(description: string): void;
4859
+ setDefinition(definition: string): void;
4860
+ private getDebug;
4861
+ }
4862
+
4863
+ declare class AxChainOfThought<IN extends AxGenIn = AxGenIn, OUT extends AxGenOut = AxGenOut> extends AxGen<IN, OUT> {
4864
+ constructor(signature: Readonly<AxSignature | string>, options?: Readonly<AxProgramForwardOptions & {
4865
+ setVisibleReasoning?: boolean;
4866
+ }>);
4863
4867
  }
4864
4868
 
4865
4869
  declare class AxRAG extends AxChainOfThought<{
@@ -4885,85 +4889,75 @@ declare class AxRAG extends AxChainOfThought<{
4885
4889
  }>;
4886
4890
  }
4887
4891
 
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[][];
4892
+ declare const axSpanAttributes: {
4893
+ LLM_SYSTEM: string;
4894
+ LLM_OPERATION_NAME: string;
4895
+ LLM_REQUEST_MODEL: string;
4896
+ LLM_REQUEST_MAX_TOKENS: string;
4897
+ LLM_REQUEST_TEMPERATURE: string;
4898
+ LLM_REQUEST_TOP_K: string;
4899
+ LLM_REQUEST_FREQUENCY_PENALTY: string;
4900
+ LLM_REQUEST_PRESENCE_PENALTY: string;
4901
+ LLM_REQUEST_STOP_SEQUENCES: string;
4902
+ LLM_REQUEST_LLM_IS_STREAMING: string;
4903
+ LLM_REQUEST_TOP_P: string;
4904
+ LLM_USAGE_INPUT_TOKENS: string;
4905
+ LLM_USAGE_OUTPUT_TOKENS: string;
4906
+ LLM_USAGE_TOTAL_TOKENS: string;
4907
+ LLM_USAGE_THOUGHTS_TOKENS: string;
4908
+ DB_SYSTEM: string;
4909
+ DB_TABLE: string;
4910
+ DB_NAMESPACE: string;
4911
+ DB_ID: string;
4912
+ DB_QUERY_TEXT: string;
4913
+ DB_VECTOR: string;
4914
+ DB_OPERATION_NAME: string;
4915
+ DB_VECTOR_QUERY_TOP_K: string;
4916
+ DB_QUERY_EMBEDDINGS: string;
4917
+ DB_QUERY_RESULT: string;
4918
+ DB_QUERY_EMBEDDINGS_VECTOR: string;
4919
+ DB_QUERY_RESULT_ID: string;
4920
+ DB_QUERY_RESULT_SCORE: string;
4921
+ DB_QUERY_RESULT_DISTANCE: string;
4922
+ DB_QUERY_RESULT_METADATA: string;
4923
+ DB_QUERY_RESULT_VECTOR: string;
4924
+ DB_QUERY_RESULT_DOCUMENT: string;
4898
4925
  };
4899
-
4900
- declare const axGlobals: {
4901
- signatureStrict: boolean;
4902
- tracer: Tracer | undefined;
4903
- meter: Meter | undefined;
4926
+ declare const axSpanEvents: {
4927
+ GEN_AI_USER_MESSAGE: string;
4928
+ GEN_AI_SYSTEM_MESSAGE: string;
4929
+ GEN_AI_ASSISTANT_MESSAGE: string;
4930
+ GEN_AI_TOOL_MESSAGE: string;
4931
+ GEN_AI_CHOICE: string;
4932
+ GEN_AI_USAGE: string;
4904
4933
  };
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;
4934
+ declare enum AxLLMRequestTypeValues {
4935
+ COMPLETION = "completion",
4936
+ CHAT = "chat",
4937
+ RERANK = "rerank",
4938
+ UNKNOWN = "unknown"
4939
+ }
4940
+ declare enum AxSpanKindValues {
4941
+ WORKFLOW = "workflow",
4942
+ TASK = "task",
4943
+ AGENT = "agent",
4944
+ TOOL = "tool",
4945
+ UNKNOWN = "unknown"
4963
4946
  }
4964
4947
 
4965
- interface AxSamplePickerOptions<OUT extends AxGenOut> {
4966
- resultPicker?: AxResultPickerFunction<OUT>;
4948
+ interface AxRateLimiterTokenUsageOptions {
4949
+ debug?: boolean;
4950
+ }
4951
+ declare class AxRateLimiterTokenUsage {
4952
+ private options?;
4953
+ private maxTokens;
4954
+ private refillRate;
4955
+ private currentTokens;
4956
+ private lastRefillTime;
4957
+ constructor(maxTokens: number, refillRate: number, options?: Readonly<AxRateLimiterTokenUsageOptions>);
4958
+ private refillTokens;
4959
+ private waitUntilTokensAvailable;
4960
+ acquire(tokens: number): Promise<void>;
4967
4961
  }
4968
4962
 
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 };
4963
+ 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, 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 };