@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.cjs CHANGED
@@ -1074,6 +1074,11 @@ var AxBaseAI = class {
1074
1074
  ...this.aiImpl.getModelConfig(),
1075
1075
  ...req.modelConfig
1076
1076
  };
1077
+ if (options?.thinkingTokenBudget && !this.getFeatures(model).hasThinkingBudget) {
1078
+ throw new Error(
1079
+ `Model ${model} does not support thinkingTokenBudget.`
1080
+ );
1081
+ }
1077
1082
  modelConfig.stream = (options?.stream !== void 0 ? options.stream : modelConfig.stream) ?? true;
1078
1083
  const canStream = this.getFeatures(model).streaming;
1079
1084
  if (!canStream) {
@@ -1176,6 +1181,13 @@ var AxBaseAI = class {
1176
1181
  const wrappedRespFn = (state) => (resp) => {
1177
1182
  const res2 = respFn(resp, state);
1178
1183
  res2.sessionId = options?.sessionId;
1184
+ if (options?.hideThought) {
1185
+ res2.results.forEach((result) => {
1186
+ if (result.thought) {
1187
+ result.thought = void 0;
1188
+ }
1189
+ });
1190
+ }
1179
1191
  if (!res2.modelUsage) {
1180
1192
  res2.modelUsage = {
1181
1193
  ai: this.name,
@@ -1213,6 +1225,13 @@ var AxBaseAI = class {
1213
1225
  }
1214
1226
  const res = this.aiImpl.createChatResp(rv);
1215
1227
  res.sessionId = options?.sessionId;
1228
+ if (options?.hideThought) {
1229
+ res.results.forEach((result) => {
1230
+ if (result.thought) {
1231
+ result.thought = void 0;
1232
+ }
1233
+ });
1234
+ }
1216
1235
  if (!res.modelUsage) {
1217
1236
  const tokenUsage = this.aiImpl.getTokenUsage();
1218
1237
  if (tokenUsage) {
@@ -2000,25 +2019,29 @@ var axModelInfoOpenAI = [
2000
2019
  name: "o1" /* O1 */,
2001
2020
  currency: "usd",
2002
2021
  promptTokenCostPer1M: 15,
2003
- completionTokenCostPer1M: 60
2022
+ completionTokenCostPer1M: 60,
2023
+ hasThinkingBudget: true
2004
2024
  },
2005
2025
  {
2006
2026
  name: "o1-mini" /* O1Mini */,
2007
2027
  currency: "usd",
2008
2028
  promptTokenCostPer1M: 1.1,
2009
- completionTokenCostPer1M: 14.4
2029
+ completionTokenCostPer1M: 14.4,
2030
+ hasThinkingBudget: true
2010
2031
  },
2011
2032
  {
2012
2033
  name: "o3-mini" /* O3Mini */,
2013
2034
  currency: "usd",
2014
2035
  promptTokenCostPer1M: 1.1,
2015
- completionTokenCostPer1M: 4.4
2036
+ completionTokenCostPer1M: 4.4,
2037
+ hasThinkingBudget: true
2016
2038
  },
2017
2039
  {
2018
2040
  name: "o4-mini" /* O4Mini */,
2019
2041
  currency: "usd",
2020
2042
  promptTokenCostPer1M: 1.1,
2021
- completionTokenCostPer1M: 4.4
2043
+ completionTokenCostPer1M: 4.4,
2044
+ hasThinkingBudget: true
2022
2045
  },
2023
2046
  {
2024
2047
  name: "gpt-4" /* GPT4 */,
@@ -2172,6 +2195,32 @@ var AxAIOpenAIImpl = class {
2172
2195
  if (this.config.reasoningEffort) {
2173
2196
  reqValue.reasoning_effort = this.config.reasoningEffort;
2174
2197
  }
2198
+ if (this.config.webSearchOptions) {
2199
+ reqValue.web_search_options = {
2200
+ ...this.config.webSearchOptions.searchContextSize && {
2201
+ search_context_size: this.config.webSearchOptions.searchContextSize
2202
+ },
2203
+ ...this.config.webSearchOptions.userLocation && {
2204
+ user_location: {
2205
+ approximate: {
2206
+ type: "approximate",
2207
+ ...this.config.webSearchOptions.userLocation.approximate.city && {
2208
+ city: this.config.webSearchOptions.userLocation.approximate.city
2209
+ },
2210
+ ...this.config.webSearchOptions.userLocation.approximate.country && {
2211
+ country: this.config.webSearchOptions.userLocation.approximate.country
2212
+ },
2213
+ ...this.config.webSearchOptions.userLocation.approximate.region && {
2214
+ region: this.config.webSearchOptions.userLocation.approximate.region
2215
+ },
2216
+ ...this.config.webSearchOptions.userLocation.approximate.timezone && {
2217
+ timezone: this.config.webSearchOptions.userLocation.approximate.timezone
2218
+ }
2219
+ }
2220
+ }
2221
+ }
2222
+ };
2223
+ }
2175
2224
  if (config.thinkingTokenBudget) {
2176
2225
  switch (config.thinkingTokenBudget) {
2177
2226
  case "minimal":
@@ -2232,6 +2281,7 @@ var AxAIOpenAIImpl = class {
2232
2281
  return {
2233
2282
  id: `${choice.index}`,
2234
2283
  content: choice.message.content,
2284
+ thought: choice.message.reasoning_content,
2235
2285
  functionCalls,
2236
2286
  finishReason
2237
2287
  };
@@ -2254,7 +2304,12 @@ var AxAIOpenAIImpl = class {
2254
2304
  }
2255
2305
  const results = choices.map(
2256
2306
  ({
2257
- delta: { content, role, tool_calls: toolCalls },
2307
+ delta: {
2308
+ content,
2309
+ role,
2310
+ tool_calls: toolCalls,
2311
+ reasoning_content: thought
2312
+ },
2258
2313
  finish_reason: oaiFinishReason
2259
2314
  }) => {
2260
2315
  const finishReason = mapFinishReason2(oaiFinishReason);
@@ -2275,6 +2330,7 @@ var AxAIOpenAIImpl = class {
2275
2330
  return {
2276
2331
  content,
2277
2332
  role,
2333
+ thought,
2278
2334
  functionCalls,
2279
2335
  finishReason,
2280
2336
  id
@@ -2373,7 +2429,8 @@ var AxAIOpenAIBase = class extends AxBaseAI {
2373
2429
  apiURL,
2374
2430
  modelInfo,
2375
2431
  models,
2376
- chatReqUpdater
2432
+ chatReqUpdater,
2433
+ supportFor
2377
2434
  }) {
2378
2435
  if (!apiKey || apiKey === "") {
2379
2436
  throw new Error("OpenAI API key not set");
@@ -2393,9 +2450,15 @@ var AxAIOpenAIBase = class extends AxBaseAI {
2393
2450
  embedModel: config.embedModel
2394
2451
  },
2395
2452
  options,
2396
- supportFor: () => {
2397
- return { functions: true, streaming: true };
2398
- },
2453
+ supportFor: supportFor ?? ((model) => {
2454
+ const modelInf = modelInfo.find((m) => m.name === model);
2455
+ return {
2456
+ functions: true,
2457
+ streaming: true,
2458
+ hasThinkingBudget: modelInf?.hasThinkingBudget ?? false,
2459
+ hasShowThoughts: modelInf?.hasShowThoughts ?? false
2460
+ };
2461
+ }),
2399
2462
  models
2400
2463
  });
2401
2464
  }
@@ -2410,6 +2473,15 @@ var AxAIOpenAI = class extends AxAIOpenAIBase {
2410
2473
  if (!apiKey || apiKey === "") {
2411
2474
  throw new Error("OpenAI API key not set");
2412
2475
  }
2476
+ const supportForFn = (model) => {
2477
+ const modelInf = axModelInfoOpenAI.find((m) => m.name === model);
2478
+ return {
2479
+ functions: true,
2480
+ streaming: true,
2481
+ hasThinkingBudget: modelInf?.hasThinkingBudget ?? false,
2482
+ hasShowThoughts: modelInf?.hasShowThoughts ?? false
2483
+ };
2484
+ };
2413
2485
  super({
2414
2486
  apiKey,
2415
2487
  config: {
@@ -2418,7 +2490,8 @@ var AxAIOpenAI = class extends AxAIOpenAIBase {
2418
2490
  },
2419
2491
  options,
2420
2492
  modelInfo: axModelInfoOpenAI,
2421
- models
2493
+ models,
2494
+ supportFor: supportForFn
2422
2495
  });
2423
2496
  super.setName("OpenAI");
2424
2497
  }
@@ -2457,7 +2530,16 @@ var AxAIAzureOpenAI = class extends AxAIOpenAIBase {
2457
2530
  config: _config,
2458
2531
  options,
2459
2532
  models,
2460
- modelInfo: axModelInfoOpenAI
2533
+ modelInfo: axModelInfoOpenAI,
2534
+ supportFor: (model) => {
2535
+ const modelInf = axModelInfoOpenAI.find((m) => m.name === model);
2536
+ return {
2537
+ functions: true,
2538
+ streaming: true,
2539
+ hasThinkingBudget: modelInf?.hasThinkingBudget ?? false,
2540
+ hasShowThoughts: modelInf?.hasShowThoughts ?? false
2541
+ };
2542
+ }
2461
2543
  });
2462
2544
  const host = resourceName.includes("://") ? resourceName : `https://${resourceName}.openai.azure.com/`;
2463
2545
  super.setName("Azure OpenAI");
@@ -2916,14 +2998,18 @@ var axModelInfoGoogleGemini = [
2916
2998
  currency: "usd",
2917
2999
  characterIsToken: false,
2918
3000
  promptTokenCostPer1M: 2.5,
2919
- completionTokenCostPer1M: 15
3001
+ completionTokenCostPer1M: 15,
3002
+ hasThinkingBudget: true,
3003
+ hasShowThoughts: true
2920
3004
  },
2921
3005
  {
2922
3006
  name: "gemini-2.5-flash-preview-04-17" /* Gemini25Flash */,
2923
3007
  currency: "usd",
2924
3008
  characterIsToken: false,
2925
3009
  promptTokenCostPer1M: 15,
2926
- completionTokenCostPer1M: 3.5
3010
+ completionTokenCostPer1M: 3.5,
3011
+ hasThinkingBudget: true,
3012
+ hasShowThoughts: true
2927
3013
  },
2928
3014
  {
2929
3015
  name: "gemini-2.0-flash" /* Gemini20Flash */,
@@ -3398,7 +3484,16 @@ var AxAIGoogleGemini = class extends AxBaseAI {
3398
3484
  embedModel: _config.embedModel
3399
3485
  },
3400
3486
  options,
3401
- supportFor: { functions: true, streaming: true },
3487
+ supportFor: (model) => {
3488
+ const modelInf = axModelInfoGoogleGemini.find((m) => m.name === model);
3489
+ return {
3490
+ functions: true,
3491
+ streaming: true,
3492
+ hasThinkingBudget: modelInf?.hasThinkingBudget ?? false,
3493
+ hasShowThoughts: modelInf?.hasShowThoughts ?? false,
3494
+ functionCot: false
3495
+ };
3496
+ },
3402
3497
  models
3403
3498
  });
3404
3499
  }
@@ -4188,7 +4283,8 @@ var axModelInfoGrok = [
4188
4283
  name: "grok-3-mini" /* Grok3Mini */,
4189
4284
  currency: "USD",
4190
4285
  promptTokenCostPer1M: 0.3,
4191
- completionTokenCostPer1M: 0.5
4286
+ completionTokenCostPer1M: 0.5,
4287
+ hasThinkingBudget: true
4192
4288
  },
4193
4289
  {
4194
4290
  name: "grok-3-fast" /* Grok3Fast */,
@@ -4200,7 +4296,8 @@ var axModelInfoGrok = [
4200
4296
  name: "grok-3-mini-fast" /* Grok3MiniFast */,
4201
4297
  currency: "USD",
4202
4298
  promptTokenCostPer1M: 0.6,
4203
- completionTokenCostPer1M: 4
4299
+ completionTokenCostPer1M: 4,
4300
+ hasThinkingBudget: true
4204
4301
  }
4205
4302
  ];
4206
4303
 
@@ -4233,7 +4330,16 @@ var AxAIGrok = class extends AxAIOpenAIBase {
4233
4330
  options,
4234
4331
  apiURL: "https://api.x.ai/v1",
4235
4332
  modelInfo: axModelInfoGrok,
4236
- models
4333
+ models,
4334
+ supportFor: (model) => {
4335
+ const modelInf = axModelInfoGrok.find((m) => m.name === model);
4336
+ return {
4337
+ functions: true,
4338
+ streaming: true,
4339
+ hasThinkingBudget: modelInf?.hasThinkingBudget ?? false,
4340
+ hasShowThoughts: modelInf?.hasShowThoughts ?? false
4341
+ };
4342
+ }
4237
4343
  });
4238
4344
  super.setName("Grok");
4239
4345
  }
@@ -7070,7 +7176,7 @@ Content: ${result.content}`
7070
7176
  return false;
7071
7177
  }
7072
7178
  async *_forward1(ai, values, options) {
7073
- const tracer = options?.tracer ?? this.options?.tracer;
7179
+ const tracer = options?.tracer ?? this.options?.tracer ?? ai.getOptions().tracer;
7074
7180
  let functions = this.functions;
7075
7181
  if (options?.functions) {
7076
7182
  functions = parseFunctions(options.functions, this.functions);