@ax-llm/ax 11.0.8 → 11.0.9

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
@@ -905,7 +905,8 @@ var AxBaseAI = class {
905
905
  const startTime = performance.now();
906
906
  let isError = false;
907
907
  try {
908
- return this._chat1(req, options);
908
+ const result = await this._chat1(req, options);
909
+ return result;
909
910
  } catch (error) {
910
911
  isError = true;
911
912
  throw error;
@@ -958,13 +959,31 @@ var AxBaseAI = class {
958
959
  }
959
960
  return await this._chat2(model, modelConfig, req, options);
960
961
  }
962
+ cleanupFunctionSchema(fn) {
963
+ const cleanFn = { ...fn };
964
+ if (cleanFn.parameters) {
965
+ const cleanParams = { ...cleanFn.parameters };
966
+ if (Array.isArray(cleanParams.required) && cleanParams.required.length === 0) {
967
+ delete cleanParams.required;
968
+ }
969
+ if (cleanParams.properties && Object.keys(cleanParams.properties).length === 0) {
970
+ delete cleanParams.properties;
971
+ }
972
+ if (Object.keys(cleanParams).length === 0 || Object.keys(cleanParams).length === 1 && cleanParams.type === "object") {
973
+ delete cleanFn.parameters;
974
+ } else {
975
+ cleanFn.parameters = cleanParams;
976
+ }
977
+ }
978
+ return cleanFn;
979
+ }
961
980
  async _chat2(model, modelConfig, chatReq, options, span) {
962
981
  if (!this.aiImpl.createChatReq) {
963
982
  throw new Error("generateChatReq not implemented");
964
983
  }
965
984
  let functions;
966
985
  if (chatReq.functions && chatReq.functions.length > 0) {
967
- functions = chatReq.functions;
986
+ functions = chatReq.functions.map((fn2) => this.cleanupFunctionSchema(fn2));
968
987
  }
969
988
  const req = {
970
989
  ...chatReq,
@@ -6134,14 +6153,12 @@ function processChildAgentFunction(childFunction, parentValues, parentInputKeys,
6134
6153
  }
6135
6154
  var AxAgent = class {
6136
6155
  ai;
6137
- signature;
6138
6156
  program;
6139
6157
  functions;
6140
6158
  agents;
6141
6159
  disableSmartModelRouting;
6142
6160
  excludeFieldsFromPassthrough;
6143
6161
  name;
6144
- description;
6145
6162
  subAgentList;
6146
6163
  func;
6147
6164
  constructor({
@@ -6157,8 +6174,8 @@ var AxAgent = class {
6157
6174
  this.functions = functions;
6158
6175
  this.disableSmartModelRouting = options?.disableSmartModelRouting;
6159
6176
  this.excludeFieldsFromPassthrough = options?.excludeFieldsFromPassthrough ?? [];
6160
- this.signature = new AxSignature(signature);
6161
- this.signature.setDescription(description);
6177
+ const sig = new AxSignature(signature);
6178
+ sig.setDescription(description);
6162
6179
  if (!name || name.length < 5) {
6163
6180
  throw new Error(
6164
6181
  `Agent name must be at least 10 characters (more descriptive): ${name}`
@@ -6169,17 +6186,16 @@ var AxAgent = class {
6169
6186
  `Agent description must be at least 20 characters (explain in detail what the agent does): ${description}`
6170
6187
  );
6171
6188
  }
6172
- this.program = new AxGen(this.signature, options);
6189
+ this.program = new AxGen(sig, options);
6173
6190
  for (const agent of agents ?? []) {
6174
6191
  this.program.register(agent);
6175
6192
  }
6176
6193
  this.name = name;
6177
- this.description = description;
6178
6194
  this.subAgentList = agents?.map((a) => a.getFunction().name).join(", ");
6179
6195
  this.func = {
6180
6196
  name: toCamelCase(this.name),
6181
- description: this.description,
6182
- parameters: this.signature.toJSONSchema(),
6197
+ description,
6198
+ parameters: sig.toJSONSchema(),
6183
6199
  func: () => this.forward
6184
6200
  };
6185
6201
  const mm = ai?.getModelList();
@@ -6235,7 +6251,7 @@ var AxAgent = class {
6235
6251
  init(parentAi, values, options) {
6236
6252
  const ai = this.ai ?? parentAi;
6237
6253
  const mm = ai?.getModelList();
6238
- const parentSchema = this.signature.getInputFields();
6254
+ const parentSchema = this.program.getSignature().getInputFields();
6239
6255
  const parentKeys = parentSchema.map((p) => p.name);
6240
6256
  const agentFuncs = this.agents?.map((agent) => {
6241
6257
  const f = agent.getFeatures();
@@ -6283,8 +6299,7 @@ var AxAgent = class {
6283
6299
  "Agent description must be at least 20 characters (explain in detail what the agent does)"
6284
6300
  );
6285
6301
  }
6286
- this.description = description;
6287
- this.signature.setDescription(description);
6302
+ this.program.getSignature().setDescription(description);
6288
6303
  this.func.description = description;
6289
6304
  }
6290
6305
  };