@ax-llm/ax 11.0.45 → 11.0.47

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
@@ -65,6 +65,8 @@ interface AxAIFeatures {
65
65
  functions: boolean;
66
66
  streaming: boolean;
67
67
  functionCot?: boolean;
68
+ hasThinkingBudget?: boolean;
69
+ hasShowThoughts?: boolean;
68
70
  }
69
71
  interface AxBaseAIArgs<TModel, TEmbedModel> {
70
72
  name: string;
@@ -156,6 +158,8 @@ type AxModelInfo = {
156
158
  promptTokenCostPer1M?: number;
157
159
  completionTokenCostPer1M?: number;
158
160
  aliases?: string[];
161
+ hasThinkingBudget?: boolean;
162
+ hasShowThoughts?: boolean;
159
163
  };
160
164
  type AxTokenUsage = {
161
165
  promptTokens: number;
@@ -346,6 +350,7 @@ type AxAIServiceActionOptions<TModel = unknown, TEmbedModel = unknown> = {
346
350
  rateLimiter?: AxRateLimiterFunction;
347
351
  debug?: boolean;
348
352
  debugHideSystemPrompt?: boolean;
353
+ hideThought?: boolean;
349
354
  };
350
355
  interface AxAIService<TModel = unknown, TEmbedModel = unknown> {
351
356
  getId(): string;
@@ -615,6 +620,18 @@ type AxAIOpenAIConfig<TModel, TEmbedModel> = Omit<AxModelConfig, 'topK'> & {
615
620
  dimensions?: number;
616
621
  reasoningEffort?: 'low' | 'medium' | 'high';
617
622
  store?: boolean;
623
+ webSearchOptions?: {
624
+ searchContextSize?: 'low' | 'medium' | 'high';
625
+ userLocation?: {
626
+ approximate: {
627
+ type: 'approximate';
628
+ city?: string;
629
+ country?: string;
630
+ region?: string;
631
+ timezone?: string;
632
+ };
633
+ } | null;
634
+ };
618
635
  };
619
636
  type AxAIOpenAILogprob = {
620
637
  tokens: string[];
@@ -710,6 +727,18 @@ type AxAIOpenAIChatRequest<TModel> = {
710
727
  logit_bias?: Map<string, number>;
711
728
  user?: string;
712
729
  organization?: string;
730
+ web_search_options?: {
731
+ search_context_size?: 'low' | 'medium' | 'high';
732
+ user_location?: {
733
+ approximate: {
734
+ type: 'approximate';
735
+ city?: string;
736
+ country?: string;
737
+ region?: string;
738
+ timezone?: string;
739
+ };
740
+ } | null;
741
+ };
713
742
  };
714
743
  type AxAIOpenAIChatResponse = {
715
744
  id: string;
@@ -721,6 +750,7 @@ type AxAIOpenAIChatResponse = {
721
750
  message: {
722
751
  role: string;
723
752
  content: string;
753
+ reasoning_content?: string;
724
754
  tool_calls?: {
725
755
  id: string;
726
756
  type: 'function';
@@ -743,6 +773,7 @@ type AxAIOpenAIChatResponse = {
743
773
  };
744
774
  type AxAIOpenAIChatResponseDelta = AxAIOpenAIResponseDelta<{
745
775
  content: string;
776
+ reasoning_content?: string;
746
777
  role?: string;
747
778
  tool_calls?: (NonNullable<AxAIOpenAIChatResponse['choices'][0]['message']['tool_calls']>[0] & {
748
779
  index: number;
@@ -782,9 +813,10 @@ interface AxAIOpenAIBaseArgs<TModel, TEmbedModel, TChatReq extends AxAIOpenAICha
782
813
  modelInfo: Readonly<AxModelInfo[]>;
783
814
  models?: AxAIInputModelList<TModel, TEmbedModel>;
784
815
  chatReqUpdater?: ChatReqUpdater<TModel, TChatReq>;
816
+ supportFor?: AxAIFeatures | ((model: TModel) => AxAIFeatures);
785
817
  }
786
818
  declare class AxAIOpenAIBase<TModel, TEmbedModel, TChatReq extends AxAIOpenAIChatRequest<TModel> = AxAIOpenAIChatRequest<TModel>> extends AxBaseAI<TModel, TEmbedModel, AxAIOpenAIChatRequest<TModel>, AxAIOpenAIEmbedRequest<TEmbedModel>, AxAIOpenAIChatResponse, AxAIOpenAIChatResponseDelta, AxAIOpenAIEmbedResponse> {
787
- constructor({ apiKey, config, options, apiURL, modelInfo, models, chatReqUpdater, }: Readonly<Omit<AxAIOpenAIBaseArgs<TModel, TEmbedModel, TChatReq>, 'name'>>);
819
+ constructor({ apiKey, config, options, apiURL, modelInfo, models, chatReqUpdater, supportFor, }: Readonly<Omit<AxAIOpenAIBaseArgs<TModel, TEmbedModel, TChatReq>, 'name'>>);
788
820
  }
789
821
  declare class AxAIOpenAI extends AxAIOpenAIBase<AxAIOpenAIModel, AxAIOpenAIEmbedModel> {
790
822
  constructor({ apiKey, config, options, models, }: Readonly<Omit<AxAIOpenAIArgs, 'name' | 'modelInfo'>>);
package/index.d.ts CHANGED
@@ -65,6 +65,8 @@ interface AxAIFeatures {
65
65
  functions: boolean;
66
66
  streaming: boolean;
67
67
  functionCot?: boolean;
68
+ hasThinkingBudget?: boolean;
69
+ hasShowThoughts?: boolean;
68
70
  }
69
71
  interface AxBaseAIArgs<TModel, TEmbedModel> {
70
72
  name: string;
@@ -156,6 +158,8 @@ type AxModelInfo = {
156
158
  promptTokenCostPer1M?: number;
157
159
  completionTokenCostPer1M?: number;
158
160
  aliases?: string[];
161
+ hasThinkingBudget?: boolean;
162
+ hasShowThoughts?: boolean;
159
163
  };
160
164
  type AxTokenUsage = {
161
165
  promptTokens: number;
@@ -346,6 +350,7 @@ type AxAIServiceActionOptions<TModel = unknown, TEmbedModel = unknown> = {
346
350
  rateLimiter?: AxRateLimiterFunction;
347
351
  debug?: boolean;
348
352
  debugHideSystemPrompt?: boolean;
353
+ hideThought?: boolean;
349
354
  };
350
355
  interface AxAIService<TModel = unknown, TEmbedModel = unknown> {
351
356
  getId(): string;
@@ -615,6 +620,18 @@ type AxAIOpenAIConfig<TModel, TEmbedModel> = Omit<AxModelConfig, 'topK'> & {
615
620
  dimensions?: number;
616
621
  reasoningEffort?: 'low' | 'medium' | 'high';
617
622
  store?: boolean;
623
+ webSearchOptions?: {
624
+ searchContextSize?: 'low' | 'medium' | 'high';
625
+ userLocation?: {
626
+ approximate: {
627
+ type: 'approximate';
628
+ city?: string;
629
+ country?: string;
630
+ region?: string;
631
+ timezone?: string;
632
+ };
633
+ } | null;
634
+ };
618
635
  };
619
636
  type AxAIOpenAILogprob = {
620
637
  tokens: string[];
@@ -710,6 +727,18 @@ type AxAIOpenAIChatRequest<TModel> = {
710
727
  logit_bias?: Map<string, number>;
711
728
  user?: string;
712
729
  organization?: string;
730
+ web_search_options?: {
731
+ search_context_size?: 'low' | 'medium' | 'high';
732
+ user_location?: {
733
+ approximate: {
734
+ type: 'approximate';
735
+ city?: string;
736
+ country?: string;
737
+ region?: string;
738
+ timezone?: string;
739
+ };
740
+ } | null;
741
+ };
713
742
  };
714
743
  type AxAIOpenAIChatResponse = {
715
744
  id: string;
@@ -721,6 +750,7 @@ type AxAIOpenAIChatResponse = {
721
750
  message: {
722
751
  role: string;
723
752
  content: string;
753
+ reasoning_content?: string;
724
754
  tool_calls?: {
725
755
  id: string;
726
756
  type: 'function';
@@ -743,6 +773,7 @@ type AxAIOpenAIChatResponse = {
743
773
  };
744
774
  type AxAIOpenAIChatResponseDelta = AxAIOpenAIResponseDelta<{
745
775
  content: string;
776
+ reasoning_content?: string;
746
777
  role?: string;
747
778
  tool_calls?: (NonNullable<AxAIOpenAIChatResponse['choices'][0]['message']['tool_calls']>[0] & {
748
779
  index: number;
@@ -782,9 +813,10 @@ interface AxAIOpenAIBaseArgs<TModel, TEmbedModel, TChatReq extends AxAIOpenAICha
782
813
  modelInfo: Readonly<AxModelInfo[]>;
783
814
  models?: AxAIInputModelList<TModel, TEmbedModel>;
784
815
  chatReqUpdater?: ChatReqUpdater<TModel, TChatReq>;
816
+ supportFor?: AxAIFeatures | ((model: TModel) => AxAIFeatures);
785
817
  }
786
818
  declare class AxAIOpenAIBase<TModel, TEmbedModel, TChatReq extends AxAIOpenAIChatRequest<TModel> = AxAIOpenAIChatRequest<TModel>> extends AxBaseAI<TModel, TEmbedModel, AxAIOpenAIChatRequest<TModel>, AxAIOpenAIEmbedRequest<TEmbedModel>, AxAIOpenAIChatResponse, AxAIOpenAIChatResponseDelta, AxAIOpenAIEmbedResponse> {
787
- constructor({ apiKey, config, options, apiURL, modelInfo, models, chatReqUpdater, }: Readonly<Omit<AxAIOpenAIBaseArgs<TModel, TEmbedModel, TChatReq>, 'name'>>);
819
+ constructor({ apiKey, config, options, apiURL, modelInfo, models, chatReqUpdater, supportFor, }: Readonly<Omit<AxAIOpenAIBaseArgs<TModel, TEmbedModel, TChatReq>, 'name'>>);
788
820
  }
789
821
  declare class AxAIOpenAI extends AxAIOpenAIBase<AxAIOpenAIModel, AxAIOpenAIEmbedModel> {
790
822
  constructor({ apiKey, config, options, models, }: Readonly<Omit<AxAIOpenAIArgs, 'name' | 'modelInfo'>>);
package/index.js CHANGED
@@ -916,6 +916,11 @@ var AxBaseAI = class {
916
916
  ...this.aiImpl.getModelConfig(),
917
917
  ...req.modelConfig
918
918
  };
919
+ if (options?.thinkingTokenBudget && !this.getFeatures(model).hasThinkingBudget) {
920
+ throw new Error(
921
+ `Model ${model} does not support thinkingTokenBudget.`
922
+ );
923
+ }
919
924
  modelConfig.stream = (options?.stream !== void 0 ? options.stream : modelConfig.stream) ?? true;
920
925
  const canStream = this.getFeatures(model).streaming;
921
926
  if (!canStream) {
@@ -1018,6 +1023,13 @@ var AxBaseAI = class {
1018
1023
  const wrappedRespFn = (state) => (resp) => {
1019
1024
  const res2 = respFn(resp, state);
1020
1025
  res2.sessionId = options?.sessionId;
1026
+ if (options?.hideThought) {
1027
+ res2.results.forEach((result) => {
1028
+ if (result.thought) {
1029
+ result.thought = void 0;
1030
+ }
1031
+ });
1032
+ }
1021
1033
  if (!res2.modelUsage) {
1022
1034
  res2.modelUsage = {
1023
1035
  ai: this.name,
@@ -1055,6 +1067,13 @@ var AxBaseAI = class {
1055
1067
  }
1056
1068
  const res = this.aiImpl.createChatResp(rv);
1057
1069
  res.sessionId = options?.sessionId;
1070
+ if (options?.hideThought) {
1071
+ res.results.forEach((result) => {
1072
+ if (result.thought) {
1073
+ result.thought = void 0;
1074
+ }
1075
+ });
1076
+ }
1058
1077
  if (!res.modelUsage) {
1059
1078
  const tokenUsage = this.aiImpl.getTokenUsage();
1060
1079
  if (tokenUsage) {
@@ -1842,25 +1861,29 @@ var axModelInfoOpenAI = [
1842
1861
  name: "o1" /* O1 */,
1843
1862
  currency: "usd",
1844
1863
  promptTokenCostPer1M: 15,
1845
- completionTokenCostPer1M: 60
1864
+ completionTokenCostPer1M: 60,
1865
+ hasThinkingBudget: true
1846
1866
  },
1847
1867
  {
1848
1868
  name: "o1-mini" /* O1Mini */,
1849
1869
  currency: "usd",
1850
1870
  promptTokenCostPer1M: 1.1,
1851
- completionTokenCostPer1M: 14.4
1871
+ completionTokenCostPer1M: 14.4,
1872
+ hasThinkingBudget: true
1852
1873
  },
1853
1874
  {
1854
1875
  name: "o3-mini" /* O3Mini */,
1855
1876
  currency: "usd",
1856
1877
  promptTokenCostPer1M: 1.1,
1857
- completionTokenCostPer1M: 4.4
1878
+ completionTokenCostPer1M: 4.4,
1879
+ hasThinkingBudget: true
1858
1880
  },
1859
1881
  {
1860
1882
  name: "o4-mini" /* O4Mini */,
1861
1883
  currency: "usd",
1862
1884
  promptTokenCostPer1M: 1.1,
1863
- completionTokenCostPer1M: 4.4
1885
+ completionTokenCostPer1M: 4.4,
1886
+ hasThinkingBudget: true
1864
1887
  },
1865
1888
  {
1866
1889
  name: "gpt-4" /* GPT4 */,
@@ -2014,6 +2037,32 @@ var AxAIOpenAIImpl = class {
2014
2037
  if (this.config.reasoningEffort) {
2015
2038
  reqValue.reasoning_effort = this.config.reasoningEffort;
2016
2039
  }
2040
+ if (this.config.webSearchOptions) {
2041
+ reqValue.web_search_options = {
2042
+ ...this.config.webSearchOptions.searchContextSize && {
2043
+ search_context_size: this.config.webSearchOptions.searchContextSize
2044
+ },
2045
+ ...this.config.webSearchOptions.userLocation && {
2046
+ user_location: {
2047
+ approximate: {
2048
+ type: "approximate",
2049
+ ...this.config.webSearchOptions.userLocation.approximate.city && {
2050
+ city: this.config.webSearchOptions.userLocation.approximate.city
2051
+ },
2052
+ ...this.config.webSearchOptions.userLocation.approximate.country && {
2053
+ country: this.config.webSearchOptions.userLocation.approximate.country
2054
+ },
2055
+ ...this.config.webSearchOptions.userLocation.approximate.region && {
2056
+ region: this.config.webSearchOptions.userLocation.approximate.region
2057
+ },
2058
+ ...this.config.webSearchOptions.userLocation.approximate.timezone && {
2059
+ timezone: this.config.webSearchOptions.userLocation.approximate.timezone
2060
+ }
2061
+ }
2062
+ }
2063
+ }
2064
+ };
2065
+ }
2017
2066
  if (config.thinkingTokenBudget) {
2018
2067
  switch (config.thinkingTokenBudget) {
2019
2068
  case "minimal":
@@ -2074,6 +2123,7 @@ var AxAIOpenAIImpl = class {
2074
2123
  return {
2075
2124
  id: `${choice.index}`,
2076
2125
  content: choice.message.content,
2126
+ thought: choice.message.reasoning_content,
2077
2127
  functionCalls,
2078
2128
  finishReason
2079
2129
  };
@@ -2096,7 +2146,12 @@ var AxAIOpenAIImpl = class {
2096
2146
  }
2097
2147
  const results = choices.map(
2098
2148
  ({
2099
- delta: { content, role, tool_calls: toolCalls },
2149
+ delta: {
2150
+ content,
2151
+ role,
2152
+ tool_calls: toolCalls,
2153
+ reasoning_content: thought
2154
+ },
2100
2155
  finish_reason: oaiFinishReason
2101
2156
  }) => {
2102
2157
  const finishReason = mapFinishReason2(oaiFinishReason);
@@ -2117,6 +2172,7 @@ var AxAIOpenAIImpl = class {
2117
2172
  return {
2118
2173
  content,
2119
2174
  role,
2175
+ thought,
2120
2176
  functionCalls,
2121
2177
  finishReason,
2122
2178
  id
@@ -2215,7 +2271,8 @@ var AxAIOpenAIBase = class extends AxBaseAI {
2215
2271
  apiURL,
2216
2272
  modelInfo,
2217
2273
  models,
2218
- chatReqUpdater
2274
+ chatReqUpdater,
2275
+ supportFor
2219
2276
  }) {
2220
2277
  if (!apiKey || apiKey === "") {
2221
2278
  throw new Error("OpenAI API key not set");
@@ -2235,9 +2292,15 @@ var AxAIOpenAIBase = class extends AxBaseAI {
2235
2292
  embedModel: config.embedModel
2236
2293
  },
2237
2294
  options,
2238
- supportFor: () => {
2239
- return { functions: true, streaming: true };
2240
- },
2295
+ supportFor: supportFor ?? ((model) => {
2296
+ const modelInf = modelInfo.find((m) => m.name === model);
2297
+ return {
2298
+ functions: true,
2299
+ streaming: true,
2300
+ hasThinkingBudget: modelInf?.hasThinkingBudget ?? false,
2301
+ hasShowThoughts: modelInf?.hasShowThoughts ?? false
2302
+ };
2303
+ }),
2241
2304
  models
2242
2305
  });
2243
2306
  }
@@ -2252,6 +2315,15 @@ var AxAIOpenAI = class extends AxAIOpenAIBase {
2252
2315
  if (!apiKey || apiKey === "") {
2253
2316
  throw new Error("OpenAI API key not set");
2254
2317
  }
2318
+ const supportForFn = (model) => {
2319
+ const modelInf = axModelInfoOpenAI.find((m) => m.name === model);
2320
+ return {
2321
+ functions: true,
2322
+ streaming: true,
2323
+ hasThinkingBudget: modelInf?.hasThinkingBudget ?? false,
2324
+ hasShowThoughts: modelInf?.hasShowThoughts ?? false
2325
+ };
2326
+ };
2255
2327
  super({
2256
2328
  apiKey,
2257
2329
  config: {
@@ -2260,7 +2332,8 @@ var AxAIOpenAI = class extends AxAIOpenAIBase {
2260
2332
  },
2261
2333
  options,
2262
2334
  modelInfo: axModelInfoOpenAI,
2263
- models
2335
+ models,
2336
+ supportFor: supportForFn
2264
2337
  });
2265
2338
  super.setName("OpenAI");
2266
2339
  }
@@ -2299,7 +2372,16 @@ var AxAIAzureOpenAI = class extends AxAIOpenAIBase {
2299
2372
  config: _config,
2300
2373
  options,
2301
2374
  models,
2302
- modelInfo: axModelInfoOpenAI
2375
+ modelInfo: axModelInfoOpenAI,
2376
+ supportFor: (model) => {
2377
+ const modelInf = axModelInfoOpenAI.find((m) => m.name === model);
2378
+ return {
2379
+ functions: true,
2380
+ streaming: true,
2381
+ hasThinkingBudget: modelInf?.hasThinkingBudget ?? false,
2382
+ hasShowThoughts: modelInf?.hasShowThoughts ?? false
2383
+ };
2384
+ }
2303
2385
  });
2304
2386
  const host = resourceName.includes("://") ? resourceName : `https://${resourceName}.openai.azure.com/`;
2305
2387
  super.setName("Azure OpenAI");
@@ -2758,14 +2840,18 @@ var axModelInfoGoogleGemini = [
2758
2840
  currency: "usd",
2759
2841
  characterIsToken: false,
2760
2842
  promptTokenCostPer1M: 2.5,
2761
- completionTokenCostPer1M: 15
2843
+ completionTokenCostPer1M: 15,
2844
+ hasThinkingBudget: true,
2845
+ hasShowThoughts: true
2762
2846
  },
2763
2847
  {
2764
2848
  name: "gemini-2.5-flash-preview-04-17" /* Gemini25Flash */,
2765
2849
  currency: "usd",
2766
2850
  characterIsToken: false,
2767
2851
  promptTokenCostPer1M: 15,
2768
- completionTokenCostPer1M: 3.5
2852
+ completionTokenCostPer1M: 3.5,
2853
+ hasThinkingBudget: true,
2854
+ hasShowThoughts: true
2769
2855
  },
2770
2856
  {
2771
2857
  name: "gemini-2.0-flash" /* Gemini20Flash */,
@@ -3240,7 +3326,16 @@ var AxAIGoogleGemini = class extends AxBaseAI {
3240
3326
  embedModel: _config.embedModel
3241
3327
  },
3242
3328
  options,
3243
- supportFor: { functions: true, streaming: true },
3329
+ supportFor: (model) => {
3330
+ const modelInf = axModelInfoGoogleGemini.find((m) => m.name === model);
3331
+ return {
3332
+ functions: true,
3333
+ streaming: true,
3334
+ hasThinkingBudget: modelInf?.hasThinkingBudget ?? false,
3335
+ hasShowThoughts: modelInf?.hasShowThoughts ?? false,
3336
+ functionCot: false
3337
+ };
3338
+ },
3244
3339
  models
3245
3340
  });
3246
3341
  }
@@ -4030,7 +4125,8 @@ var axModelInfoGrok = [
4030
4125
  name: "grok-3-mini" /* Grok3Mini */,
4031
4126
  currency: "USD",
4032
4127
  promptTokenCostPer1M: 0.3,
4033
- completionTokenCostPer1M: 0.5
4128
+ completionTokenCostPer1M: 0.5,
4129
+ hasThinkingBudget: true
4034
4130
  },
4035
4131
  {
4036
4132
  name: "grok-3-fast" /* Grok3Fast */,
@@ -4042,7 +4138,8 @@ var axModelInfoGrok = [
4042
4138
  name: "grok-3-mini-fast" /* Grok3MiniFast */,
4043
4139
  currency: "USD",
4044
4140
  promptTokenCostPer1M: 0.6,
4045
- completionTokenCostPer1M: 4
4141
+ completionTokenCostPer1M: 4,
4142
+ hasThinkingBudget: true
4046
4143
  }
4047
4144
  ];
4048
4145
 
@@ -4075,7 +4172,16 @@ var AxAIGrok = class extends AxAIOpenAIBase {
4075
4172
  options,
4076
4173
  apiURL: "https://api.x.ai/v1",
4077
4174
  modelInfo: axModelInfoGrok,
4078
- models
4175
+ models,
4176
+ supportFor: (model) => {
4177
+ const modelInf = axModelInfoGrok.find((m) => m.name === model);
4178
+ return {
4179
+ functions: true,
4180
+ streaming: true,
4181
+ hasThinkingBudget: modelInf?.hasThinkingBudget ?? false,
4182
+ hasShowThoughts: modelInf?.hasShowThoughts ?? false
4183
+ };
4184
+ }
4079
4185
  });
4080
4186
  super.setName("Grok");
4081
4187
  }
@@ -6912,7 +7018,7 @@ Content: ${result.content}`
6912
7018
  return false;
6913
7019
  }
6914
7020
  async *_forward1(ai, values, options) {
6915
- const tracer = options?.tracer ?? this.options?.tracer;
7021
+ const tracer = options?.tracer ?? this.options?.tracer ?? ai.getOptions().tracer;
6916
7022
  let functions = this.functions;
6917
7023
  if (options?.functions) {
6918
7024
  functions = parseFunctions(options.functions, this.functions);