@ax-llm/ax 12.0.0 → 12.0.1

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
@@ -1270,6 +1270,7 @@ var AxBaseAI = class {
1270
1270
  if (chatReq.functions && chatReq.functions.length > 0) {
1271
1271
  functions = chatReq.functions.map((fn2) => this.cleanupFunctionSchema(fn2));
1272
1272
  }
1273
+ validateChatPrompt(chatReq.chatPrompt);
1273
1274
  const req = {
1274
1275
  ...chatReq,
1275
1276
  model,
@@ -1611,6 +1612,31 @@ function setChatResponseEvents(res, span, excludeContentFromTrace) {
1611
1612
  });
1612
1613
  }
1613
1614
  }
1615
+ function validateAxMessageArray(values) {
1616
+ for (let i = 0; i < values.length; i++) {
1617
+ const message = values[i];
1618
+ if (!message || typeof message !== "object") {
1619
+ throw new Error(
1620
+ `AxMessage array validation failed: Item at index ${i} is not a valid message object`
1621
+ );
1622
+ }
1623
+ if ("content" in message && typeof message.content === "string" && message.content.trim() === "") {
1624
+ throw new Error(
1625
+ `AxMessage array validation failed: Item at index ${i} has empty content`
1626
+ );
1627
+ }
1628
+ }
1629
+ }
1630
+ function validateChatPrompt(chatPrompt) {
1631
+ for (let i = 0; i < chatPrompt.length; i++) {
1632
+ const message = chatPrompt[i];
1633
+ if (message && "content" in message && typeof message.content === "string" && message.content.trim() === "") {
1634
+ throw new Error(
1635
+ `Chat prompt validation failed: Message at index ${i} has empty content`
1636
+ );
1637
+ }
1638
+ }
1639
+ }
1614
1640
  function validateModels(models) {
1615
1641
  const keys = /* @__PURE__ */ new Set();
1616
1642
  for (const model of models) {
@@ -3387,7 +3413,9 @@ var AxAIGoogleGeminiImpl = class {
3387
3413
  const contents = req.chatPrompt.filter((p) => p.role !== "system").map((msg, i) => {
3388
3414
  switch (msg.role) {
3389
3415
  case "user": {
3390
- const parts = Array.isArray(msg.content) ? msg.content.map((c, i2) => {
3416
+ const parts = Array.isArray(
3417
+ msg.content
3418
+ ) ? msg.content.map((c, i2) => {
3391
3419
  switch (c.type) {
3392
3420
  case "text":
3393
3421
  return { text: c.text };
@@ -3448,12 +3476,14 @@ var AxAIGoogleGeminiImpl = class {
3448
3476
  }
3449
3477
  ];
3450
3478
  return {
3451
- role: "function",
3479
+ role: "model",
3452
3480
  parts
3453
3481
  };
3454
3482
  }
3455
3483
  default:
3456
- throw new Error("Invalid role");
3484
+ throw new Error(
3485
+ `Invalid role: ${JSON.stringify(msg)} (index: ${i})`
3486
+ );
3457
3487
  }
3458
3488
  });
3459
3489
  let tools = [];
@@ -9185,6 +9215,7 @@ Content: ${result.content}`
9185
9215
  }
9186
9216
  let prompt;
9187
9217
  if (Array.isArray(values)) {
9218
+ validateAxMessageArray(values);
9188
9219
  prompt = this.promptTemplate.render(values, {
9189
9220
  examples: this.examples,
9190
9221
  demos: this.demos