@ax-llm/ax 19.0.42 → 19.0.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.cts CHANGED
@@ -191,6 +191,16 @@ type AxModelInfo = {
191
191
  characterIsToken?: boolean;
192
192
  promptTokenCostPer1M?: number;
193
193
  completionTokenCostPer1M?: number;
194
+ cacheReadTokenCostPer1M?: number;
195
+ cacheWriteTokenCostPer1M?: number;
196
+ /** Prompt token cost for requests exceeding longContextThreshold */
197
+ longContextPromptTokenCostPer1M?: number;
198
+ /** Completion token cost for requests exceeding longContextThreshold */
199
+ longContextCompletionTokenCostPer1M?: number;
200
+ /** Cache read token cost for requests exceeding longContextThreshold */
201
+ longContextCacheReadTokenCostPer1M?: number;
202
+ /** Total input token count (including cached) above which long-context rates apply */
203
+ longContextThreshold?: number;
194
204
  aliases?: string[];
195
205
  supported?: {
196
206
  thinkingBudget?: boolean;
@@ -433,6 +443,7 @@ type AxDebugChatResponseUsage = AxModelUsage & {
433
443
  mutableChatContextCharacters?: number;
434
444
  chatContextCharacters?: number;
435
445
  totalPromptCharacters?: number;
446
+ estimatedCost?: number;
436
447
  };
437
448
  type AxChatResponse = {
438
449
  sessionId?: string;
@@ -971,6 +982,7 @@ interface AxAIService<TModel = unknown, TEmbedModel = unknown, TModelKey = strin
971
982
  getLastUsedModelConfig(): AxModelConfig | undefined;
972
983
  chat(req: Readonly<AxChatRequest<TModel | TModelKey>>, options?: Readonly<AxAIServiceOptions>): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
973
984
  embed(req: Readonly<AxEmbedRequest<TEmbedModel | TModelKey>>, options?: Readonly<AxAIServiceOptions>): Promise<AxEmbedResponse>;
985
+ getEstimatedCost(modelUsage?: AxModelUsage): number;
974
986
  setOptions(options: Readonly<AxAIServiceOptions>): void;
975
987
  getOptions(): Readonly<AxAIServiceOptions>;
976
988
  }
@@ -3883,7 +3895,6 @@ declare class AxBaseAI<TModel, TEmbedModel, TChatRequest, TEmbedRequest, TChatRe
3883
3895
  private calculateResponseSize;
3884
3896
  private detectMultimodalContent;
3885
3897
  private calculateContextWindowUsage;
3886
- private estimateCost;
3887
3898
  private estimateCostByName;
3888
3899
  private recordFunctionCallMetrics;
3889
3900
  private recordTimeoutMetric;
@@ -3891,6 +3902,7 @@ declare class AxBaseAI<TModel, TEmbedModel, TChatRequest, TEmbedRequest, TChatRe
3891
3902
  private recordChatMetrics;
3892
3903
  private recordEmbedMetrics;
3893
3904
  getMetrics(): AxAIServiceMetrics;
3905
+ getEstimatedCost(modelUsage?: AxModelUsage): number;
3894
3906
  chat(req: Readonly<AxChatRequest<TModel | TModelKey>>, options?: Readonly<AxAIServiceOptions>): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
3895
3907
  private _chat1;
3896
3908
  private cleanupFunctionSchema;
@@ -4527,7 +4539,9 @@ interface AxAIOpenAIArgs<TName = 'openai', TModel = AxAIOpenAIModel, TEmbedModel
4527
4539
  modelInfo?: AxModelInfo[];
4528
4540
  config?: Partial<AxAIOpenAIBaseArgs<TModel, TEmbedModel, TModelKey, TChatReq>['config']>;
4529
4541
  }
4530
- type ChatReqUpdater<TModel, TChatReq extends AxAIOpenAIChatRequest<TModel>> = (req: Readonly<TChatReq>) => TChatReq;
4542
+ type ChatReqUpdater<TModel, TChatReq extends AxAIOpenAIChatRequest<TModel>> = (req: Readonly<TChatReq>, config: Readonly<AxAIServiceOptions>) => TChatReq;
4543
+ type ChatRespProcessor = (resp: AxChatResponse) => AxChatResponse;
4544
+ type ChatStreamRespProcessor = (resp: AxChatResponse, state: object) => AxChatResponse;
4531
4545
  interface AxAIOpenAIBaseArgs<TModel, TEmbedModel, TModelKey, TChatReq extends AxAIOpenAIChatRequest<TModel>> {
4532
4546
  apiKey: string;
4533
4547
  apiURL?: string;
@@ -4538,10 +4552,12 @@ interface AxAIOpenAIBaseArgs<TModel, TEmbedModel, TModelKey, TChatReq extends Ax
4538
4552
  modelInfo: Readonly<AxModelInfo[]>;
4539
4553
  models?: AxAIInputModelList<TModel, TEmbedModel, TModelKey>;
4540
4554
  chatReqUpdater?: ChatReqUpdater<TModel, TChatReq>;
4555
+ chatRespProcessor?: ChatRespProcessor;
4556
+ chatStreamRespProcessor?: ChatStreamRespProcessor;
4541
4557
  supportFor: AxAIFeatures | ((model: TModel) => AxAIFeatures);
4542
4558
  }
4543
4559
  declare class AxAIOpenAIBase<TModel, TEmbedModel, TModelKey, TChatReq extends AxAIOpenAIChatRequest<TModel> = AxAIOpenAIChatRequest<TModel>> extends AxBaseAI<TModel, TEmbedModel, AxAIOpenAIChatRequest<TModel>, AxAIOpenAIEmbedRequest<TEmbedModel>, AxAIOpenAIChatResponse, AxAIOpenAIChatResponseDelta, AxAIOpenAIEmbedResponse, TModelKey> {
4544
- constructor({ apiKey, config, options, apiURL, modelInfo, models, chatReqUpdater, supportFor, }: Readonly<Omit<AxAIOpenAIBaseArgs<TModel, TEmbedModel, TModelKey, TChatReq>, 'name'>>);
4560
+ constructor({ apiKey, config, options, apiURL, modelInfo, models, chatReqUpdater, chatRespProcessor, chatStreamRespProcessor, supportFor, }: Readonly<Omit<AxAIOpenAIBaseArgs<TModel, TEmbedModel, TModelKey, TChatReq>, 'name'>>);
4545
4561
  }
4546
4562
  declare class AxAIOpenAI<TModelKey = string> extends AxAIOpenAIBase<AxAIOpenAIModel, AxAIOpenAIEmbedModel, TModelKey> {
4547
4563
  constructor({ apiKey, apiURL, config, options, models, modelInfo, }: Readonly<Omit<AxAIOpenAIArgs<'openai', AxAIOpenAIModel, AxAIOpenAIEmbedModel, TModelKey>, 'name'>>);
@@ -4611,6 +4627,7 @@ declare class AxBalancer<TServices extends readonly AxAIService<any, any, any>[]
4611
4627
  getId(): string;
4612
4628
  getFeatures(model?: string): AxAIFeatures;
4613
4629
  getMetrics(): AxAIServiceMetrics;
4630
+ getEstimatedCost(modelUsage?: AxModelUsage): number;
4614
4631
  private canRetryService;
4615
4632
  private handleFailure;
4616
4633
  private handleSuccess;
@@ -5677,6 +5694,7 @@ declare class AxMockAIService<TModelKey> implements AxAIService<unknown, unknown
5677
5694
  getFeatures(_model?: string): AxAIFeatures;
5678
5695
  getModelList(): AxAIModelList<TModelKey> | undefined;
5679
5696
  getMetrics(): AxAIServiceMetrics;
5697
+ getEstimatedCost(): number;
5680
5698
  chat(req: Readonly<AxChatRequest<unknown>>, _options?: Readonly<AxAIServiceOptions>): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
5681
5699
  embed(req: Readonly<AxEmbedRequest>, _options?: Readonly<AxAIServiceOptions>): Promise<AxEmbedResponse>;
5682
5700
  setOptions(options: Readonly<AxAIServiceOptions>): void;
@@ -5744,6 +5762,7 @@ declare class AxMultiServiceRouter<TServices extends readonly (AxAIService | AxA
5744
5762
  * or falls back to the first service if none has been used.
5745
5763
  */
5746
5764
  getMetrics(): AxAIServiceMetrics;
5765
+ getEstimatedCost(modelUsage?: AxModelUsage): number;
5747
5766
  /**
5748
5767
  * Sets options on all underlying services.
5749
5768
  */
@@ -5776,6 +5795,9 @@ declare class AxMultiServiceRouter<TServices extends readonly (AxAIService | AxA
5776
5795
  * Configuration type for Ollama AI service
5777
5796
  */
5778
5797
  type AxAIOllamaAIConfig = AxAIOpenAIConfig<string, string>;
5798
+ type AxAIOllamaChatRequest = AxAIOpenAIChatRequest<string> & {
5799
+ think?: boolean;
5800
+ };
5779
5801
  /**
5780
5802
  * Creates default configuration for Ollama AI service
5781
5803
  * @returns Default configuration object with nous-hermes2 model and all-minilm embed model
@@ -5800,7 +5822,7 @@ type AxAIOllamaArgs<TModelKey> = AxAIOpenAIArgs<'ollama', string, string, TModel
5800
5822
  * Provides access to locally hosted Ollama models with OpenAI-compatible API
5801
5823
  * @template TModelKey - Type for model key
5802
5824
  */
5803
- declare class AxAIOllama<TModelKey> extends AxAIOpenAIBase<string, string, TModelKey> {
5825
+ declare class AxAIOllama<TModelKey> extends AxAIOpenAIBase<string, string, TModelKey, AxAIOllamaChatRequest> {
5804
5826
  /**
5805
5827
  * Creates a new Ollama AI service instance
5806
5828
  * @param args - Configuration arguments for the Ollama service
@@ -7116,6 +7138,7 @@ declare class AxAI<TModelKey = string> implements AxAIService<any, any, TModelKe
7116
7138
  getLastUsedEmbedModel(): any;
7117
7139
  getLastUsedModelConfig(): AxModelConfig | undefined;
7118
7140
  getMetrics(): AxAIServiceMetrics;
7141
+ getEstimatedCost(modelUsage?: AxModelUsage): number;
7119
7142
  chat(req: Readonly<AxChatRequest<TModelKey>>, options?: Readonly<AxAIServiceOptions>): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
7120
7143
  embed(req: Readonly<AxEmbedRequest<TModelKey>>, options?: Readonly<AxAIServiceOptions>): Promise<AxEmbedResponse>;
7121
7144
  setOptions(options: Readonly<AxAIServiceOptions>): void;
package/index.d.ts CHANGED
@@ -191,6 +191,16 @@ type AxModelInfo = {
191
191
  characterIsToken?: boolean;
192
192
  promptTokenCostPer1M?: number;
193
193
  completionTokenCostPer1M?: number;
194
+ cacheReadTokenCostPer1M?: number;
195
+ cacheWriteTokenCostPer1M?: number;
196
+ /** Prompt token cost for requests exceeding longContextThreshold */
197
+ longContextPromptTokenCostPer1M?: number;
198
+ /** Completion token cost for requests exceeding longContextThreshold */
199
+ longContextCompletionTokenCostPer1M?: number;
200
+ /** Cache read token cost for requests exceeding longContextThreshold */
201
+ longContextCacheReadTokenCostPer1M?: number;
202
+ /** Total input token count (including cached) above which long-context rates apply */
203
+ longContextThreshold?: number;
194
204
  aliases?: string[];
195
205
  supported?: {
196
206
  thinkingBudget?: boolean;
@@ -433,6 +443,7 @@ type AxDebugChatResponseUsage = AxModelUsage & {
433
443
  mutableChatContextCharacters?: number;
434
444
  chatContextCharacters?: number;
435
445
  totalPromptCharacters?: number;
446
+ estimatedCost?: number;
436
447
  };
437
448
  type AxChatResponse = {
438
449
  sessionId?: string;
@@ -971,6 +982,7 @@ interface AxAIService<TModel = unknown, TEmbedModel = unknown, TModelKey = strin
971
982
  getLastUsedModelConfig(): AxModelConfig | undefined;
972
983
  chat(req: Readonly<AxChatRequest<TModel | TModelKey>>, options?: Readonly<AxAIServiceOptions>): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
973
984
  embed(req: Readonly<AxEmbedRequest<TEmbedModel | TModelKey>>, options?: Readonly<AxAIServiceOptions>): Promise<AxEmbedResponse>;
985
+ getEstimatedCost(modelUsage?: AxModelUsage): number;
974
986
  setOptions(options: Readonly<AxAIServiceOptions>): void;
975
987
  getOptions(): Readonly<AxAIServiceOptions>;
976
988
  }
@@ -3883,7 +3895,6 @@ declare class AxBaseAI<TModel, TEmbedModel, TChatRequest, TEmbedRequest, TChatRe
3883
3895
  private calculateResponseSize;
3884
3896
  private detectMultimodalContent;
3885
3897
  private calculateContextWindowUsage;
3886
- private estimateCost;
3887
3898
  private estimateCostByName;
3888
3899
  private recordFunctionCallMetrics;
3889
3900
  private recordTimeoutMetric;
@@ -3891,6 +3902,7 @@ declare class AxBaseAI<TModel, TEmbedModel, TChatRequest, TEmbedRequest, TChatRe
3891
3902
  private recordChatMetrics;
3892
3903
  private recordEmbedMetrics;
3893
3904
  getMetrics(): AxAIServiceMetrics;
3905
+ getEstimatedCost(modelUsage?: AxModelUsage): number;
3894
3906
  chat(req: Readonly<AxChatRequest<TModel | TModelKey>>, options?: Readonly<AxAIServiceOptions>): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
3895
3907
  private _chat1;
3896
3908
  private cleanupFunctionSchema;
@@ -4527,7 +4539,9 @@ interface AxAIOpenAIArgs<TName = 'openai', TModel = AxAIOpenAIModel, TEmbedModel
4527
4539
  modelInfo?: AxModelInfo[];
4528
4540
  config?: Partial<AxAIOpenAIBaseArgs<TModel, TEmbedModel, TModelKey, TChatReq>['config']>;
4529
4541
  }
4530
- type ChatReqUpdater<TModel, TChatReq extends AxAIOpenAIChatRequest<TModel>> = (req: Readonly<TChatReq>) => TChatReq;
4542
+ type ChatReqUpdater<TModel, TChatReq extends AxAIOpenAIChatRequest<TModel>> = (req: Readonly<TChatReq>, config: Readonly<AxAIServiceOptions>) => TChatReq;
4543
+ type ChatRespProcessor = (resp: AxChatResponse) => AxChatResponse;
4544
+ type ChatStreamRespProcessor = (resp: AxChatResponse, state: object) => AxChatResponse;
4531
4545
  interface AxAIOpenAIBaseArgs<TModel, TEmbedModel, TModelKey, TChatReq extends AxAIOpenAIChatRequest<TModel>> {
4532
4546
  apiKey: string;
4533
4547
  apiURL?: string;
@@ -4538,10 +4552,12 @@ interface AxAIOpenAIBaseArgs<TModel, TEmbedModel, TModelKey, TChatReq extends Ax
4538
4552
  modelInfo: Readonly<AxModelInfo[]>;
4539
4553
  models?: AxAIInputModelList<TModel, TEmbedModel, TModelKey>;
4540
4554
  chatReqUpdater?: ChatReqUpdater<TModel, TChatReq>;
4555
+ chatRespProcessor?: ChatRespProcessor;
4556
+ chatStreamRespProcessor?: ChatStreamRespProcessor;
4541
4557
  supportFor: AxAIFeatures | ((model: TModel) => AxAIFeatures);
4542
4558
  }
4543
4559
  declare class AxAIOpenAIBase<TModel, TEmbedModel, TModelKey, TChatReq extends AxAIOpenAIChatRequest<TModel> = AxAIOpenAIChatRequest<TModel>> extends AxBaseAI<TModel, TEmbedModel, AxAIOpenAIChatRequest<TModel>, AxAIOpenAIEmbedRequest<TEmbedModel>, AxAIOpenAIChatResponse, AxAIOpenAIChatResponseDelta, AxAIOpenAIEmbedResponse, TModelKey> {
4544
- constructor({ apiKey, config, options, apiURL, modelInfo, models, chatReqUpdater, supportFor, }: Readonly<Omit<AxAIOpenAIBaseArgs<TModel, TEmbedModel, TModelKey, TChatReq>, 'name'>>);
4560
+ constructor({ apiKey, config, options, apiURL, modelInfo, models, chatReqUpdater, chatRespProcessor, chatStreamRespProcessor, supportFor, }: Readonly<Omit<AxAIOpenAIBaseArgs<TModel, TEmbedModel, TModelKey, TChatReq>, 'name'>>);
4545
4561
  }
4546
4562
  declare class AxAIOpenAI<TModelKey = string> extends AxAIOpenAIBase<AxAIOpenAIModel, AxAIOpenAIEmbedModel, TModelKey> {
4547
4563
  constructor({ apiKey, apiURL, config, options, models, modelInfo, }: Readonly<Omit<AxAIOpenAIArgs<'openai', AxAIOpenAIModel, AxAIOpenAIEmbedModel, TModelKey>, 'name'>>);
@@ -4611,6 +4627,7 @@ declare class AxBalancer<TServices extends readonly AxAIService<any, any, any>[]
4611
4627
  getId(): string;
4612
4628
  getFeatures(model?: string): AxAIFeatures;
4613
4629
  getMetrics(): AxAIServiceMetrics;
4630
+ getEstimatedCost(modelUsage?: AxModelUsage): number;
4614
4631
  private canRetryService;
4615
4632
  private handleFailure;
4616
4633
  private handleSuccess;
@@ -5677,6 +5694,7 @@ declare class AxMockAIService<TModelKey> implements AxAIService<unknown, unknown
5677
5694
  getFeatures(_model?: string): AxAIFeatures;
5678
5695
  getModelList(): AxAIModelList<TModelKey> | undefined;
5679
5696
  getMetrics(): AxAIServiceMetrics;
5697
+ getEstimatedCost(): number;
5680
5698
  chat(req: Readonly<AxChatRequest<unknown>>, _options?: Readonly<AxAIServiceOptions>): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
5681
5699
  embed(req: Readonly<AxEmbedRequest>, _options?: Readonly<AxAIServiceOptions>): Promise<AxEmbedResponse>;
5682
5700
  setOptions(options: Readonly<AxAIServiceOptions>): void;
@@ -5744,6 +5762,7 @@ declare class AxMultiServiceRouter<TServices extends readonly (AxAIService | AxA
5744
5762
  * or falls back to the first service if none has been used.
5745
5763
  */
5746
5764
  getMetrics(): AxAIServiceMetrics;
5765
+ getEstimatedCost(modelUsage?: AxModelUsage): number;
5747
5766
  /**
5748
5767
  * Sets options on all underlying services.
5749
5768
  */
@@ -5776,6 +5795,9 @@ declare class AxMultiServiceRouter<TServices extends readonly (AxAIService | AxA
5776
5795
  * Configuration type for Ollama AI service
5777
5796
  */
5778
5797
  type AxAIOllamaAIConfig = AxAIOpenAIConfig<string, string>;
5798
+ type AxAIOllamaChatRequest = AxAIOpenAIChatRequest<string> & {
5799
+ think?: boolean;
5800
+ };
5779
5801
  /**
5780
5802
  * Creates default configuration for Ollama AI service
5781
5803
  * @returns Default configuration object with nous-hermes2 model and all-minilm embed model
@@ -5800,7 +5822,7 @@ type AxAIOllamaArgs<TModelKey> = AxAIOpenAIArgs<'ollama', string, string, TModel
5800
5822
  * Provides access to locally hosted Ollama models with OpenAI-compatible API
5801
5823
  * @template TModelKey - Type for model key
5802
5824
  */
5803
- declare class AxAIOllama<TModelKey> extends AxAIOpenAIBase<string, string, TModelKey> {
5825
+ declare class AxAIOllama<TModelKey> extends AxAIOpenAIBase<string, string, TModelKey, AxAIOllamaChatRequest> {
5804
5826
  /**
5805
5827
  * Creates a new Ollama AI service instance
5806
5828
  * @param args - Configuration arguments for the Ollama service
@@ -7116,6 +7138,7 @@ declare class AxAI<TModelKey = string> implements AxAIService<any, any, TModelKe
7116
7138
  getLastUsedEmbedModel(): any;
7117
7139
  getLastUsedModelConfig(): AxModelConfig | undefined;
7118
7140
  getMetrics(): AxAIServiceMetrics;
7141
+ getEstimatedCost(modelUsage?: AxModelUsage): number;
7119
7142
  chat(req: Readonly<AxChatRequest<TModelKey>>, options?: Readonly<AxAIServiceOptions>): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
7120
7143
  embed(req: Readonly<AxEmbedRequest<TModelKey>>, options?: Readonly<AxAIServiceOptions>): Promise<AxEmbedResponse>;
7121
7144
  setOptions(options: Readonly<AxAIServiceOptions>): void;