@hiper2d/ai-agents 0.1.1 → 0.1.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/dist/index.mjs CHANGED
@@ -705,6 +705,14 @@ var ModelQuotaExceededError = class extends ModelError {
705
705
  this.name = "ModelQuotaExceededError";
706
706
  }
707
707
  };
708
+ var ModelInvalidResponseError = class extends ModelError {
709
+ truncated;
710
+ constructor(modelType, detail, truncated = false) {
711
+ super(`${modelType} failed to produce a valid response: ${detail}`, modelType);
712
+ this.name = "ModelInvalidResponseError";
713
+ this.truncated = truncated;
714
+ }
715
+ };
708
716
  var ModelRefusalError = class extends ModelError {
709
717
  constructor(modelType, message = `${modelType} refused to answer (stop_reason: refusal)`) {
710
718
  super(message, modelType);
@@ -905,10 +913,11 @@ var SupportedAiModels = {
905
913
  tags: ["expensive"]
906
914
  },
907
915
  [LLM_CONSTANTS.GEMINI_FLASH]: {
908
- // Repointed from gemini-3.6-flash 2026-08-13 (stable picker id, same pattern as gpt).
909
- // 3.7 rejects thinkingLevel 'minimal' (low|medium|high only), unlike 3.5/3.6.
910
- displayName: "Gemini 3.7 Flash",
911
- modelApiName: "gemini-3.7-flash",
916
+ // Repointed 3.6 → 3.7 (2026-08-13) → 3.8 (2026-09-02); stable picker id, same pattern as gpt.
917
+ // 3.7 rejected thinkingLevel 'minimal' (low|medium|high only), unlike 3.5/3.6 — 3.8 untested
918
+ // on 'minimal', so keep the pin at 'medium' or above.
919
+ displayName: "Gemini 3.8 Flash",
920
+ modelApiName: "gemini-3.8-flash",
912
921
  apiKeyName: API_KEY_CONSTANTS.GOOGLE,
913
922
  hasThinking: true,
914
923
  reasoningEffort: "medium",
@@ -1236,9 +1245,9 @@ var MODEL_PRICING = {
1236
1245
  extendedContextThresholdTokens: 2e5
1237
1246
  },
1238
1247
  [SupportedAiModels[LLM_CONSTANTS.GEMINI_FLASH].modelApiName]: {
1239
- // Launch pricing through 2026-12-31; doubles to $1.50/$7.50/$0.15 on 2027-01-01
1240
- // (ai.google.dev pricing page, fetched 2026-08-13) — ACTION NEEDED then: update these
1241
- // rates.
1248
+ // 3.8 Flash (2026-09-02) launched at the same rates as 3.7. 3.7's launch pricing was
1249
+ // scheduled to double to $1.50/$7.50/$0.15 on 2027-01-01 (ai.google.dev pricing page,
1250
+ // fetched 2026-08-13) — ACTION NEEDED then: re-check whether 3.8 follows and update.
1242
1251
  // Cache storage cost ($0.50 / 1M tokens per hour) is not tracked here — the
1243
1252
  // schema only models per-token call costs, not time-based storage.
1244
1253
  inputPrice: 0.75,
@@ -1771,18 +1780,37 @@ var Gpt5Agent = class extends AbstractAgent {
1771
1780
  thinking: z2.string().describe("Your internal chain-of-thought reasoning process used to arrive at the final answer.")
1772
1781
  });
1773
1782
  }
1774
- const response = await this.client.responses.parse({
1775
- model: this.model,
1776
- instructions: this.instruction,
1777
- input,
1778
- max_output_tokens: this.maxOutputTokens,
1779
- text: {
1780
- format: zodTextFormat(schemaToSend, "response_schema")
1783
+ let response;
1784
+ try {
1785
+ response = await this.client.responses.parse({
1786
+ model: this.model,
1787
+ instructions: this.instruction,
1788
+ input,
1789
+ max_output_tokens: this.maxOutputTokens,
1790
+ text: {
1791
+ format: zodTextFormat(schemaToSend, "response_schema")
1792
+ }
1793
+ });
1794
+ } catch (error) {
1795
+ if (error instanceof SyntaxError) {
1796
+ throw new ModelInvalidResponseError(
1797
+ this.model,
1798
+ `malformed JSON output \u2014 the generation was cut off at the ${this.maxOutputTokens}-token output cap or went off the rails (${error.message})`
1799
+ );
1781
1800
  }
1782
- });
1801
+ throw error;
1802
+ }
1803
+ if (response.status === "incomplete") {
1804
+ const reason = response.incomplete_details?.reason ?? "unknown";
1805
+ throw new ModelInvalidResponseError(
1806
+ this.model,
1807
+ `response incomplete (${reason}) at max_output_tokens=${this.maxOutputTokens}`,
1808
+ reason === "max_output_tokens"
1809
+ );
1810
+ }
1783
1811
  if (!response.output_parsed) {
1784
1812
  this.logger(`Parsing failed. Raw content: ${response.output_text}`);
1785
- throw new Error(this.errorMessages.invalidFormat);
1813
+ throw new ModelInvalidResponseError(this.model, this.errorMessages.invalidFormat);
1786
1814
  }
1787
1815
  let reasoningContent = "";
1788
1816
  if (this.enableThinking && response.output_parsed.thinking) {
@@ -1821,6 +1849,9 @@ var Gpt5Agent = class extends AbstractAgent {
1821
1849
  return [response.output_parsed, reasoningContent, tokenUsage];
1822
1850
  } catch (error) {
1823
1851
  this.logger(this.logTemplates.error(this.name, error));
1852
+ if (error instanceof ModelError) {
1853
+ throw error;
1854
+ }
1824
1855
  throw new Error(this.errorMessages.apiError(error));
1825
1856
  }
1826
1857
  }
@@ -1846,6 +1877,14 @@ var Gpt5Agent = class extends AbstractAgent {
1846
1877
  });
1847
1878
  const content = response.output_text;
1848
1879
  if (!content) {
1880
+ if (response.status === "incomplete") {
1881
+ const reason = response.incomplete_details?.reason ?? "unknown";
1882
+ throw new ModelInvalidResponseError(
1883
+ this.model,
1884
+ `empty response, incomplete (${reason}) at max_output_tokens=${this.maxOutputTokens}`,
1885
+ reason === "max_output_tokens"
1886
+ );
1887
+ }
1849
1888
  throw new Error(this.errorMessages.emptyResponse);
1850
1889
  }
1851
1890
  let tokenUsage;
@@ -1878,6 +1917,9 @@ var Gpt5Agent = class extends AbstractAgent {
1878
1917
  return [content, "", tokenUsage];
1879
1918
  } catch (error) {
1880
1919
  this.logger(this.logTemplates.error(this.name, error));
1920
+ if (error instanceof ModelError) {
1921
+ throw error;
1922
+ }
1881
1923
  throw new Error(this.errorMessages.apiError(error));
1882
1924
  }
1883
1925
  }
@@ -4293,6 +4335,7 @@ export {
4293
4335
  MistralAgent,
4294
4336
  ModelAuthenticationError,
4295
4337
  ModelError,
4338
+ ModelInvalidResponseError,
4296
4339
  ModelOverloadError,
4297
4340
  ModelQuotaExceededError,
4298
4341
  ModelRateLimitError,