@ax-llm/ax 11.0.34 → 11.0.35

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.js CHANGED
@@ -734,8 +734,8 @@ var AxBaseAI = class {
734
734
  this.modelInfo = modelInfo;
735
735
  this.models = models;
736
736
  this.id = crypto.randomUUID();
737
- const model = this.models?.find((v) => v.key === defaults.model)?.model ?? defaults.model;
738
- const embedModel = defaults.embedModel;
737
+ const model = this.getModel(defaults.model) ?? defaults.model;
738
+ const embedModel = this.getEmbedModel(defaults.embedModel);
739
739
  this.defaults = { model, embedModel };
740
740
  if (!defaults.model || typeof defaults.model !== "string" || defaults.model === "") {
741
741
  throw new Error("No model defined");
@@ -801,18 +801,10 @@ var AxBaseAI = class {
801
801
  this.headers = headers;
802
802
  }
803
803
  setOptions(options) {
804
- if (options.debug) {
805
- this.debug = options.debug;
806
- }
807
- if (options.rateLimiter) {
808
- this.rt = options.rateLimiter;
809
- }
810
- if (options.fetch) {
811
- this.fetch = options.fetch;
812
- }
813
- if (options.tracer) {
814
- this.tracer = options.tracer;
815
- }
804
+ this.debug = options.debug ?? false;
805
+ this.rt = options.rateLimiter;
806
+ this.fetch = options.fetch;
807
+ this.tracer = options.tracer;
816
808
  }
817
809
  getOptions() {
818
810
  return {
@@ -823,11 +815,27 @@ var AxBaseAI = class {
823
815
  };
824
816
  }
825
817
  getModelList() {
826
- return this.models?.filter((model) => !model.isInternal)?.map((model) => ({
827
- key: model.key,
828
- description: model.description,
829
- model: model.model
830
- }));
818
+ const models = [];
819
+ for (const model of this.models ?? []) {
820
+ if (model.isInternal) {
821
+ continue;
822
+ }
823
+ if ("model" in model && model.model) {
824
+ models.push({
825
+ key: model.key,
826
+ description: model.description,
827
+ model: model.model
828
+ });
829
+ }
830
+ if ("embedModel" in model && model.embedModel) {
831
+ models.push({
832
+ key: model.key,
833
+ description: model.description,
834
+ embedModel: model.embedModel
835
+ });
836
+ }
837
+ }
838
+ return models;
831
839
  }
832
840
  getDefaultModels() {
833
841
  return {
@@ -888,7 +896,7 @@ var AxBaseAI = class {
888
896
  }
889
897
  }
890
898
  async _chat1(req, options) {
891
- const model = req.model ? this.models?.find((v) => v.key === req.model)?.model ?? req.model : this.defaults.model;
899
+ const model = this.getModel(req.model) ?? req.model ?? this.defaults.model;
892
900
  const modelConfig = {
893
901
  ...this.aiImpl.getModelConfig(),
894
902
  ...req.modelConfig
@@ -952,6 +960,7 @@ var AxBaseAI = class {
952
960
  if (!this.aiImpl.createChatReq) {
953
961
  throw new Error("generateChatReq not implemented");
954
962
  }
963
+ const debug = options?.debug ?? this.debug;
955
964
  let functions;
956
965
  if (chatReq.functions && chatReq.functions.length > 0) {
957
966
  functions = chatReq.functions.map((fn2) => this.cleanupFunctionSchema(fn2));
@@ -973,7 +982,7 @@ var AxBaseAI = class {
973
982
  url: this.apiURL,
974
983
  headers: await this.buildHeaders(apiConfig.headers),
975
984
  stream: modelConfig.stream,
976
- debug: this.debug,
985
+ debug,
977
986
  fetch: this.fetch,
978
987
  span
979
988
  },
@@ -981,7 +990,7 @@ var AxBaseAI = class {
981
990
  );
982
991
  return res2;
983
992
  };
984
- if (options?.debug ?? this.debug) {
993
+ if (debug) {
985
994
  logChatRequest(req.chatPrompt, options?.debugHideSystemPrompt);
986
995
  }
987
996
  const rt = options?.rateLimiter ?? this.rt;
@@ -1000,13 +1009,13 @@ var AxBaseAI = class {
1000
1009
  if (span?.isRecording()) {
1001
1010
  setResponseAttr(res2, span);
1002
1011
  }
1003
- if (options?.debug ?? this.debug) {
1012
+ if (debug) {
1004
1013
  logResponse(res2);
1005
1014
  }
1006
1015
  return res2;
1007
1016
  };
1008
1017
  const doneCb = async (_values) => {
1009
- if (options?.debug ?? this.debug) {
1018
+ if (debug) {
1010
1019
  process.stdout.write("\n");
1011
1020
  }
1012
1021
  };
@@ -1029,7 +1038,7 @@ var AxBaseAI = class {
1029
1038
  if (span?.isRecording()) {
1030
1039
  setResponseAttr(res, span);
1031
1040
  }
1032
- if (options?.debug ?? this.debug) {
1041
+ if (debug) {
1033
1042
  logResponse(res);
1034
1043
  }
1035
1044
  span?.end();
@@ -1050,7 +1059,7 @@ var AxBaseAI = class {
1050
1059
  }
1051
1060
  }
1052
1061
  async _embed1(req, options) {
1053
- const embedModel = req.embedModel ?? this.defaults.embedModel;
1062
+ const embedModel = this.getEmbedModel(req.embedModel) ?? req.embedModel ?? this.defaults.embedModel;
1054
1063
  if (!embedModel) {
1055
1064
  throw new Error("No embed model defined");
1056
1065
  }
@@ -1082,6 +1091,7 @@ var AxBaseAI = class {
1082
1091
  if (!this.aiImpl.createEmbedResp) {
1083
1092
  throw new Error("generateEmbedResp not implemented");
1084
1093
  }
1094
+ const debug = options?.debug ?? this.debug;
1085
1095
  const req = {
1086
1096
  ...embedReq,
1087
1097
  embedModel
@@ -1093,7 +1103,7 @@ var AxBaseAI = class {
1093
1103
  name: apiConfig.name,
1094
1104
  url: this.apiURL,
1095
1105
  headers: await this.buildHeaders(apiConfig.headers),
1096
- debug: this.debug,
1106
+ debug,
1097
1107
  fetch: this.fetch,
1098
1108
  span
1099
1109
  },
@@ -1119,6 +1129,21 @@ var AxBaseAI = class {
1119
1129
  async buildHeaders(headers = {}) {
1120
1130
  return { ...headers, ...await this.headers() };
1121
1131
  }
1132
+ getModelByKey(modelName) {
1133
+ if (!modelName) {
1134
+ return void 0;
1135
+ }
1136
+ const item = this.models?.find((v) => v.key === modelName);
1137
+ return item;
1138
+ }
1139
+ getModel(modelName) {
1140
+ const item = this.getModelByKey(modelName);
1141
+ return item && "model" in item ? item.model : void 0;
1142
+ }
1143
+ getEmbedModel(modelName) {
1144
+ const item = this.getModelByKey(modelName);
1145
+ return item && "embedModel" in item ? item.embedModel : void 0;
1146
+ }
1122
1147
  };
1123
1148
  function setResponseAttr(res, span) {
1124
1149
  if (res.modelUsage) {
@@ -1645,10 +1670,12 @@ function mapFinishReason(stopReason) {
1645
1670
  // ai/openai/types.ts
1646
1671
  var AxAIOpenAIModel = /* @__PURE__ */ ((AxAIOpenAIModel2) => {
1647
1672
  AxAIOpenAIModel2["O1"] = "o1";
1673
+ AxAIOpenAIModel2["O3"] = "o3";
1648
1674
  AxAIOpenAIModel2["O1Mini"] = "o1-mini";
1649
1675
  AxAIOpenAIModel2["O3Mini"] = "o3-mini";
1676
+ AxAIOpenAIModel2["O4Mini"] = "o4-mini";
1650
1677
  AxAIOpenAIModel2["GPT4"] = "gpt-4";
1651
- AxAIOpenAIModel2["GPT45"] = "gpt-4.5-preview";
1678
+ AxAIOpenAIModel2["GPT41"] = "gpt-4.1";
1652
1679
  AxAIOpenAIModel2["GPT4O"] = "gpt-4o";
1653
1680
  AxAIOpenAIModel2["GPT4OMini"] = "gpt-4o-mini";
1654
1681
  AxAIOpenAIModel2["GPT4ChatGPT4O"] = "chatgpt-4o-latest";
@@ -1669,12 +1696,6 @@ var AxAIOpenAIEmbedModel = /* @__PURE__ */ ((AxAIOpenAIEmbedModel2) => {
1669
1696
 
1670
1697
  // ai/openai/info.ts
1671
1698
  var axModelInfoOpenAI = [
1672
- {
1673
- name: "gpt-4.5-preview" /* GPT45 */,
1674
- currency: "usd",
1675
- promptTokenCostPer1M: 75,
1676
- completionTokenCostPer1M: 150
1677
- },
1678
1699
  {
1679
1700
  name: "o1" /* O1 */,
1680
1701
  currency: "usd",
@@ -1693,12 +1714,24 @@ var axModelInfoOpenAI = [
1693
1714
  promptTokenCostPer1M: 1.1,
1694
1715
  completionTokenCostPer1M: 4.4
1695
1716
  },
1717
+ {
1718
+ name: "o4-mini" /* O4Mini */,
1719
+ currency: "usd",
1720
+ promptTokenCostPer1M: 1.1,
1721
+ completionTokenCostPer1M: 4.4
1722
+ },
1696
1723
  {
1697
1724
  name: "gpt-4" /* GPT4 */,
1698
1725
  currency: "usd",
1699
1726
  promptTokenCostPer1M: 30,
1700
1727
  completionTokenCostPer1M: 60
1701
1728
  },
1729
+ {
1730
+ name: "gpt-4.1" /* GPT41 */,
1731
+ currency: "usd",
1732
+ promptTokenCostPer1M: 2,
1733
+ completionTokenCostPer1M: 8
1734
+ },
1702
1735
  {
1703
1736
  name: "gpt-4o" /* GPT4O */,
1704
1737
  currency: "usd",
@@ -2503,8 +2536,8 @@ var AxAIDeepSeek = class extends AxAIOpenAIBase {
2503
2536
 
2504
2537
  // ai/google-gemini/types.ts
2505
2538
  var AxAIGoogleGeminiModel = /* @__PURE__ */ ((AxAIGoogleGeminiModel2) => {
2506
- AxAIGoogleGeminiModel2["Gemini25Pro"] = "gemini-2.5-pro-exp-03-25";
2507
- AxAIGoogleGeminiModel2["Gemini20Pro"] = "gemini-2.0-pro-exp-02-05";
2539
+ AxAIGoogleGeminiModel2["Gemini25Pro"] = "gemini-2.5-pro-preview-03-25";
2540
+ AxAIGoogleGeminiModel2["Gemini25Flash"] = "gemini-2.5-flash-preview-04-17";
2508
2541
  AxAIGoogleGeminiModel2["Gemini20Flash"] = "gemini-2.0-flash";
2509
2542
  AxAIGoogleGeminiModel2["Gemini20FlashLite"] = "gemini-2.0-flash-lite-preview-02-05";
2510
2543
  AxAIGoogleGeminiModel2["Gemini20FlashThinking"] = "gemini-2.0-flash-thinking-exp-01-21";
@@ -2552,11 +2585,18 @@ var AxAIGoogleGeminiEmbedTypes = /* @__PURE__ */ ((AxAIGoogleGeminiEmbedTypes2)
2552
2585
  // ai/google-gemini/info.ts
2553
2586
  var axModelInfoGoogleGemini = [
2554
2587
  {
2555
- name: "gemini-2.0-pro-exp-02-05" /* Gemini20Pro */,
2588
+ name: "gemini-2.5-pro-preview-03-25" /* Gemini25Pro */,
2556
2589
  currency: "usd",
2557
2590
  characterIsToken: false,
2558
- promptTokenCostPer1M: 0,
2559
- completionTokenCostPer1M: 0
2591
+ promptTokenCostPer1M: 2.5,
2592
+ completionTokenCostPer1M: 15
2593
+ },
2594
+ {
2595
+ name: "gemini-2.5-flash-preview-04-17" /* Gemini25Flash */,
2596
+ currency: "usd",
2597
+ characterIsToken: false,
2598
+ promptTokenCostPer1M: 15,
2599
+ completionTokenCostPer1M: 3.5
2560
2600
  },
2561
2601
  {
2562
2602
  name: "gemini-2.0-flash" /* Gemini20Flash */,
@@ -2810,7 +2850,10 @@ var AxAIGoogleGeminiImpl = class {
2810
2850
  frequencyPenalty: req.modelConfig?.frequencyPenalty ?? this.config.frequencyPenalty,
2811
2851
  candidateCount: 1,
2812
2852
  stopSequences: req.modelConfig?.stopSequences ?? this.config.stopSequences,
2813
- responseMimeType: "text/plain"
2853
+ responseMimeType: "text/plain",
2854
+ ...this.config.thinkingConfig && {
2855
+ thinkingConfig: this.config.thinkingConfig
2856
+ }
2814
2857
  };
2815
2858
  const safetySettings2 = this.config.safetySettings;
2816
2859
  const reqValue = {
@@ -6424,10 +6467,8 @@ var AxGen = class extends AxProgramWithSignature {
6424
6467
  const maxRetries = options.maxRetries ?? this.options?.maxRetries ?? 10;
6425
6468
  const maxSteps = options.maxSteps ?? this.options?.maxSteps ?? 10;
6426
6469
  const debug = options.debug ?? ai.getOptions().debug;
6427
- const memOptions = {
6428
- debug: options.debug,
6429
- debugHideSystemPrompt: options.debugHideSystemPrompt
6430
- };
6470
+ const debugHideSystemPrompt = options.debugHideSystemPrompt;
6471
+ const memOptions = { debug, debugHideSystemPrompt };
6431
6472
  const mem = options.mem ?? this.options?.mem ?? new AxMemory(1e4, memOptions);
6432
6473
  let err;
6433
6474
  if (options?.functions && options.functions.length > 0) {
@@ -6505,7 +6546,7 @@ var AxGen = class extends AxProgramWithSignature {
6505
6546
  return false;
6506
6547
  }
6507
6548
  async *_forward1(ai, values, options) {
6508
- const tracer = this.options?.tracer ?? options?.tracer;
6549
+ const tracer = options?.tracer ?? this.options?.tracer;
6509
6550
  let functions = this.functions;
6510
6551
  if (options?.functions) {
6511
6552
  functions = parseFunctions(options.functions, this.functions);
@@ -6541,9 +6582,7 @@ var AxGen = class extends AxProgramWithSignature {
6541
6582
  }
6542
6583
  }
6543
6584
  async forward(ai, values, options) {
6544
- const generator = this._forward1(ai, values, {
6545
- ...options
6546
- });
6585
+ const generator = this._forward1(ai, values, options ?? {});
6547
6586
  let buffer = {};
6548
6587
  let currentVersion = 0;
6549
6588
  for await (const item of generator) {
@@ -9207,7 +9246,7 @@ var AxMockAIService = class {
9207
9246
  }
9208
9247
  };
9209
9248
 
9210
- // dsp/router.ts
9249
+ // dsp/classifier.ts
9211
9250
  var colorLog6 = new ColorLog();
9212
9251
  var AxSimpleClassifierClass = class {
9213
9252
  name;
@@ -11016,6 +11055,7 @@ var AxMCPStdioTransport = class {
11016
11055
 
11017
11056
  // ai/multiservice.ts
11018
11057
  var AxMultiServiceRouter = class {
11058
+ options;
11019
11059
  services = /* @__PURE__ */ new Map();
11020
11060
  /**
11021
11061
  * Constructs a new multi-service router.
@@ -11036,9 +11076,7 @@ var AxMultiServiceRouter = class {
11036
11076
  this.services.set(item.key, {
11037
11077
  service,
11038
11078
  description,
11039
- isInternal,
11040
- model: item.service.getDefaultModels().model,
11041
- useDefaultModel: true
11079
+ isInternal
11042
11080
  });
11043
11081
  } else {
11044
11082
  const modelList = item.getModelList();
@@ -11047,18 +11085,31 @@ var AxMultiServiceRouter = class {
11047
11085
  `Service ${index} \`${item.getName()}\` has no model list.`
11048
11086
  );
11049
11087
  }
11050
- for (const { key, description, model } of modelList ?? []) {
11051
- if (this.services.has(key)) {
11052
- const otherService = this.services.get(key)?.service;
11088
+ for (const v of modelList) {
11089
+ if (this.services.has(v.key)) {
11090
+ const otherService = this.services.get(v.key)?.service;
11053
11091
  throw new Error(
11054
- `Service ${index} \`${item.getName()}\` has duplicate model key: ${key} as service ${otherService?.getName()}`
11092
+ `Service ${index} \`${item.getName()}\` has duplicate model key: ${v.key} as service ${otherService?.getName()}`
11055
11093
  );
11094
+ } else {
11095
+ if ("model" in v && typeof v.model) {
11096
+ this.services.set(v.key, {
11097
+ description: v.description,
11098
+ service: item,
11099
+ model: v.model
11100
+ });
11101
+ } else if ("embedModel" in v && v.embedModel) {
11102
+ this.services.set(v.key, {
11103
+ description: v.description,
11104
+ service: item,
11105
+ embedModel: v.embedModel
11106
+ });
11107
+ } else {
11108
+ throw new Error(
11109
+ `Key ${v.key} in model list for service ${index} \`${item.getName()}\` is missing a model or embedModel property.`
11110
+ );
11111
+ }
11056
11112
  }
11057
- this.services.set(key, {
11058
- description,
11059
- service: item,
11060
- model
11061
- });
11062
11113
  }
11063
11114
  }
11064
11115
  }
@@ -11075,25 +11126,32 @@ var AxMultiServiceRouter = class {
11075
11126
  if (!item) {
11076
11127
  throw new Error(`No service found for model key: ${modelKey}`);
11077
11128
  }
11078
- const service = item.service;
11079
- const model = item.useDefaultModel ? req.model : modelKey;
11080
- return await service.chat({ model, ...req }, options);
11129
+ if (!item.model) {
11130
+ const { model, ...reqWithoutModel } = req;
11131
+ return await item.service.chat(reqWithoutModel, options);
11132
+ }
11133
+ return await item.service.chat({ model: modelKey, ...req }, options);
11081
11134
  }
11082
11135
  /**
11083
11136
  * Delegates the embed call to the service matching the provided embed model key.
11084
11137
  */
11085
11138
  async embed(req, options) {
11086
- const modelKey = req.embedModel;
11087
- if (!modelKey) {
11139
+ const embedModelKey = req.embedModel;
11140
+ if (!embedModelKey) {
11088
11141
  throw new Error("Embed model key must be specified for multi-service");
11089
11142
  }
11090
- const item = this.services.get(modelKey);
11143
+ const item = this.services.get(embedModelKey);
11091
11144
  if (!item) {
11092
- throw new Error(`No service found for embed model key: ${modelKey}`);
11145
+ throw new Error(`No service found for embed model key: ${embedModelKey}`);
11146
+ }
11147
+ if (!item.model) {
11148
+ const { embedModel, ...reqWithoutEmbedModel } = req;
11149
+ return await item.service.embed(reqWithoutEmbedModel, options);
11093
11150
  }
11094
- const service = item.service;
11095
- const embedModel = item.useDefaultModel ? req.embedModel : modelKey;
11096
- return await service.embed({ embedModel, ...req }, options);
11151
+ return await item.service.embed(
11152
+ { embedModel: embedModelKey, ...req },
11153
+ options
11154
+ );
11097
11155
  }
11098
11156
  /**
11099
11157
  * Returns a composite ID built from the IDs of the underlying services.
@@ -11111,11 +11169,15 @@ var AxMultiServiceRouter = class {
11111
11169
  * Aggregates all available models across the underlying services.
11112
11170
  */
11113
11171
  getModelList() {
11114
- return Array.from(this.services).filter(([, value]) => !value.isInternal).map(([key, { description, model }]) => ({
11115
- key,
11116
- description,
11117
- model
11118
- }));
11172
+ return Array.from(this.services).filter(([, value]) => !value.isInternal).map(([key, v]) => {
11173
+ if (v.model) {
11174
+ return { key, description: v.description, model: v.model };
11175
+ } else if (v.embedModel) {
11176
+ return { key, description: v.description, embedModel: v.embedModel };
11177
+ } else {
11178
+ throw new Error(`Service ${key} has no model or embedModel`);
11179
+ }
11180
+ });
11119
11181
  }
11120
11182
  getDefaultModels() {
11121
11183
  throw new Error(
@@ -11154,17 +11216,14 @@ var AxMultiServiceRouter = class {
11154
11216
  for (const service of this.services.values()) {
11155
11217
  service.service.setOptions(options);
11156
11218
  }
11219
+ this.options = options;
11157
11220
  }
11158
11221
  /**
11159
11222
  * Returns the options from the last used service,
11160
11223
  * or falls back to the first service if none has been used.
11161
11224
  */
11162
11225
  getOptions() {
11163
- const service = this.services.values().next().value;
11164
- if (!service) {
11165
- throw new Error("No service available to get options.");
11166
- }
11167
- return service.service.getOptions();
11226
+ return this.options ?? {};
11168
11227
  }
11169
11228
  };
11170
11229