@ax-llm/ax 11.0.7 → 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,
@@ -2555,7 +2574,7 @@ var safetySettings = [
2555
2574
  }
2556
2575
  ];
2557
2576
  var axAIGoogleGeminiDefaultConfig = () => structuredClone({
2558
- model: "gemini-1.5-pro" /* Gemini15Pro */,
2577
+ model: "gemini-2.0-flash" /* Gemini20Flash */,
2559
2578
  embedModel: "text-embedding-004" /* TextEmbedding004 */,
2560
2579
  safetySettings,
2561
2580
  ...axBaseAIDefaultConfig()
@@ -4494,6 +4513,9 @@ var LRUCache = class {
4494
4513
  };
4495
4514
  var globalPrefixCache = new LRUCache(500);
4496
4515
  function matchesContent(content, prefix, startIndex = 0, prefixCache = globalPrefixCache) {
4516
+ if (/^\s*$/.test(content)) {
4517
+ return -3;
4518
+ }
4497
4519
  const exactMatchIndex = content.indexOf(prefix, startIndex);
4498
4520
  if (exactMatchIndex !== -1) {
4499
4521
  return exactMatchIndex;
@@ -5218,6 +5240,9 @@ var streamingExtractValues = (sig, values, xstate, content, streamingValidation
5218
5240
  // Field is not found, continue to the next field
5219
5241
  case -2:
5220
5242
  return true;
5243
+ // Partial match at end, skip and gather more content
5244
+ case -3:
5245
+ return true;
5221
5246
  }
5222
5247
  let prefixLen = prefix.length;
5223
5248
  if (xstate.currField) {
@@ -6001,14 +6026,20 @@ function processChildAgentFunction(childFunction, parentValues, parentInputKeys,
6001
6026
  injectionKeys
6002
6027
  );
6003
6028
  const originalFunc = processedFunction.func;
6004
- processedFunction.func = (childArgs, funcOptions) => originalFunc(
6005
- {
6029
+ processedFunction.func = (childArgs, funcOptions) => {
6030
+ const updatedChildArgs = {
6006
6031
  ...childArgs,
6007
6032
  ...pick(parentValues, injectionKeys)
6008
- },
6009
- funcOptions
6010
- );
6033
+ };
6034
+ if (options.debug && injectionKeys.length > 0) {
6035
+ process.stdout.write(
6036
+ `Function Params: ${JSON.stringify(updatedChildArgs, null, 2)}`
6037
+ );
6038
+ }
6039
+ return originalFunc(updatedChildArgs, funcOptions);
6040
+ };
6011
6041
  }
6042
+ return processedFunction;
6012
6043
  }
6013
6044
  if (modelList && !options.disableSmartModelRouting && options.canConfigureSmartModelRouting) {
6014
6045
  processedFunction.parameters = addModelParameter(
@@ -6020,14 +6051,12 @@ function processChildAgentFunction(childFunction, parentValues, parentInputKeys,
6020
6051
  }
6021
6052
  var AxAgent = class {
6022
6053
  ai;
6023
- signature;
6024
6054
  program;
6025
6055
  functions;
6026
6056
  agents;
6027
6057
  disableSmartModelRouting;
6028
6058
  excludeFieldsFromPassthrough;
6029
6059
  name;
6030
- description;
6031
6060
  subAgentList;
6032
6061
  func;
6033
6062
  constructor({
@@ -6043,8 +6072,8 @@ var AxAgent = class {
6043
6072
  this.functions = functions;
6044
6073
  this.disableSmartModelRouting = options?.disableSmartModelRouting;
6045
6074
  this.excludeFieldsFromPassthrough = options?.excludeFieldsFromPassthrough ?? [];
6046
- this.signature = new AxSignature(signature);
6047
- this.signature.setDescription(description);
6075
+ const sig = new AxSignature(signature);
6076
+ sig.setDescription(description);
6048
6077
  if (!name || name.length < 5) {
6049
6078
  throw new Error(
6050
6079
  `Agent name must be at least 10 characters (more descriptive): ${name}`
@@ -6055,17 +6084,16 @@ var AxAgent = class {
6055
6084
  `Agent description must be at least 20 characters (explain in detail what the agent does): ${description}`
6056
6085
  );
6057
6086
  }
6058
- this.program = new AxGen(this.signature, options);
6087
+ this.program = new AxGen(sig, options);
6059
6088
  for (const agent of agents ?? []) {
6060
6089
  this.program.register(agent);
6061
6090
  }
6062
6091
  this.name = name;
6063
- this.description = description;
6064
6092
  this.subAgentList = agents?.map((a) => a.getFunction().name).join(", ");
6065
6093
  this.func = {
6066
6094
  name: toCamelCase(this.name),
6067
- description: this.description,
6068
- parameters: this.signature.toJSONSchema(),
6095
+ description,
6096
+ parameters: sig.toJSONSchema(),
6069
6097
  func: () => this.forward
6070
6098
  };
6071
6099
  const mm = ai?.getModelList();
@@ -6121,11 +6149,12 @@ var AxAgent = class {
6121
6149
  init(parentAi, values, options) {
6122
6150
  const ai = this.ai ?? parentAi;
6123
6151
  const mm = ai?.getModelList();
6124
- const parentSchema = this.signature.toJSONSchema();
6125
- const parentKeys = parentSchema.properties ? Object.keys(parentSchema.properties) : [];
6152
+ const parentSchema = this.program.getSignature().getInputFields();
6153
+ const parentKeys = parentSchema.map((p) => p.name);
6126
6154
  const agentFuncs = this.agents?.map((agent) => {
6127
6155
  const f = agent.getFeatures();
6128
6156
  const processOptions = {
6157
+ debug: ai?.getOptions()?.debug ?? false,
6129
6158
  disableSmartModelRouting: !!this.disableSmartModelRouting,
6130
6159
  excludeFieldsFromPassthrough: f.excludeFieldsFromPassthrough,
6131
6160
  canConfigureSmartModelRouting: f.canConfigureSmartModelRouting
@@ -6168,8 +6197,7 @@ var AxAgent = class {
6168
6197
  "Agent description must be at least 20 characters (explain in detail what the agent does)"
6169
6198
  );
6170
6199
  }
6171
- this.description = description;
6172
- this.signature.setDescription(description);
6200
+ this.program.getSignature().setDescription(description);
6173
6201
  this.func.description = description;
6174
6202
  }
6175
6203
  };
@@ -6196,7 +6224,7 @@ function addModelParameter(parameters, models) {
6196
6224
  const modelProperty = {
6197
6225
  type: "string",
6198
6226
  enum: models.map((m) => m.key),
6199
- description: `The AI model to use for this function call. Available options: ${models.map((m) => `${m.key}: ${m.description}`).join(" | ")}`
6227
+ description: `The AI model to use for this function call. Available options: ${models.map((m) => `\`${m.key}\` ${m.description}`).join(", ")}`
6200
6228
  };
6201
6229
  const newProperties = {
6202
6230
  ...baseSchema.properties ?? {},