@ax-llm/ax 10.0.50 → 11.0.0

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
@@ -114,9 +114,9 @@ var import_api2 = require("@opentelemetry/api");
114
114
  function getModelInfo({
115
115
  model,
116
116
  modelInfo,
117
- modelMap = {}
117
+ models
118
118
  }) {
119
- const mappedModel = modelMap?.[model] ?? model;
119
+ const mappedModel = models?.find((v) => v.key === model)?.model ?? model;
120
120
  const exactMatch = modelInfo.find((v) => v.name === model);
121
121
  if (exactMatch) return exactMatch;
122
122
  const normalizedName = mappedModel.replace(/^(anthropic\.|openai\.)/, "").replace(/-latest$/, "").replace(/-\d{8}$/, "").replace(/-v\d+:\d+$/, "").replace(/@\d{8}$/, "").replace(/-\d{2,}(-[a-zA-Z0-9-]+)?$/, "").replace(/-v\d+@\d{8}$/, "").replace(/-v\d+$/, "");
@@ -737,10 +737,10 @@ var AxBaseAI = class {
737
737
  apiURL,
738
738
  headers,
739
739
  modelInfo,
740
- models,
740
+ defaults,
741
741
  options = {},
742
742
  supportFor,
743
- modelMap
743
+ models
744
744
  }) {
745
745
  this.aiImpl = aiImpl;
746
746
  this.name = name;
@@ -749,12 +749,11 @@ var AxBaseAI = class {
749
749
  this.supportFor = supportFor;
750
750
  this.tracer = options.tracer;
751
751
  this.modelInfo = modelInfo;
752
- this.modelMap = modelMap;
753
- this.models = {
754
- model: modelMap?.[models.model] ?? models.model,
755
- embedModel: modelMap?.[models.embedModel ?? ""] ?? models.embedModel
756
- };
757
- if (!models.model || typeof models.model !== "string" || models.model === "") {
752
+ this.models = models;
753
+ const model = this.models?.find((v) => v.key === defaults.model)?.model ?? defaults.model;
754
+ const embedModel = this.models?.find((v) => v.key === defaults.embedModel)?.model ?? defaults.embedModel;
755
+ this.defaults = { model, embedModel };
756
+ if (!defaults.model || typeof defaults.model !== "string" || defaults.model === "") {
758
757
  throw new Error("No model defined");
759
758
  }
760
759
  this.setOptions(options);
@@ -763,11 +762,11 @@ var AxBaseAI = class {
763
762
  rt;
764
763
  fetch;
765
764
  tracer;
766
- modelMap;
765
+ models;
767
766
  modelInfo;
768
767
  modelUsage;
769
768
  embedModelUsage;
770
- models;
769
+ defaults;
771
770
  apiURL;
772
771
  name;
773
772
  headers;
@@ -834,9 +833,9 @@ var AxBaseAI = class {
834
833
  }
835
834
  getModelInfo() {
836
835
  const mi = getModelInfo({
837
- model: this.models.model,
836
+ model: this.defaults.model,
838
837
  modelInfo: this.modelInfo,
839
- modelMap: this.modelMap
838
+ models: this.models
840
839
  });
841
840
  return {
842
841
  ...mi,
@@ -844,27 +843,27 @@ var AxBaseAI = class {
844
843
  };
845
844
  }
846
845
  getEmbedModelInfo() {
847
- if (!this.models.embedModel) {
846
+ if (!this.defaults.embedModel) {
848
847
  return;
849
848
  }
850
849
  const mi = getModelInfo({
851
- model: this.models.embedModel,
850
+ model: this.defaults.embedModel,
852
851
  modelInfo: this.modelInfo,
853
- modelMap: this.modelMap
852
+ models: this.models
854
853
  });
855
854
  return {
856
855
  ...mi,
857
856
  provider: this.name
858
857
  };
859
858
  }
860
- getModelMap() {
861
- return this.modelMap;
859
+ getModelList() {
860
+ return this.models;
862
861
  }
863
862
  getName() {
864
863
  return this.name;
865
864
  }
866
865
  getFeatures(model) {
867
- return typeof this.supportFor === "function" ? this.supportFor(model ?? this.models.model) : this.supportFor;
866
+ return typeof this.supportFor === "function" ? this.supportFor(model ?? this.defaults.model) : this.supportFor;
868
867
  }
869
868
  // Method to calculate percentiles
870
869
  calculatePercentile(samples, percentile) {
@@ -912,7 +911,7 @@ var AxBaseAI = class {
912
911
  }
913
912
  }
914
913
  async _chat1(req, options) {
915
- const model = req.model ? this.modelMap?.[req.model] ?? req.model : this.modelMap?.[this.models.model] ?? this.models.model;
914
+ const model = req.model ? this.models?.find((v) => v.key === req.model)?.model ?? req.model : this.defaults.model;
916
915
  const modelConfig = {
917
916
  ...this.aiImpl.getModelConfig(),
918
917
  ...req.modelConfig
@@ -1056,7 +1055,7 @@ var AxBaseAI = class {
1056
1055
  }
1057
1056
  }
1058
1057
  async _embed1(req, options) {
1059
- const embedModel = req.embedModel ? this.modelMap?.[req.embedModel] ?? req.embedModel : this.modelMap?.[this.models.embedModel ?? ""] ?? this.models.embedModel;
1058
+ const embedModel = req.embedModel ? this.models?.find((v) => v.key === req.embedModel)?.model ?? req.embedModel : this.defaults.embedModel;
1060
1059
  if (!embedModel) {
1061
1060
  throw new Error("No embed model defined");
1062
1061
  }
@@ -1067,7 +1066,7 @@ var AxBaseAI = class {
1067
1066
  kind: import_api2.SpanKind.SERVER,
1068
1067
  attributes: {
1069
1068
  [axSpanAttributes.LLM_SYSTEM]: this.name,
1070
- [axSpanAttributes.LLM_REQUEST_MODEL]: req.embedModel ?? this.models.embedModel
1069
+ [axSpanAttributes.LLM_REQUEST_MODEL]: req.embedModel ?? this.defaults.embedModel
1071
1070
  }
1072
1071
  },
1073
1072
  async (span) => {
@@ -1540,7 +1539,7 @@ var AxAIAnthropic = class extends AxBaseAI {
1540
1539
  region,
1541
1540
  config,
1542
1541
  options,
1543
- modelMap
1542
+ models
1544
1543
  }) {
1545
1544
  const isVertex = projectId !== void 0 && region !== void 0;
1546
1545
  let apiURL;
@@ -1576,10 +1575,10 @@ var AxAIAnthropic = class extends AxBaseAI {
1576
1575
  apiURL,
1577
1576
  headers,
1578
1577
  modelInfo: axModelInfoAnthropic,
1579
- models: { model: _config.model },
1578
+ defaults: { model: _config.model },
1580
1579
  options,
1581
- supportFor: { functions: true, streaming: true },
1582
- modelMap
1580
+ supportFor: { functions: true, streaming: true, functionCot: true },
1581
+ models
1583
1582
  });
1584
1583
  }
1585
1584
  };
@@ -2063,7 +2062,7 @@ var AxAIOpenAI = class extends AxBaseAI {
2063
2062
  options,
2064
2063
  apiURL,
2065
2064
  modelInfo = axModelInfoOpenAI,
2066
- modelMap
2065
+ models
2067
2066
  }) {
2068
2067
  if (!apiKey || apiKey === "") {
2069
2068
  throw new Error("OpenAI API key not set");
@@ -2082,7 +2081,7 @@ var AxAIOpenAI = class extends AxBaseAI {
2082
2081
  apiURL: apiURL ? apiURL : "https://api.openai.com/v1",
2083
2082
  headers: async () => ({ Authorization: `Bearer ${apiKey}` }),
2084
2083
  modelInfo,
2085
- models: {
2084
+ defaults: {
2086
2085
  model: _config.model,
2087
2086
  embedModel: _config.embedModel
2088
2087
  },
@@ -2090,7 +2089,7 @@ var AxAIOpenAI = class extends AxBaseAI {
2090
2089
  supportFor: () => {
2091
2090
  return { functions: true, streaming: true };
2092
2091
  },
2093
- modelMap
2092
+ models
2094
2093
  });
2095
2094
  }
2096
2095
  };
@@ -2108,7 +2107,7 @@ var AxAIAzureOpenAI = class extends AxAIOpenAI {
2108
2107
  version = "api-version=2024-02-15-preview",
2109
2108
  config,
2110
2109
  options,
2111
- modelMap
2110
+ models
2112
2111
  }) {
2113
2112
  if (!apiKey || apiKey === "") {
2114
2113
  throw new Error("Azure OpenAPI API key not set");
@@ -2123,7 +2122,7 @@ var AxAIAzureOpenAI = class extends AxAIOpenAI {
2123
2122
  ...axAIAzureOpenAIDefaultConfig(),
2124
2123
  ...config
2125
2124
  };
2126
- super({ apiKey, config: _config, options, modelMap });
2125
+ super({ apiKey, config: _config, options, models });
2127
2126
  const host = resourceName.includes("://") ? resourceName : `https://${resourceName}.openai.azure.com/`;
2128
2127
  super.setName("Azure OpenAI");
2129
2128
  super.setAPIURL(
@@ -2379,7 +2378,7 @@ var AxAICohere = class extends AxBaseAI {
2379
2378
  apiKey,
2380
2379
  config,
2381
2380
  options,
2382
- modelMap
2381
+ models
2383
2382
  }) {
2384
2383
  if (!apiKey || apiKey === "") {
2385
2384
  throw new Error("Cohere API key not set");
@@ -2394,10 +2393,10 @@ var AxAICohere = class extends AxBaseAI {
2394
2393
  apiURL: "https://api.cohere.ai/v1",
2395
2394
  headers: async () => ({ Authorization: `Bearer ${apiKey}` }),
2396
2395
  modelInfo: axModelInfoCohere,
2397
- models: { model: _config.model },
2396
+ defaults: { model: _config.model },
2398
2397
  supportFor: { functions: true, streaming: true },
2399
2398
  options,
2400
- modelMap
2399
+ models
2401
2400
  });
2402
2401
  }
2403
2402
  };
@@ -2491,7 +2490,7 @@ var AxAIDeepSeek = class extends AxAIOpenAI {
2491
2490
  apiKey,
2492
2491
  config,
2493
2492
  options,
2494
- modelMap
2493
+ models
2495
2494
  }) {
2496
2495
  if (!apiKey || apiKey === "") {
2497
2496
  throw new Error("DeepSeek API key not set");
@@ -2506,7 +2505,7 @@ var AxAIDeepSeek = class extends AxAIOpenAI {
2506
2505
  options,
2507
2506
  apiURL: "https://api.deepseek.com",
2508
2507
  modelInfo: axModelInfoDeepSeek,
2509
- modelMap
2508
+ models
2510
2509
  });
2511
2510
  super.setName("DeepSeek");
2512
2511
  }
@@ -2514,6 +2513,10 @@ var AxAIDeepSeek = class extends AxAIOpenAI {
2514
2513
 
2515
2514
  // ai/google-gemini/types.ts
2516
2515
  var AxAIGoogleGeminiModel = /* @__PURE__ */ ((AxAIGoogleGeminiModel2) => {
2516
+ AxAIGoogleGeminiModel2["Gemini20Pro"] = "gemini-2.0-pro-exp-02-05";
2517
+ AxAIGoogleGeminiModel2["Gemini20Flash"] = "gemini-2.0-flash";
2518
+ AxAIGoogleGeminiModel2["Gemini20FlashLite"] = "gemini-2.0-flash-lite-preview-02-05";
2519
+ AxAIGoogleGeminiModel2["Gemini20FlashThinking"] = "gemini-2.0-flash-thinking-exp-01-21";
2517
2520
  AxAIGoogleGeminiModel2["Gemini1Pro"] = "gemini-1.0-pro";
2518
2521
  AxAIGoogleGeminiModel2["Gemini15Flash"] = "gemini-1.5-flash";
2519
2522
  AxAIGoogleGeminiModel2["Gemini15Flash8B"] = "gemini-1.5-flash-8b";
@@ -2545,31 +2548,59 @@ var AxAIGoogleGeminiSafetyThreshold = /* @__PURE__ */ ((AxAIGoogleGeminiSafetyTh
2545
2548
 
2546
2549
  // ai/google-gemini/info.ts
2547
2550
  var axModelInfoGoogleGemini = [
2551
+ {
2552
+ name: "gemini-2.0-pro-exp-02-05" /* Gemini20Pro */,
2553
+ currency: "usd",
2554
+ characterIsToken: false,
2555
+ promptTokenCostPer1M: 0,
2556
+ completionTokenCostPer1M: 0
2557
+ },
2558
+ {
2559
+ name: "gemini-2.0-flash" /* Gemini20Flash */,
2560
+ currency: "usd",
2561
+ characterIsToken: false,
2562
+ promptTokenCostPer1M: 0.01,
2563
+ completionTokenCostPer1M: 0.4
2564
+ },
2565
+ {
2566
+ name: "gemini-2.0-flash-lite-preview-02-05" /* Gemini20FlashLite */,
2567
+ currency: "usd",
2568
+ characterIsToken: false,
2569
+ promptTokenCostPer1M: 0,
2570
+ completionTokenCostPer1M: 0
2571
+ },
2572
+ {
2573
+ name: "gemini-2.0-flash-thinking-exp-01-21" /* Gemini20FlashThinking */,
2574
+ currency: "usd",
2575
+ characterIsToken: false,
2576
+ promptTokenCostPer1M: 0,
2577
+ completionTokenCostPer1M: 0
2578
+ },
2548
2579
  {
2549
2580
  name: "gemini-1.5-flash" /* Gemini15Flash */,
2550
2581
  currency: "usd",
2551
- characterIsToken: true,
2582
+ characterIsToken: false,
2552
2583
  promptTokenCostPer1M: 0.075,
2553
2584
  completionTokenCostPer1M: 0.3
2554
2585
  },
2555
2586
  {
2556
2587
  name: "gemini-1.5-flash-8b" /* Gemini15Flash8B */,
2557
2588
  currency: "usd",
2558
- characterIsToken: true,
2589
+ characterIsToken: false,
2559
2590
  promptTokenCostPer1M: 0.0375,
2560
2591
  completionTokenCostPer1M: 0.15
2561
2592
  },
2562
2593
  {
2563
2594
  name: "gemini-1.5-pro" /* Gemini15Pro */,
2564
2595
  currency: "usd",
2565
- characterIsToken: true,
2596
+ characterIsToken: false,
2566
2597
  promptTokenCostPer1M: 1.25,
2567
2598
  completionTokenCostPer1M: 5
2568
2599
  },
2569
2600
  {
2570
2601
  name: "gemini-1.0-pro" /* Gemini1Pro */,
2571
2602
  currency: "usd",
2572
- characterIsToken: true,
2603
+ characterIsToken: false,
2573
2604
  promptTokenCostPer1M: 0.5,
2574
2605
  completionTokenCostPer1M: 1.5
2575
2606
  }
@@ -2883,7 +2914,7 @@ var AxAIGoogleGemini = class extends AxBaseAI {
2883
2914
  region,
2884
2915
  config,
2885
2916
  options,
2886
- modelMap
2917
+ models
2887
2918
  }) {
2888
2919
  const isVertex = projectId !== void 0 && region !== void 0;
2889
2920
  let apiURL;
@@ -2915,13 +2946,13 @@ var AxAIGoogleGemini = class extends AxBaseAI {
2915
2946
  apiURL,
2916
2947
  headers,
2917
2948
  modelInfo: axModelInfoGoogleGemini,
2918
- models: {
2949
+ defaults: {
2919
2950
  model: _config.model,
2920
2951
  embedModel: _config.embedModel
2921
2952
  },
2922
2953
  options,
2923
2954
  supportFor: { functions: true, streaming: true },
2924
- modelMap
2955
+ models
2925
2956
  });
2926
2957
  }
2927
2958
  };
@@ -3023,7 +3054,7 @@ var AxAIGroq = class extends AxAIOpenAI {
3023
3054
  apiKey,
3024
3055
  config,
3025
3056
  options,
3026
- modelMap
3057
+ models
3027
3058
  }) {
3028
3059
  if (!apiKey || apiKey === "") {
3029
3060
  throw new Error("Groq API key not set");
@@ -3042,7 +3073,7 @@ var AxAIGroq = class extends AxAIOpenAI {
3042
3073
  options: _options,
3043
3074
  modelInfo: axModelInfoGroq,
3044
3075
  apiURL: "https://api.groq.com/openai/v1",
3045
- modelMap
3076
+ models
3046
3077
  });
3047
3078
  super.setName("Groq");
3048
3079
  this.setOptions(_options);
@@ -3166,7 +3197,7 @@ var AxAIHuggingFace = class extends AxBaseAI {
3166
3197
  apiKey,
3167
3198
  config,
3168
3199
  options,
3169
- modelMap
3200
+ models
3170
3201
  }) {
3171
3202
  if (!apiKey || apiKey === "") {
3172
3203
  throw new Error("HuggingFace API key not set");
@@ -3181,10 +3212,10 @@ var AxAIHuggingFace = class extends AxBaseAI {
3181
3212
  apiURL: "https://api-inference.huggingface.co",
3182
3213
  headers: async () => ({ Authorization: `Bearer ${apiKey}` }),
3183
3214
  modelInfo: axModelInfoHuggingFace,
3184
- models: { model: _config.model },
3215
+ defaults: { model: _config.model },
3185
3216
  options,
3186
3217
  supportFor: { functions: false, streaming: false },
3187
- modelMap
3218
+ models
3188
3219
  });
3189
3220
  }
3190
3221
  };
@@ -3268,7 +3299,7 @@ var AxAIMistral = class extends AxAIOpenAI {
3268
3299
  apiKey,
3269
3300
  config,
3270
3301
  options,
3271
- modelMap
3302
+ models
3272
3303
  }) {
3273
3304
  if (!apiKey || apiKey === "") {
3274
3305
  throw new Error("Mistral API key not set");
@@ -3283,7 +3314,7 @@ var AxAIMistral = class extends AxAIOpenAI {
3283
3314
  options,
3284
3315
  apiURL: "https://api.mistral.ai/v1",
3285
3316
  modelInfo: axModelInfoMistral,
3286
- modelMap
3317
+ models
3287
3318
  });
3288
3319
  super.setName("Mistral");
3289
3320
  }
@@ -3301,7 +3332,7 @@ var AxAIOllama = class extends AxAIOpenAI {
3301
3332
  url = "http://localhost:11434/v1",
3302
3333
  config,
3303
3334
  options,
3304
- modelMap
3335
+ models
3305
3336
  }) {
3306
3337
  const _config = {
3307
3338
  ...axAIOllamaDefaultConfig(),
@@ -3312,7 +3343,7 @@ var AxAIOllama = class extends AxAIOpenAI {
3312
3343
  options,
3313
3344
  config: _config,
3314
3345
  apiURL: url,
3315
- modelMap
3346
+ models
3316
3347
  });
3317
3348
  super.setName("Ollama");
3318
3349
  }
@@ -3515,7 +3546,7 @@ var AxAIReka = class extends AxBaseAI {
3515
3546
  options,
3516
3547
  apiURL,
3517
3548
  modelInfo = axModelInfoReka,
3518
- modelMap
3549
+ models
3519
3550
  }) {
3520
3551
  if (!apiKey || apiKey === "") {
3521
3552
  throw new Error("Reka API key not set");
@@ -3530,12 +3561,12 @@ var AxAIReka = class extends AxBaseAI {
3530
3561
  apiURL: apiURL ? apiURL : "https://api.reka.ai/v1/chat",
3531
3562
  headers: async () => ({ "X-Api-Key": apiKey }),
3532
3563
  modelInfo,
3533
- models: {
3564
+ defaults: {
3534
3565
  model: _config.model
3535
3566
  },
3536
3567
  options,
3537
3568
  supportFor: { functions: true, streaming: true },
3538
- modelMap
3569
+ models
3539
3570
  });
3540
3571
  }
3541
3572
  };
@@ -3554,7 +3585,7 @@ var AxAITogether = class extends AxAIOpenAI {
3554
3585
  apiKey,
3555
3586
  config,
3556
3587
  options,
3557
- modelMap
3588
+ models
3558
3589
  }) {
3559
3590
  if (!apiKey || apiKey === "") {
3560
3591
  throw new Error("Together API key not set");
@@ -3569,7 +3600,7 @@ var AxAITogether = class extends AxAIOpenAI {
3569
3600
  options,
3570
3601
  apiURL: "https://api.together.xyz/v1",
3571
3602
  modelInfo: axModelInfoTogether,
3572
- modelMap
3603
+ models
3573
3604
  });
3574
3605
  super.setName("Together");
3575
3606
  }
@@ -3632,8 +3663,8 @@ var AxAI = class {
3632
3663
  getFeatures(model) {
3633
3664
  return this.ai.getFeatures(model);
3634
3665
  }
3635
- getModelMap() {
3636
- return this.ai.getModelMap();
3666
+ getModelList() {
3667
+ return this.ai.getModelList();
3637
3668
  }
3638
3669
  getMetrics() {
3639
3670
  return this.ai.getMetrics();
@@ -5766,7 +5797,7 @@ var AxGen = class extends AxProgramWithSignature {
5766
5797
  traceId,
5767
5798
  functions
5768
5799
  }) {
5769
- const streamingValidation = !functions || functions.length == 0;
5800
+ const streamingValidation = ai.getFeatures().functionCot !== true;
5770
5801
  const functionCalls = [];
5771
5802
  const values = {};
5772
5803
  const xstate = {
@@ -6027,6 +6058,7 @@ var AxAgent = class {
6027
6058
  ai;
6028
6059
  signature;
6029
6060
  program;
6061
+ functions;
6030
6062
  agents;
6031
6063
  name;
6032
6064
  description;
@@ -6042,14 +6074,9 @@ var AxAgent = class {
6042
6074
  }, options) {
6043
6075
  this.ai = ai;
6044
6076
  this.agents = agents;
6077
+ this.functions = functions;
6045
6078
  this.signature = new AxSignature(signature);
6046
6079
  this.signature.setDescription(description);
6047
- const funcs = [
6048
- ...functions ?? [],
6049
- ...agents?.map((a) => a.getFunction()) ?? []
6050
- ];
6051
- const opt = { ...options, functions: funcs };
6052
- this.program = new AxGen(this.signature, opt);
6053
6080
  if (!name || name.length < 5) {
6054
6081
  throw new Error(
6055
6082
  `Agent name must be at least 10 characters (more descriptive): ${name}`
@@ -6060,6 +6087,10 @@ var AxAgent = class {
6060
6087
  `Agent description must be at least 20 characters (explain in detail what the agent does): ${description}`
6061
6088
  );
6062
6089
  }
6090
+ this.program = new AxGen(this.signature, options);
6091
+ for (const agent of agents ?? []) {
6092
+ this.program.register(agent);
6093
+ }
6063
6094
  this.name = name;
6064
6095
  this.description = description;
6065
6096
  this.subAgentList = agents?.map((a) => a.getFunction().name).join(", ");
@@ -6069,8 +6100,9 @@ var AxAgent = class {
6069
6100
  parameters: this.signature.toJSONSchema(),
6070
6101
  func: () => this.forward
6071
6102
  };
6072
- for (const agent of agents ?? []) {
6073
- this.program.register(agent);
6103
+ const mm = ai?.getModelList();
6104
+ if (mm) {
6105
+ this.func.parameters = addModelParameter(this.func.parameters, mm);
6074
6106
  }
6075
6107
  }
6076
6108
  setExamples(examples) {
@@ -6096,38 +6128,41 @@ var AxAgent = class {
6096
6128
  }
6097
6129
  getFunction() {
6098
6130
  const boundFunc = this.forward.bind(this);
6099
- const wrappedFunc = (values, options) => {
6131
+ const wrappedFunc = (valuesAndModel, options) => {
6132
+ const { model, ...values } = valuesAndModel;
6100
6133
  const ai = this.ai ?? options?.ai;
6101
6134
  if (!ai) {
6102
6135
  throw new Error("AI service is required to run the agent");
6103
6136
  }
6104
- return boundFunc(ai, values, options);
6137
+ return boundFunc(ai, values, { ...options, model });
6105
6138
  };
6106
6139
  return {
6107
6140
  ...this.func,
6108
6141
  func: wrappedFunc
6109
6142
  };
6110
6143
  }
6111
- init(ai, options) {
6112
- const _ai = this.ai ?? ai;
6113
- const funcs = [
6114
- ...options?.functions ?? [],
6115
- ...this.agents?.map((a) => a.getFunction()) ?? []
6144
+ init(parentAi, options) {
6145
+ const ai = this.ai ?? parentAi;
6146
+ const mm = ai?.getModelList();
6147
+ const agentFuncs = this.agents?.map((a) => a.getFunction())?.map(
6148
+ (f) => mm ? { ...f, parameters: addModelParameter(f.parameters, mm) } : f
6149
+ );
6150
+ const functions = [
6151
+ ...options?.functions ?? this.functions ?? [],
6152
+ ...agentFuncs ?? []
6116
6153
  ];
6117
- const opt = options;
6118
- if (funcs.length > 0) {
6119
- const opt2 = { ...options, functions: funcs };
6120
- this.program = new AxGen(this.signature, opt2);
6121
- }
6122
- return { _ai, opt };
6154
+ return { ai, functions };
6123
6155
  }
6124
- async forward(ai, values, options) {
6125
- const { _ai, opt } = this.init(ai, options);
6126
- return await this.program.forward(_ai, values, opt);
6156
+ async forward(parentAi, values, options) {
6157
+ const { ai, functions } = this.init(parentAi, options);
6158
+ return await this.program.forward(ai, values, { ...options, functions });
6127
6159
  }
6128
- async *streamingForward(ai, values, options) {
6129
- const { _ai, opt } = this.init(ai, options);
6130
- return yield* this.program.streamingForward(_ai, values, opt);
6160
+ async *streamingForward(parentAi, values, options) {
6161
+ const { ai, functions } = this.init(parentAi, options);
6162
+ return yield* this.program.streamingForward(ai, values, {
6163
+ ...options,
6164
+ functions
6165
+ });
6131
6166
  }
6132
6167
  };
6133
6168
  function toCamelCase(inputString) {
@@ -6141,6 +6176,31 @@ function toCamelCase(inputString) {
6141
6176
  }).join("");
6142
6177
  return camelCaseString;
6143
6178
  }
6179
+ function addModelParameter(parameters, models) {
6180
+ const baseSchema = parameters ? structuredClone(parameters) : {
6181
+ type: "object",
6182
+ properties: {},
6183
+ required: []
6184
+ };
6185
+ if (baseSchema.properties?.model) {
6186
+ return baseSchema;
6187
+ }
6188
+ const modelProperty = {
6189
+ type: "string",
6190
+ enum: models.map((m) => m.key),
6191
+ description: `The AI model to use for this function call. Available options: ${models.map((m) => `${m.key}: ${m.description}`).join(" | ")}`
6192
+ };
6193
+ const newProperties = {
6194
+ ...baseSchema.properties ?? {},
6195
+ model: modelProperty
6196
+ };
6197
+ const newRequired = [...baseSchema.required ?? [], "model"];
6198
+ return {
6199
+ ...baseSchema,
6200
+ properties: newProperties,
6201
+ required: newRequired
6202
+ };
6203
+ }
6144
6204
 
6145
6205
  // docs/tika.ts
6146
6206
  var import_node_fs = require("fs");
@@ -6223,7 +6283,7 @@ var AxBalancer = class _AxBalancer {
6223
6283
  const bTotalCost = (bInfo.promptTokenCostPer1M || Infinity) + (bInfo.completionTokenCostPer1M || Infinity);
6224
6284
  return aTotalCost - bTotalCost;
6225
6285
  };
6226
- getModelMap() {
6286
+ getModelList() {
6227
6287
  throw new Error("Method not implemented.");
6228
6288
  }
6229
6289
  getNextService() {
@@ -7840,8 +7900,8 @@ var AxMockAIService = class {
7840
7900
  streaming: this.config.features?.streaming ?? false
7841
7901
  };
7842
7902
  }
7843
- getModelMap() {
7844
- return this.config.modelMap;
7903
+ getModelList() {
7904
+ return this.config.models;
7845
7905
  }
7846
7906
  getMetrics() {
7847
7907
  return this.metrics;