@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.d.cts CHANGED
@@ -326,6 +326,7 @@ declare class AxBaseAI<TModel, TEmbedModel, TChatRequest, TEmbedRequest, TChatRe
326
326
  getMetrics(): AxAIServiceMetrics;
327
327
  chat(req: Readonly<AxChatRequest<TModel>>, options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions<TModel, TEmbedModel>>): Promise<AxChatResponse | ReadableStream$1<AxChatResponse>>;
328
328
  private _chat1;
329
+ private cleanupFunctionSchema;
329
330
  private _chat2;
330
331
  embed(req: Readonly<AxEmbedRequest<TEmbedModel>>, options?: Readonly<AxAIServiceActionOptions<TModel, TEmbedModel>>): Promise<AxEmbedResponse>;
331
332
  private _embed1;
@@ -1637,14 +1638,12 @@ interface AxAgentFeatures {
1637
1638
  */
1638
1639
  declare class AxAgent<IN extends AxGenIn, OUT extends AxGenOut = AxGenOut> implements AxAgentic {
1639
1640
  private ai?;
1640
- private signature;
1641
1641
  private program;
1642
1642
  private functions?;
1643
1643
  private agents?;
1644
1644
  private disableSmartModelRouting?;
1645
1645
  private excludeFieldsFromPassthrough;
1646
1646
  private name;
1647
- private description;
1648
1647
  private subAgentList?;
1649
1648
  private func;
1650
1649
  constructor({ ai, name, description, signature, agents, functions, }: Readonly<{
package/index.d.ts CHANGED
@@ -326,6 +326,7 @@ declare class AxBaseAI<TModel, TEmbedModel, TChatRequest, TEmbedRequest, TChatRe
326
326
  getMetrics(): AxAIServiceMetrics;
327
327
  chat(req: Readonly<AxChatRequest<TModel>>, options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions<TModel, TEmbedModel>>): Promise<AxChatResponse | ReadableStream$1<AxChatResponse>>;
328
328
  private _chat1;
329
+ private cleanupFunctionSchema;
329
330
  private _chat2;
330
331
  embed(req: Readonly<AxEmbedRequest<TEmbedModel>>, options?: Readonly<AxAIServiceActionOptions<TModel, TEmbedModel>>): Promise<AxEmbedResponse>;
331
332
  private _embed1;
@@ -1637,14 +1638,12 @@ interface AxAgentFeatures {
1637
1638
  */
1638
1639
  declare class AxAgent<IN extends AxGenIn, OUT extends AxGenOut = AxGenOut> implements AxAgentic {
1639
1640
  private ai?;
1640
- private signature;
1641
1641
  private program;
1642
1642
  private functions?;
1643
1643
  private agents?;
1644
1644
  private disableSmartModelRouting?;
1645
1645
  private excludeFieldsFromPassthrough;
1646
1646
  private name;
1647
- private description;
1648
1647
  private subAgentList?;
1649
1648
  private func;
1650
1649
  constructor({ ai, name, description, signature, agents, functions, }: Readonly<{
package/index.js CHANGED
@@ -803,7 +803,8 @@ var AxBaseAI = class {
803
803
  const startTime = performance.now();
804
804
  let isError = false;
805
805
  try {
806
- return this._chat1(req, options);
806
+ const result = await this._chat1(req, options);
807
+ return result;
807
808
  } catch (error) {
808
809
  isError = true;
809
810
  throw error;
@@ -856,13 +857,31 @@ var AxBaseAI = class {
856
857
  }
857
858
  return await this._chat2(model, modelConfig, req, options);
858
859
  }
860
+ cleanupFunctionSchema(fn) {
861
+ const cleanFn = { ...fn };
862
+ if (cleanFn.parameters) {
863
+ const cleanParams = { ...cleanFn.parameters };
864
+ if (Array.isArray(cleanParams.required) && cleanParams.required.length === 0) {
865
+ delete cleanParams.required;
866
+ }
867
+ if (cleanParams.properties && Object.keys(cleanParams.properties).length === 0) {
868
+ delete cleanParams.properties;
869
+ }
870
+ if (Object.keys(cleanParams).length === 0 || Object.keys(cleanParams).length === 1 && cleanParams.type === "object") {
871
+ delete cleanFn.parameters;
872
+ } else {
873
+ cleanFn.parameters = cleanParams;
874
+ }
875
+ }
876
+ return cleanFn;
877
+ }
859
878
  async _chat2(model, modelConfig, chatReq, options, span) {
860
879
  if (!this.aiImpl.createChatReq) {
861
880
  throw new Error("generateChatReq not implemented");
862
881
  }
863
882
  let functions;
864
883
  if (chatReq.functions && chatReq.functions.length > 0) {
865
- functions = chatReq.functions;
884
+ functions = chatReq.functions.map((fn2) => this.cleanupFunctionSchema(fn2));
866
885
  }
867
886
  const req = {
868
887
  ...chatReq,
@@ -6032,14 +6051,12 @@ function processChildAgentFunction(childFunction, parentValues, parentInputKeys,
6032
6051
  }
6033
6052
  var AxAgent = class {
6034
6053
  ai;
6035
- signature;
6036
6054
  program;
6037
6055
  functions;
6038
6056
  agents;
6039
6057
  disableSmartModelRouting;
6040
6058
  excludeFieldsFromPassthrough;
6041
6059
  name;
6042
- description;
6043
6060
  subAgentList;
6044
6061
  func;
6045
6062
  constructor({
@@ -6055,8 +6072,8 @@ var AxAgent = class {
6055
6072
  this.functions = functions;
6056
6073
  this.disableSmartModelRouting = options?.disableSmartModelRouting;
6057
6074
  this.excludeFieldsFromPassthrough = options?.excludeFieldsFromPassthrough ?? [];
6058
- this.signature = new AxSignature(signature);
6059
- this.signature.setDescription(description);
6075
+ const sig = new AxSignature(signature);
6076
+ sig.setDescription(description);
6060
6077
  if (!name || name.length < 5) {
6061
6078
  throw new Error(
6062
6079
  `Agent name must be at least 10 characters (more descriptive): ${name}`
@@ -6067,17 +6084,16 @@ var AxAgent = class {
6067
6084
  `Agent description must be at least 20 characters (explain in detail what the agent does): ${description}`
6068
6085
  );
6069
6086
  }
6070
- this.program = new AxGen(this.signature, options);
6087
+ this.program = new AxGen(sig, options);
6071
6088
  for (const agent of agents ?? []) {
6072
6089
  this.program.register(agent);
6073
6090
  }
6074
6091
  this.name = name;
6075
- this.description = description;
6076
6092
  this.subAgentList = agents?.map((a) => a.getFunction().name).join(", ");
6077
6093
  this.func = {
6078
6094
  name: toCamelCase(this.name),
6079
- description: this.description,
6080
- parameters: this.signature.toJSONSchema(),
6095
+ description,
6096
+ parameters: sig.toJSONSchema(),
6081
6097
  func: () => this.forward
6082
6098
  };
6083
6099
  const mm = ai?.getModelList();
@@ -6133,7 +6149,7 @@ var AxAgent = class {
6133
6149
  init(parentAi, values, options) {
6134
6150
  const ai = this.ai ?? parentAi;
6135
6151
  const mm = ai?.getModelList();
6136
- const parentSchema = this.signature.getInputFields();
6152
+ const parentSchema = this.program.getSignature().getInputFields();
6137
6153
  const parentKeys = parentSchema.map((p) => p.name);
6138
6154
  const agentFuncs = this.agents?.map((agent) => {
6139
6155
  const f = agent.getFeatures();
@@ -6181,8 +6197,7 @@ var AxAgent = class {
6181
6197
  "Agent description must be at least 20 characters (explain in detail what the agent does)"
6182
6198
  );
6183
6199
  }
6184
- this.description = description;
6185
- this.signature.setDescription(description);
6200
+ this.program.getSignature().setDescription(description);
6186
6201
  this.func.description = description;
6187
6202
  }
6188
6203
  };