@ax-llm/ax 12.0.1 → 12.0.3

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
@@ -3215,8 +3215,9 @@ var AxAIDeepSeek = class extends AxAIOpenAIBase {
3215
3215
 
3216
3216
  // ai/google-gemini/types.ts
3217
3217
  var AxAIGoogleGeminiModel = /* @__PURE__ */ ((AxAIGoogleGeminiModel2) => {
3218
- AxAIGoogleGeminiModel2["Gemini25Pro"] = "gemini-2.5-pro-preview-05-06";
3219
- AxAIGoogleGeminiModel2["Gemini25Flash"] = "gemini-2.5-flash-preview-04-17";
3218
+ AxAIGoogleGeminiModel2["Gemini25Pro"] = "gemini-2.5-pro";
3219
+ AxAIGoogleGeminiModel2["Gemini25Flash"] = "gemini-2.5-flash";
3220
+ AxAIGoogleGeminiModel2["Gemini25FlashLite"] = "gemini-2.5-flash-lite-preview-06-17";
3220
3221
  AxAIGoogleGeminiModel2["Gemini20Flash"] = "gemini-2.0-flash";
3221
3222
  AxAIGoogleGeminiModel2["Gemini20FlashLite"] = "gemini-2.0-flash-lite-preview-02-05";
3222
3223
  AxAIGoogleGeminiModel2["Gemini1Pro"] = "gemini-1.0-pro";
@@ -3227,7 +3228,7 @@ var AxAIGoogleGeminiModel = /* @__PURE__ */ ((AxAIGoogleGeminiModel2) => {
3227
3228
  return AxAIGoogleGeminiModel2;
3228
3229
  })(AxAIGoogleGeminiModel || {});
3229
3230
  var AxAIGoogleGeminiEmbedModel = /* @__PURE__ */ ((AxAIGoogleGeminiEmbedModel2) => {
3230
- AxAIGoogleGeminiEmbedModel2["GeminiEmbedding"] = "gemini-embedding-exp-03-07";
3231
+ AxAIGoogleGeminiEmbedModel2["GeminiEmbedding"] = "gemini-embedding-exp";
3231
3232
  AxAIGoogleGeminiEmbedModel2["TextEmbeddingLarge"] = "text-embedding-large-exp-03-07";
3232
3233
  AxAIGoogleGeminiEmbedModel2["TextEmbedding004"] = "text-embedding-004";
3233
3234
  AxAIGoogleGeminiEmbedModel2["TextEmbedding005"] = "text-embedding-005";
@@ -3263,7 +3264,7 @@ var AxAIGoogleGeminiEmbedTypes = /* @__PURE__ */ ((AxAIGoogleGeminiEmbedTypes2)
3263
3264
  // ai/google-gemini/info.ts
3264
3265
  var axModelInfoGoogleGemini = [
3265
3266
  {
3266
- name: "gemini-2.5-pro-preview-05-06" /* Gemini25Pro */,
3267
+ name: "gemini-2.5-pro" /* Gemini25Pro */,
3267
3268
  currency: "usd",
3268
3269
  characterIsToken: false,
3269
3270
  promptTokenCostPer1M: 2.5,
@@ -3272,7 +3273,7 @@ var axModelInfoGoogleGemini = [
3272
3273
  hasShowThoughts: true
3273
3274
  },
3274
3275
  {
3275
- name: "gemini-2.5-flash-preview-04-17" /* Gemini25Flash */,
3276
+ name: "gemini-2.5-flash" /* Gemini25Flash */,
3276
3277
  currency: "usd",
3277
3278
  characterIsToken: false,
3278
3279
  promptTokenCostPer1M: 15,
@@ -3280,6 +3281,15 @@ var axModelInfoGoogleGemini = [
3280
3281
  hasThinkingBudget: true,
3281
3282
  hasShowThoughts: true
3282
3283
  },
3284
+ {
3285
+ name: "gemini-2.5-flash-lite-preview-06-17" /* Gemini25FlashLite */,
3286
+ currency: "usd",
3287
+ characterIsToken: false,
3288
+ promptTokenCostPer1M: 0.1,
3289
+ completionTokenCostPer1M: 0.4,
3290
+ hasThinkingBudget: true,
3291
+ hasShowThoughts: true
3292
+ },
3283
3293
  {
3284
3294
  name: "gemini-2.0-flash" /* Gemini20Flash */,
3285
3295
  currency: "usd",
@@ -3344,15 +3354,29 @@ var safetySettings = [
3344
3354
  }
3345
3355
  ];
3346
3356
  var axAIGoogleGeminiDefaultConfig = () => structuredClone({
3347
- model: "gemini-2.5-flash-preview-04-17" /* Gemini25Flash */,
3357
+ model: "gemini-2.5-flash" /* Gemini25Flash */,
3348
3358
  embedModel: "text-embedding-005" /* TextEmbedding005 */,
3349
3359
  safetySettings,
3360
+ thinkingTokenBudgetLevels: {
3361
+ minimal: 200,
3362
+ low: 800,
3363
+ medium: 5e3,
3364
+ high: 1e4,
3365
+ highest: 24500
3366
+ },
3350
3367
  ...axBaseAIDefaultConfig()
3351
3368
  });
3352
3369
  var axAIGoogleGeminiDefaultCreativeConfig = () => structuredClone({
3353
3370
  model: "gemini-2.0-flash" /* Gemini20Flash */,
3354
3371
  embedModel: "text-embedding-005" /* TextEmbedding005 */,
3355
3372
  safetySettings,
3373
+ thinkingTokenBudgetLevels: {
3374
+ minimal: 200,
3375
+ low: 800,
3376
+ medium: 5e3,
3377
+ high: 1e4,
3378
+ highest: 24500
3379
+ },
3356
3380
  ...axBaseAIDefaultCreativeConfig()
3357
3381
  });
3358
3382
  var AxAIGoogleGeminiImpl = class {
@@ -3539,25 +3563,26 @@ var AxAIGoogleGeminiImpl = class {
3539
3563
  thinkingConfig.thinkingBudget = this.config.thinking.thinkingTokenBudget;
3540
3564
  }
3541
3565
  if (config?.thinkingTokenBudget) {
3566
+ const levels = this.config.thinkingTokenBudgetLevels;
3542
3567
  switch (config.thinkingTokenBudget) {
3543
3568
  case "none":
3544
3569
  thinkingConfig.thinkingBudget = 0;
3545
3570
  thinkingConfig.includeThoughts = false;
3546
3571
  break;
3547
3572
  case "minimal":
3548
- thinkingConfig.thinkingBudget = 200;
3573
+ thinkingConfig.thinkingBudget = levels?.minimal ?? 200;
3549
3574
  break;
3550
3575
  case "low":
3551
- thinkingConfig.thinkingBudget = 800;
3576
+ thinkingConfig.thinkingBudget = levels?.low ?? 800;
3552
3577
  break;
3553
3578
  case "medium":
3554
- thinkingConfig.thinkingBudget = 5e3;
3579
+ thinkingConfig.thinkingBudget = levels?.medium ?? 5e3;
3555
3580
  break;
3556
3581
  case "high":
3557
- thinkingConfig.thinkingBudget = 1e4;
3582
+ thinkingConfig.thinkingBudget = levels?.high ?? 1e4;
3558
3583
  break;
3559
3584
  case "highest":
3560
- thinkingConfig.thinkingBudget = 24500;
3585
+ thinkingConfig.thinkingBudget = levels?.highest ?? 24500;
3561
3586
  break;
3562
3587
  }
3563
3588
  }
@@ -5659,10 +5684,15 @@ var MemoryImpl = class {
5659
5684
  name,
5660
5685
  functionCalls
5661
5686
  }) {
5662
- if (!content && (!functionCalls || functionCalls.length === 0)) {
5687
+ const isContentEmpty = typeof content === "string" && content.trim() === "";
5688
+ if (isContentEmpty && (!functionCalls || functionCalls.length === 0)) {
5663
5689
  return;
5664
5690
  }
5665
- this.addMemory({ content, name, role: "assistant", functionCalls });
5691
+ if (isContentEmpty) {
5692
+ this.addMemory({ name, role: "assistant", functionCalls });
5693
+ } else {
5694
+ this.addMemory({ content, name, role: "assistant", functionCalls });
5695
+ }
5666
5696
  }
5667
5697
  addResult({
5668
5698
  content,
@@ -5684,7 +5714,7 @@ var MemoryImpl = class {
5684
5714
  if (!lastItem || lastItem.chat.role !== "assistant") {
5685
5715
  this.addResultMessage({ content, name, functionCalls });
5686
5716
  } else {
5687
- if ("content" in lastItem.chat && content) {
5717
+ if ("content" in lastItem.chat && typeof content === "string" && content.trim() !== "") {
5688
5718
  lastItem.chat.content = content;
5689
5719
  }
5690
5720
  if ("name" in lastItem.chat && name) {
@@ -7815,7 +7845,7 @@ var SignatureParser = class {
7815
7845
  'Add class names in quotes. Example: class "positive, negative, neutral"'
7816
7846
  );
7817
7847
  }
7818
- const options = classNamesString.split(/[,\s]+/).map((s2) => s2.trim()).filter((s2) => s2.length > 0);
7848
+ const options = classNamesString.split(/[,|]/).map((s2) => s2.trim()).filter((s2) => s2.length > 0);
7819
7849
  if (options.length === 0) {
7820
7850
  throw new SignatureValidationError(
7821
7851
  `Output field "${name}": Empty class list provided`,
@@ -7824,24 +7854,6 @@ var SignatureParser = class {
7824
7854
  'Provide at least one class option. Example: "positive, negative"'
7825
7855
  );
7826
7856
  }
7827
- if (options.length === 1) {
7828
- throw new SignatureValidationError(
7829
- `Output field "${name}": Class type needs at least 2 options`,
7830
- this.position,
7831
- this.getErrorContext(),
7832
- 'Add more class options or use "string" type instead. Example: "positive, negative, neutral"'
7833
- );
7834
- }
7835
- for (const option of options) {
7836
- if (!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(option)) {
7837
- throw new SignatureValidationError(
7838
- `Output field "${name}": Invalid class option "${option}"`,
7839
- this.position,
7840
- this.getErrorContext(),
7841
- "Class options must start with a letter and contain only letters, numbers, underscores, or hyphens"
7842
- );
7843
- }
7844
- }
7845
7857
  type = { name: "class", isArray, options };
7846
7858
  } else {
7847
7859
  try {
@@ -8139,6 +8151,8 @@ var AxSignature = class _AxSignature {
8139
8151
  outputFields;
8140
8152
  sigHash;
8141
8153
  sigString;
8154
+ // Validation caching - stores hash when validation last passed
8155
+ validatedAtHash;
8142
8156
  constructor(signature) {
8143
8157
  if (!signature) {
8144
8158
  this.inputFields = [];
@@ -8180,6 +8194,9 @@ var AxSignature = class _AxSignature {
8180
8194
  );
8181
8195
  this.sigHash = signature.hash();
8182
8196
  this.sigString = signature.toString();
8197
+ if (signature.validatedAtHash === this.sigHash) {
8198
+ this.validatedAtHash = this.sigHash;
8199
+ }
8183
8200
  } else {
8184
8201
  throw new AxSignatureValidationError(
8185
8202
  "Invalid signature argument type",
@@ -8226,14 +8243,34 @@ var AxSignature = class _AxSignature {
8226
8243
  );
8227
8244
  }
8228
8245
  this.description = desc;
8246
+ this.invalidateValidationCache();
8229
8247
  this.updateHash();
8230
8248
  };
8231
8249
  addInputField = (field) => {
8232
8250
  try {
8233
8251
  const parsedField = this.parseField(field);
8234
8252
  validateField(parsedField, "input");
8253
+ for (const existingField of this.inputFields) {
8254
+ if (existingField.name === parsedField.name) {
8255
+ throw new AxSignatureValidationError(
8256
+ `Duplicate input field name: "${parsedField.name}"`,
8257
+ parsedField.name,
8258
+ "Each field name must be unique within the signature"
8259
+ );
8260
+ }
8261
+ }
8262
+ for (const outputField of this.outputFields) {
8263
+ if (outputField.name === parsedField.name) {
8264
+ throw new AxSignatureValidationError(
8265
+ `Field name "${parsedField.name}" appears in both inputs and outputs`,
8266
+ parsedField.name,
8267
+ "Use different names for input and output fields to avoid confusion"
8268
+ );
8269
+ }
8270
+ }
8235
8271
  this.inputFields.push(parsedField);
8236
- this.updateHash();
8272
+ this.invalidateValidationCache();
8273
+ this.updateHashLight();
8237
8274
  } catch (error) {
8238
8275
  if (error instanceof AxSignatureValidationError) {
8239
8276
  throw error;
@@ -8248,8 +8285,27 @@ var AxSignature = class _AxSignature {
8248
8285
  try {
8249
8286
  const parsedField = this.parseField(field);
8250
8287
  validateField(parsedField, "output");
8288
+ for (const existingField of this.outputFields) {
8289
+ if (existingField.name === parsedField.name) {
8290
+ throw new AxSignatureValidationError(
8291
+ `Duplicate output field name: "${parsedField.name}"`,
8292
+ parsedField.name,
8293
+ "Each field name must be unique within the signature"
8294
+ );
8295
+ }
8296
+ }
8297
+ for (const inputField of this.inputFields) {
8298
+ if (inputField.name === parsedField.name) {
8299
+ throw new AxSignatureValidationError(
8300
+ `Field name "${parsedField.name}" appears in both inputs and outputs`,
8301
+ parsedField.name,
8302
+ "Use different names for input and output fields to avoid confusion"
8303
+ );
8304
+ }
8305
+ }
8251
8306
  this.outputFields.push(parsedField);
8252
- this.updateHash();
8307
+ this.invalidateValidationCache();
8308
+ this.updateHashLight();
8253
8309
  } catch (error) {
8254
8310
  if (error instanceof AxSignatureValidationError) {
8255
8311
  throw error;
@@ -8275,6 +8331,7 @@ var AxSignature = class _AxSignature {
8275
8331
  return parsed;
8276
8332
  });
8277
8333
  this.inputFields = parsedFields;
8334
+ this.invalidateValidationCache();
8278
8335
  this.updateHash();
8279
8336
  } catch (error) {
8280
8337
  if (error instanceof AxSignatureValidationError) {
@@ -8300,6 +8357,7 @@ var AxSignature = class _AxSignature {
8300
8357
  return parsed;
8301
8358
  });
8302
8359
  this.outputFields = parsedFields;
8360
+ this.invalidateValidationCache();
8303
8361
  this.updateHash();
8304
8362
  } catch (error) {
8305
8363
  if (error instanceof AxSignatureValidationError) {
@@ -8313,6 +8371,9 @@ var AxSignature = class _AxSignature {
8313
8371
  getInputFields = () => this.inputFields;
8314
8372
  getOutputFields = () => this.outputFields;
8315
8373
  getDescription = () => this.description;
8374
+ invalidateValidationCache = () => {
8375
+ this.validatedAtHash = void 0;
8376
+ };
8316
8377
  toTitle = (name) => {
8317
8378
  let result = name.replace(/_/g, " ");
8318
8379
  result = result.replace(/([A-Z]|[0-9]+)/g, " $1").trim();
@@ -8349,6 +8410,30 @@ var AxSignature = class _AxSignature {
8349
8410
  };
8350
8411
  return schema;
8351
8412
  };
8413
+ updateHashLight = () => {
8414
+ try {
8415
+ this.getInputFields().forEach((field) => {
8416
+ validateField(field, "input");
8417
+ });
8418
+ this.getOutputFields().forEach((field) => {
8419
+ validateField(field, "output");
8420
+ });
8421
+ this.sigHash = (0, import_crypto3.createHash)("sha256").update(this.description ?? "").update(JSON.stringify(this.inputFields)).update(JSON.stringify(this.outputFields)).digest("hex");
8422
+ this.sigString = renderSignature(
8423
+ this.description,
8424
+ this.inputFields,
8425
+ this.outputFields
8426
+ );
8427
+ return [this.sigHash, this.sigString];
8428
+ } catch (error) {
8429
+ if (error instanceof AxSignatureValidationError) {
8430
+ throw error;
8431
+ }
8432
+ throw new AxSignatureValidationError(
8433
+ `Signature validation failed: ${error instanceof Error ? error.message : "Unknown error"}`
8434
+ );
8435
+ }
8436
+ };
8352
8437
  updateHash = () => {
8353
8438
  try {
8354
8439
  this.getInputFields().forEach((field) => {
@@ -8421,6 +8506,19 @@ var AxSignature = class _AxSignature {
8421
8506
  );
8422
8507
  }
8423
8508
  }
8509
+ validate = () => {
8510
+ if (this.validatedAtHash === this.sigHash) {
8511
+ return true;
8512
+ }
8513
+ try {
8514
+ this.updateHash();
8515
+ this.validatedAtHash = this.sigHash;
8516
+ return true;
8517
+ } catch (error) {
8518
+ this.validatedAtHash = void 0;
8519
+ throw error;
8520
+ }
8521
+ };
8424
8522
  hash = () => this.sigHash;
8425
8523
  toString = () => this.sigString;
8426
8524
  toJSON = () => {
@@ -8446,7 +8544,7 @@ function renderField(field) {
8446
8544
  result += "[]";
8447
8545
  }
8448
8546
  if (field.type.name === "class" && field.type.options) {
8449
- result += ` "${field.type.options.join(", ")}"`;
8547
+ result += ` "${field.type.options.join(" | ")}"`;
8450
8548
  }
8451
8549
  }
8452
8550
  if (field.description && field.type?.name !== "class") {
@@ -8578,13 +8676,6 @@ function validateFieldType(field, context3) {
8578
8676
  'Provide class options. Example: class "positive, negative, neutral"'
8579
8677
  );
8580
8678
  }
8581
- if (type.options.length === 1) {
8582
- throw new AxSignatureValidationError(
8583
- "Class type needs at least 2 options",
8584
- field.name,
8585
- 'Add more class options or use "string" type instead'
8586
- );
8587
- }
8588
8679
  for (const option of type.options) {
8589
8680
  if (!option || option.trim().length === 0) {
8590
8681
  throw new AxSignatureValidationError(
@@ -8594,11 +8685,11 @@ function validateFieldType(field, context3) {
8594
8685
  );
8595
8686
  }
8596
8687
  const trimmedOption = option.trim();
8597
- if (!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(trimmedOption)) {
8688
+ if (trimmedOption.includes(",") || trimmedOption.includes("|")) {
8598
8689
  throw new AxSignatureValidationError(
8599
8690
  `Invalid class option "${trimmedOption}"`,
8600
8691
  field.name,
8601
- "Class options must start with a letter and contain only letters, numbers, underscores, or hyphens"
8692
+ "Class options cannot contain commas (,) or pipes (|) as they are used to separate options"
8602
8693
  );
8603
8694
  }
8604
8695
  }
@@ -8642,12 +8733,13 @@ var AxProgramWithSignature = class {
8642
8733
  children;
8643
8734
  constructor(signature, options) {
8644
8735
  this.signature = new AxSignature(signature);
8645
- this.sigHash = this.signature?.hash();
8646
- this.children = new AxInstanceRegistry();
8647
- this.key = { id: this.constructor.name };
8648
8736
  if (options?.description) {
8649
8737
  this.signature.setDescription(options.description);
8650
8738
  }
8739
+ this.signature.validate();
8740
+ this.sigHash = this.signature?.hash();
8741
+ this.children = new AxInstanceRegistry();
8742
+ this.key = { id: this.constructor.name };
8651
8743
  }
8652
8744
  getSignature() {
8653
8745
  return this.signature;