@hiper2d/ai-agents 0.37.0 → 0.38.0

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/dist/index.d.mts CHANGED
@@ -1401,7 +1401,14 @@ declare abstract class AbstractAgent {
1401
1401
  * invalidResponseRetries policy. Subclasses implement doAskWithZodSchema/doAskText and
1402
1402
  * must NOT override these.
1403
1403
  */
1404
- askWithZodSchema<T>(zodSchema: z.ZodSchema<T>, messages: AIMessage[]): Promise<[T, string, TokenUsage$1?, string?]>;
1404
+ /**
1405
+ * `reject` is the host's own check on a schema-valid answer: return why it is unusable
1406
+ * (a required field left as an empty string, say) and the answer is treated exactly like
1407
+ * a malformed one: a ModelInvalidResponseError, re-sent under invalidResponseRetries.
1408
+ * It exists because a check written into the zod schema would change the JSON schema
1409
+ * the provider sees.
1410
+ */
1411
+ askWithZodSchema<T>(zodSchema: z.ZodSchema<T>, messages: AIMessage[], reject?: (answer: T) => string | null | undefined): Promise<[T, string, TokenUsage$1?, string?]>;
1405
1412
  askText(messages: AIMessage[]): Promise<[string, string, TokenUsage$1?, string?]>;
1406
1413
  /**
1407
1414
  * One attempt per loop; an empty or malformed answer (ModelInvalidResponseError, not
package/dist/index.d.ts CHANGED
@@ -1401,7 +1401,14 @@ declare abstract class AbstractAgent {
1401
1401
  * invalidResponseRetries policy. Subclasses implement doAskWithZodSchema/doAskText and
1402
1402
  * must NOT override these.
1403
1403
  */
1404
- askWithZodSchema<T>(zodSchema: z.ZodSchema<T>, messages: AIMessage[]): Promise<[T, string, TokenUsage$1?, string?]>;
1404
+ /**
1405
+ * `reject` is the host's own check on a schema-valid answer: return why it is unusable
1406
+ * (a required field left as an empty string, say) and the answer is treated exactly like
1407
+ * a malformed one: a ModelInvalidResponseError, re-sent under invalidResponseRetries.
1408
+ * It exists because a check written into the zod schema would change the JSON schema
1409
+ * the provider sees.
1410
+ */
1411
+ askWithZodSchema<T>(zodSchema: z.ZodSchema<T>, messages: AIMessage[], reject?: (answer: T) => string | null | undefined): Promise<[T, string, TokenUsage$1?, string?]>;
1405
1412
  askText(messages: AIMessage[]): Promise<[string, string, TokenUsage$1?, string?]>;
1406
1413
  /**
1407
1414
  * One attempt per loop; an empty or malformed answer (ModelInvalidResponseError, not
package/dist/index.js CHANGED
@@ -2669,8 +2669,20 @@ var AbstractAgent = class {
2669
2669
  * invalidResponseRetries policy. Subclasses implement doAskWithZodSchema/doAskText and
2670
2670
  * must NOT override these.
2671
2671
  */
2672
- async askWithZodSchema(zodSchema, messages) {
2673
- return this.askWithRetries(() => this.doAskWithZodSchema(zodSchema, messages));
2672
+ /**
2673
+ * `reject` is the host's own check on a schema-valid answer: return why it is unusable
2674
+ * (a required field left as an empty string, say) and the answer is treated exactly like
2675
+ * a malformed one: a ModelInvalidResponseError, re-sent under invalidResponseRetries.
2676
+ * It exists because a check written into the zod schema would change the JSON schema
2677
+ * the provider sees.
2678
+ */
2679
+ async askWithZodSchema(zodSchema, messages, reject) {
2680
+ return this.askWithRetries(async () => {
2681
+ const result = await this.doAskWithZodSchema(zodSchema, messages);
2682
+ const reason = reject?.(result[0]);
2683
+ if (reason) throw new ModelInvalidResponseError(this.model, reason);
2684
+ return result;
2685
+ });
2674
2686
  }
2675
2687
  async askText(messages) {
2676
2688
  return this.askWithRetries(() => this.doAskText(messages));