@ax-llm/ax 11.0.66 → 11.0.67

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
@@ -159,7 +159,6 @@ __export(index_exports, {
159
159
  axAITogetherDefaultConfig: () => axAITogetherDefaultConfig,
160
160
  axBaseAIDefaultConfig: () => axBaseAIDefaultConfig,
161
161
  axBaseAIDefaultCreativeConfig: () => axBaseAIDefaultCreativeConfig,
162
- axField: () => axField,
163
162
  axModelInfoAnthropic: () => axModelInfoAnthropic,
164
163
  axModelInfoCohere: () => axModelInfoCohere,
165
164
  axModelInfoDeepSeek: () => axModelInfoDeepSeek,
@@ -172,7 +171,9 @@ __export(index_exports, {
172
171
  axModelInfoReka: () => axModelInfoReka,
173
172
  axModelInfoTogether: () => axModelInfoTogether,
174
173
  axSpanAttributes: () => axSpanAttributes,
175
- axSpanEvents: () => axSpanEvents
174
+ axSpanEvents: () => axSpanEvents,
175
+ f: () => f,
176
+ s: () => s
176
177
  });
177
178
  module.exports = __toCommonJS(index_exports);
178
179
 
@@ -953,14 +954,14 @@ var logResponseResult = (r, logger = defaultLogger) => {
953
954
  logger(r.content, { tags: ["responseContent"] });
954
955
  }
955
956
  if (r.functionCalls && r.functionCalls.length > 0) {
956
- for (const [i, f] of r.functionCalls.entries()) {
957
- if (f.function.name) {
958
- logger(`[${i + 1}] ${f.function.name}`, {
957
+ for (const [i, f2] of r.functionCalls.entries()) {
958
+ if (f2.function.name) {
959
+ logger(`[${i + 1}] ${f2.function.name}`, {
959
960
  tags: ["functionName"]
960
961
  });
961
962
  }
962
- if (f.function.params) {
963
- const params = typeof f.function.params === "string" ? f.function.params : JSON.stringify(f.function.params, null, 2);
963
+ if (f2.function.params) {
964
+ const params = typeof f2.function.params === "string" ? f2.function.params : JSON.stringify(f2.function.params, null, 2);
964
965
  logger(params, { tags: ["functionArg"] });
965
966
  }
966
967
  }
@@ -3087,7 +3088,7 @@ function createHistory(chatPrompt) {
3087
3088
  case "function": {
3088
3089
  const functionCalls = chatPrompt.map((v) => {
3089
3090
  if (v.role === "assistant") {
3090
- return v.functionCalls?.find((f) => f.id === chat.functionId);
3091
+ return v.functionCalls?.find((f2) => f2.id === chat.functionId);
3091
3092
  }
3092
3093
  return void 0;
3093
3094
  }).filter((v) => v !== void 0);
@@ -3407,11 +3408,11 @@ var AxAIGoogleGeminiImpl = class {
3407
3408
  case "assistant": {
3408
3409
  let parts = [];
3409
3410
  if (msg.functionCalls) {
3410
- parts = msg.functionCalls.map((f) => {
3411
- const args = typeof f.function.params === "string" ? JSON.parse(f.function.params) : f.function.params;
3411
+ parts = msg.functionCalls.map((f2) => {
3412
+ const args = typeof f2.function.params === "string" ? JSON.parse(f2.function.params) : f2.function.params;
3412
3413
  return {
3413
3414
  functionCall: {
3414
- name: f.function.name,
3415
+ name: f2.function.name,
3415
3416
  args
3416
3417
  }
3417
3418
  };
@@ -4468,7 +4469,7 @@ var AxAIOpenAIResponsesImpl = class {
4468
4469
  currentResult.thought = item.encrypted_content;
4469
4470
  } else {
4470
4471
  currentResult.thought = item.summary.map(
4471
- (s) => typeof s === "object" ? JSON.stringify(s) : s
4472
+ (s2) => typeof s2 === "object" ? JSON.stringify(s2) : s2
4472
4473
  ).join("\n");
4473
4474
  }
4474
4475
  break;
@@ -4792,7 +4793,7 @@ var AxAIOpenAIResponsesImpl = class {
4792
4793
  baseResult.thought = reasoningItem.encrypted_content;
4793
4794
  } else if (reasoningItem.summary) {
4794
4795
  baseResult.thought = reasoningItem.summary.map(
4795
- (s) => typeof s === "object" ? JSON.stringify(s) : s
4796
+ (s2) => typeof s2 === "object" ? JSON.stringify(s2) : s2
4796
4797
  ).join("\n");
4797
4798
  }
4798
4799
  }
@@ -6164,7 +6165,7 @@ var AxPromptTemplate = class {
6164
6165
  task.push(
6165
6166
  `You will be provided with the following fields: ${inArgs}. Your task is to generate new fields: ${outArgs}.`
6166
6167
  );
6167
- const funcs = this.functions?.map((f) => "toFunction" in f ? f.toFunction() : f)?.flat();
6168
+ const funcs = this.functions?.map((f2) => "toFunction" in f2 ? f2.toFunction() : f2)?.flat();
6168
6169
  const funcList = funcs?.map((fn) => `- \`${fn.name}\`: ${formatDescription(fn.description)}`).join("\n");
6169
6170
  if (funcList && funcList.length > 0) {
6170
6171
  task.push(`## Available Functions
@@ -6858,7 +6859,7 @@ var convertValueToType = (field, val, required = false) => {
6858
6859
  return val;
6859
6860
  }
6860
6861
  };
6861
- function* yieldDelta(content, field, s, e, xstate) {
6862
+ function* yieldDelta(content, field, s2, e, xstate) {
6862
6863
  const { name: fieldName, isInternal } = field;
6863
6864
  const { isArray: fieldIsArray, name: fieldTypeName } = field.type ?? {};
6864
6865
  if (isInternal || fieldIsArray || fieldTypeName && fieldTypeName !== "string" && fieldTypeName !== "code") {
@@ -6866,7 +6867,7 @@ function* yieldDelta(content, field, s, e, xstate) {
6866
6867
  }
6867
6868
  const pos = xstate.streamedIndex[fieldName] ?? 0;
6868
6869
  const isFirstChunk = pos === 0;
6869
- const d1 = content.substring(s + pos, e);
6870
+ const d1 = content.substring(s2 + pos, e);
6870
6871
  if (d1.length === 0) {
6871
6872
  return;
6872
6873
  }
@@ -6885,8 +6886,8 @@ function* yieldDelta(content, field, s, e, xstate) {
6885
6886
  }
6886
6887
  function* streamValues(sig, content, values, xstate) {
6887
6888
  for (const prevField of xstate.prevFields ?? []) {
6888
- const { field, s, e } = prevField;
6889
- yield* yieldDelta(content, field, s, e, xstate);
6889
+ const { field, s: s2, e } = prevField;
6890
+ yield* yieldDelta(content, field, s2, e, xstate);
6890
6891
  }
6891
6892
  xstate.prevFields = void 0;
6892
6893
  if (!xstate.currField || xstate.currField.isInternal) {
@@ -6901,17 +6902,17 @@ function* streamValues(sig, content, values, xstate) {
6901
6902
  );
6902
6903
  const outputFields = sig.getOutputFields();
6903
6904
  for (const key of Object.keys(values)) {
6904
- const field = outputFields.find((f) => f.name === key);
6905
+ const field = outputFields.find((f2) => f2.name === key);
6905
6906
  if (!field || field.isInternal) {
6906
6907
  continue;
6907
6908
  }
6908
6909
  const value = values[key];
6909
6910
  if (Array.isArray(value)) {
6910
- const s = xstate.streamedIndex?.[key] ?? 0;
6911
- const v = value.slice(s);
6911
+ const s2 = xstate.streamedIndex?.[key] ?? 0;
6912
+ const v = value.slice(s2);
6912
6913
  if (v && v.length > 0) {
6913
6914
  yield { [key]: v };
6914
- xstate.streamedIndex[key] = s + v.length;
6915
+ xstate.streamedIndex[key] = s2 + v.length;
6915
6916
  }
6916
6917
  continue;
6917
6918
  }
@@ -7334,11 +7335,11 @@ var parseFunctions = (newFuncs, existingFuncs) => {
7334
7335
  if (newFuncs.length === 0) {
7335
7336
  return [...existingFuncs ?? []];
7336
7337
  }
7337
- const functions = newFuncs.map((f) => {
7338
- if ("toFunction" in f) {
7339
- return f.toFunction();
7338
+ const functions = newFuncs.map((f2) => {
7339
+ if ("toFunction" in f2) {
7340
+ return f2.toFunction();
7340
7341
  }
7341
- return f;
7342
+ return f2;
7342
7343
  }).flat();
7343
7344
  for (const fn of functions.filter((v) => v.parameters)) {
7344
7345
  if (fn.parameters) {
@@ -7423,10 +7424,10 @@ function parseFunctionCalls(ai, functionCalls, values, model) {
7423
7424
  if (!ai.getFeatures(model).functions) {
7424
7425
  throw new Error("Functions are not supported by the AI service");
7425
7426
  }
7426
- const funcs = functionCalls.map((f) => ({
7427
- id: f.id,
7428
- name: f.function.name,
7429
- args: f.function.params
7427
+ const funcs = functionCalls.map((f2) => ({
7428
+ id: f2.id,
7429
+ name: f2.function.name,
7430
+ args: f2.function.params
7430
7431
  }));
7431
7432
  return funcs;
7432
7433
  }
@@ -7629,7 +7630,7 @@ ${pointer}`;
7629
7630
  `Output field "${name}": Expected class names in quotes after "class" type. Example: class "MyClass1, MyClass2"`
7630
7631
  );
7631
7632
  }
7632
- const options = classNamesString.split(/[,\s]+/).map((s) => s.trim()).filter((s) => s.length > 0);
7633
+ const options = classNamesString.split(/[,\s]+/).map((s2) => s2.trim()).filter((s2) => s2.length > 0);
7633
7634
  if (options.length === 0) {
7634
7635
  throw new Error(
7635
7636
  `Output field "${name}": Empty class list provided. At least one class name is required`
@@ -7853,25 +7854,25 @@ var AxSignature = class _AxSignature {
7853
7854
  toJSONSchema = () => {
7854
7855
  const properties = {};
7855
7856
  const required = [];
7856
- for (const f of this.inputFields) {
7857
- const type = f.type ? f.type.name : "string";
7858
- if (f.type?.isArray) {
7859
- properties[f.name] = {
7860
- description: f.description,
7857
+ for (const f2 of this.inputFields) {
7858
+ const type = f2.type ? f2.type.name : "string";
7859
+ if (f2.type?.isArray) {
7860
+ properties[f2.name] = {
7861
+ description: f2.description,
7861
7862
  type: "array",
7862
7863
  items: {
7863
7864
  type,
7864
- description: f.description
7865
+ description: f2.description
7865
7866
  }
7866
7867
  };
7867
7868
  } else {
7868
- properties[f.name] = {
7869
- description: f.description,
7869
+ properties[f2.name] = {
7870
+ description: f2.description,
7870
7871
  type
7871
7872
  };
7872
7873
  }
7873
- if (!f.isOptional) {
7874
- required.push(f.name);
7874
+ if (!f2.isOptional) {
7875
+ required.push(f2.name);
7875
7876
  }
7876
7877
  }
7877
7878
  const schema = {
@@ -8037,11 +8038,11 @@ var AxProgramWithSignature = class {
8037
8038
  const fields = [...sig.getInputFields(), ...sig.getOutputFields()];
8038
8039
  this.examples = traces.map((e) => {
8039
8040
  const res = {};
8040
- for (const f of fields) {
8041
- const value = e[f.name];
8041
+ for (const f2 of fields) {
8042
+ const value = e[f2.name];
8042
8043
  if (value !== void 0) {
8043
- validateValue(f, value);
8044
- res[f.name] = value;
8044
+ validateValue(f2, value);
8045
+ res[f2.name] = value;
8045
8046
  }
8046
8047
  }
8047
8048
  return res;
@@ -8195,7 +8196,7 @@ var AxGen = class extends AxProgramWithSignature {
8195
8196
  this.streamingAsserts.push({ fieldName, fn, message });
8196
8197
  };
8197
8198
  addFieldProcessorInternal = (fieldName, fn, streaming = false) => {
8198
- const field = this.signature.getOutputFields().find((f) => f.name === fieldName);
8199
+ const field = this.signature.getOutputFields().find((f2) => f2.name === fieldName);
8199
8200
  if (!field) {
8200
8201
  throw new Error(`addFieldProcessor: field ${fieldName} not found`);
8201
8202
  }
@@ -8241,7 +8242,7 @@ var AxGen = class extends AxProgramWithSignature {
8241
8242
  if (chatPrompt.length === 0) {
8242
8243
  throw new Error("No chat prompt found");
8243
8244
  }
8244
- const functions = _functions?.map((f) => "toFunction" in f ? f.toFunction() : f)?.flat();
8245
+ const functions = _functions?.map((f2) => "toFunction" in f2 ? f2.toFunction() : f2)?.flat();
8245
8246
  let functionCall = _functionCall ?? this.options?.functionCall;
8246
8247
  if (!firstStep && (functionCall === "required" || typeof functionCall === "function")) {
8247
8248
  functionCall = void 0;
@@ -8279,7 +8280,7 @@ var AxGen = class extends AxProgramWithSignature {
8279
8280
  const { sessionId, traceId, functions: _functions } = options ?? {};
8280
8281
  const fastFail = options?.fastFail ?? this.options?.fastFail;
8281
8282
  const model = options.model;
8282
- const functions = _functions?.map((f) => "toFunction" in f ? f.toFunction() : f)?.flat();
8283
+ const functions = _functions?.map((f2) => "toFunction" in f2 ? f2.toFunction() : f2)?.flat();
8283
8284
  const res = await this.forwardSendRequest({
8284
8285
  ai,
8285
8286
  mem,
@@ -8604,7 +8605,7 @@ Content: ${result.content}`
8604
8605
  if (span) {
8605
8606
  span.addEvent("validation.error", {
8606
8607
  message: e.toString(),
8607
- fixing_instructions: errorFields?.map((f) => f.title).join(", ") ?? ""
8608
+ fixing_instructions: errorFields?.map((f2) => f2.title).join(", ") ?? ""
8608
8609
  });
8609
8610
  }
8610
8611
  } else if (e instanceof AxAssertionError) {
@@ -8614,7 +8615,7 @@ Content: ${result.content}`
8614
8615
  if (span) {
8615
8616
  span.addEvent("assertion.error", {
8616
8617
  message: e1.toString(),
8617
- fixing_instructions: errorFields?.map((f) => f.title).join(", ") ?? ""
8618
+ fixing_instructions: errorFields?.map((f2) => f2.title).join(", ") ?? ""
8618
8619
  });
8619
8620
  }
8620
8621
  } else if (e instanceof AxAIServiceStreamTerminatedError) {
@@ -8669,7 +8670,7 @@ Content: ${result.content}`
8669
8670
  });
8670
8671
  return;
8671
8672
  }
8672
- const funcNames = functions?.map((f) => f.name).join(",");
8673
+ const funcNames = functions?.map((f2) => f2.name).join(",");
8673
8674
  const attributes = {
8674
8675
  signature: JSON.stringify(this.signature.toJSON(), null, 2),
8675
8676
  ...this.examples ? { examples: JSON.stringify(this.examples, null, 2) } : {},
@@ -8928,7 +8929,7 @@ var AxAgent = class {
8928
8929
  const sig = this.program.getSignature();
8929
8930
  const outFields = sig.getOutputFields();
8930
8931
  const result = Object.keys(ret).map((k) => {
8931
- const field = outFields.find((f) => f.name === k);
8932
+ const field = outFields.find((f2) => f2.name === k);
8932
8933
  if (field) {
8933
8934
  return `${field.title}: ${ret[k]}`;
8934
8935
  }
@@ -8957,12 +8958,12 @@ var AxAgent = class {
8957
8958
  const parentKeys = parentSchema.map((p) => p.name);
8958
8959
  const debug = this.getDebug(ai, options);
8959
8960
  const agentFuncs = this.agents?.map((agent) => {
8960
- const f = agent.getFeatures();
8961
+ const f2 = agent.getFeatures();
8961
8962
  const processOptions = {
8962
8963
  debug,
8963
8964
  disableSmartModelRouting: !!this.disableSmartModelRouting,
8964
- excludeFieldsFromPassthrough: f.excludeFieldsFromPassthrough,
8965
- canConfigureSmartModelRouting: f.canConfigureSmartModelRouting
8965
+ excludeFieldsFromPassthrough: f2.excludeFieldsFromPassthrough,
8966
+ canConfigureSmartModelRouting: f2.canConfigureSmartModelRouting
8966
8967
  };
8967
8968
  return processChildAgentFunction(
8968
8969
  agent.getFunction(),
@@ -11934,7 +11935,7 @@ var AxTestPrompt = class {
11934
11935
  };
11935
11936
 
11936
11937
  // dsp/template.ts
11937
- function ax(strings, ...values) {
11938
+ function s(strings, ...values) {
11938
11939
  let result = "";
11939
11940
  for (let i = 0; i < strings.length; i++) {
11940
11941
  result += strings[i] ?? "";
@@ -11962,6 +11963,34 @@ function ax(strings, ...values) {
11962
11963
  }
11963
11964
  return new AxSignature(result);
11964
11965
  }
11966
+ function ax(strings, ...values) {
11967
+ let result = "";
11968
+ for (let i = 0; i < strings.length; i++) {
11969
+ result += strings[i] ?? "";
11970
+ if (i < values.length) {
11971
+ const val = values[i];
11972
+ if (isAxFieldType(val)) {
11973
+ const fieldNameMatch = result.match(/(\w+)\s*:\s*$/);
11974
+ if (fieldNameMatch && (val.isOptional || val.isInternal)) {
11975
+ const fieldName = fieldNameMatch[1];
11976
+ let modifiedFieldName = fieldName;
11977
+ if (val.isOptional) modifiedFieldName += "?";
11978
+ if (val.isInternal) modifiedFieldName += "!";
11979
+ result = result.replace(/(\w+)(\s*:\s*)$/, `${modifiedFieldName}$2`);
11980
+ }
11981
+ const { isOptional: _o, isInternal: _i, ...typeNoFlags } = val;
11982
+ result += convertFieldTypeToString(typeNoFlags);
11983
+ } else if (isAxFieldDescriptor(val)) {
11984
+ result += convertFieldDescriptorToString(val);
11985
+ } else if (typeof val === "string" || val instanceof AxSignature) {
11986
+ result += convertValueToSignatureString(val);
11987
+ } else {
11988
+ throw new Error("Unsupported template interpolation value");
11989
+ }
11990
+ }
11991
+ }
11992
+ return new AxGen(result);
11993
+ }
11965
11994
  function convertValueToSignatureString(value) {
11966
11995
  if (typeof value === "string") {
11967
11996
  return value;
@@ -12017,7 +12046,7 @@ function isAxFieldType(value) {
12017
12046
  function isAxFieldDescriptor(value) {
12018
12047
  return value !== null && typeof value === "object" && value !== void 0 && "name" in value && typeof value.name === "string";
12019
12048
  }
12020
- var axField = {
12049
+ var f = {
12021
12050
  string: (desc) => ({
12022
12051
  type: "string",
12023
12052
  description: desc
@@ -13398,12 +13427,12 @@ function countTokens(tokens) {
13398
13427
  }
13399
13428
  return counter;
13400
13429
  }
13401
- function normalizeText(s) {
13402
- s = s.normalize("NFD");
13403
- s = s.replace(/\b(a|an|the)\b/g, " ");
13404
- s = s.split(/\s+/).join(" ");
13405
- s = s.replace(/[!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]/g, "");
13406
- return s.toLowerCase();
13430
+ function normalizeText(s2) {
13431
+ s2 = s2.normalize("NFD");
13432
+ s2 = s2.replace(/\b(a|an|the)\b/g, " ");
13433
+ s2 = s2.split(/\s+/).join(" ");
13434
+ s2 = s2.replace(/[!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]/g, "");
13435
+ return s2.toLowerCase();
13407
13436
  }
13408
13437
  function emScore(prediction, groundTruth) {
13409
13438
  return normalizeText(prediction) === normalizeText(groundTruth) ? 1 : 0;
@@ -13817,7 +13846,7 @@ var AxMultiServiceRouter = class {
13817
13846
  * Returns a composite ID built from the IDs of the underlying services.
13818
13847
  */
13819
13848
  getId() {
13820
- return "MultiServiceRouter:" + Array.from(this.services.values()).map((s) => s.service.getId()).join(",");
13849
+ return "MultiServiceRouter:" + Array.from(this.services.values()).map((s2) => s2.service.getId()).join(",");
13821
13850
  }
13822
13851
  /**
13823
13852
  * Returns the name of this router.
@@ -14077,7 +14106,6 @@ var AxRAG = class extends AxChainOfThought {
14077
14106
  axAITogetherDefaultConfig,
14078
14107
  axBaseAIDefaultConfig,
14079
14108
  axBaseAIDefaultCreativeConfig,
14080
- axField,
14081
14109
  axModelInfoAnthropic,
14082
14110
  axModelInfoCohere,
14083
14111
  axModelInfoDeepSeek,
@@ -14090,6 +14118,8 @@ var AxRAG = class extends AxChainOfThought {
14090
14118
  axModelInfoReka,
14091
14119
  axModelInfoTogether,
14092
14120
  axSpanAttributes,
14093
- axSpanEvents
14121
+ axSpanEvents,
14122
+ f,
14123
+ s
14094
14124
  });
14095
14125
  //# sourceMappingURL=index.cjs.map