@hiper2d/ai-agents 0.1.2 → 0.1.4

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);
@@ -779,6 +787,7 @@ var LLM_CONSTANTS = {
779
787
  DEEPSEEK_PRO: "deepseek-pro",
780
788
  // GPT-5.6 family. 'gpt' and 'gpt-mini' are stable picker ids carried over from the
781
789
  // GPT-5.5 / GPT-5.4-mini era so existing consumers keep working across the repoint.
790
+ GPT_ASTRA: "gpt-astra",
782
791
  GPT_SOL: "gpt-sol",
783
792
  GPT: "gpt",
784
793
  GPT_MINI: "gpt-mini",
@@ -863,6 +872,17 @@ var SupportedAiModels = {
863
872
  tags: ["cheap"]
864
873
  },
865
874
  // Models with always-on reasoning
875
+ // GPT-6 Astra (2026-09-03): OpenAI's frontier tier above Sol. No `none` reasoning effort;
876
+ // temperature/top_p are rejected — Gpt5Agent sends neither, so the same agent serves it.
877
+ // The catalog temperature is only carried for the agent constructor signature.
878
+ [LLM_CONSTANTS.GPT_ASTRA]: {
879
+ displayName: "GPT-6 Astra",
880
+ modelApiName: "gpt-6-astra",
881
+ apiKeyName: API_KEY_CONSTANTS.OPENAI,
882
+ hasThinking: true,
883
+ temperature: 1,
884
+ tags: ["expensive"]
885
+ },
866
886
  // GPT-5.6 family (promoted July 2026 when the limited preview opened up):
867
887
  // sol is the flagship, terra the mainline, luna the cheap tier.
868
888
  [LLM_CONSTANTS.GPT_SOL]: {
@@ -1134,6 +1154,19 @@ var DEEPSEEK_PEAK_SCHEDULE = {
1134
1154
  weekendOffPeak: { utcOffsetHours: 8 }
1135
1155
  };
1136
1156
  var MODEL_PRICING = {
1157
+ // OpenAI GPT-6 Astra (developers.openai.com/api/docs/pricing, 2026-09-03): $10/$50 cache-hit $1
1158
+ // short context, $20/$75 cache-hit $2 long context. OpenAI's pricing table doesn't restate
1159
+ // the boundary; we assume the same 272k threshold as the GPT-5.6 siblings. Cache writes
1160
+ // ($12.50/$25) are not modelled — caching is automatic and we only see hits.
1161
+ [SupportedAiModels[LLM_CONSTANTS.GPT_ASTRA].modelApiName]: {
1162
+ inputPrice: 10,
1163
+ outputPrice: 50,
1164
+ cacheHitPrice: 1,
1165
+ extendedContextInputPrice: 20,
1166
+ extendedContextOutputPrice: 75,
1167
+ extendedContextCacheHitPrice: 2,
1168
+ extendedContextThresholdTokens: 272e3
1169
+ },
1137
1170
  // OpenAI GPT-5.6 models
1138
1171
  // Sol repriced 2026-08-30 (developers.openai.com/api/docs/pricing): $4/$20 short context,
1139
1172
  // $8/$30 past the long-context threshold — the same 272k boundary its siblings use.
@@ -1772,18 +1805,37 @@ var Gpt5Agent = class extends AbstractAgent {
1772
1805
  thinking: z2.string().describe("Your internal chain-of-thought reasoning process used to arrive at the final answer.")
1773
1806
  });
1774
1807
  }
1775
- const response = await this.client.responses.parse({
1776
- model: this.model,
1777
- instructions: this.instruction,
1778
- input,
1779
- max_output_tokens: this.maxOutputTokens,
1780
- text: {
1781
- format: zodTextFormat(schemaToSend, "response_schema")
1808
+ let response;
1809
+ try {
1810
+ response = await this.client.responses.parse({
1811
+ model: this.model,
1812
+ instructions: this.instruction,
1813
+ input,
1814
+ max_output_tokens: this.maxOutputTokens,
1815
+ text: {
1816
+ format: zodTextFormat(schemaToSend, "response_schema")
1817
+ }
1818
+ });
1819
+ } catch (error) {
1820
+ if (error instanceof SyntaxError) {
1821
+ throw new ModelInvalidResponseError(
1822
+ this.model,
1823
+ `malformed JSON output \u2014 the generation was cut off at the ${this.maxOutputTokens}-token output cap or went off the rails (${error.message})`
1824
+ );
1782
1825
  }
1783
- });
1826
+ throw error;
1827
+ }
1828
+ if (response.status === "incomplete") {
1829
+ const reason = response.incomplete_details?.reason ?? "unknown";
1830
+ throw new ModelInvalidResponseError(
1831
+ this.model,
1832
+ `response incomplete (${reason}) at max_output_tokens=${this.maxOutputTokens}`,
1833
+ reason === "max_output_tokens"
1834
+ );
1835
+ }
1784
1836
  if (!response.output_parsed) {
1785
1837
  this.logger(`Parsing failed. Raw content: ${response.output_text}`);
1786
- throw new Error(this.errorMessages.invalidFormat);
1838
+ throw new ModelInvalidResponseError(this.model, this.errorMessages.invalidFormat);
1787
1839
  }
1788
1840
  let reasoningContent = "";
1789
1841
  if (this.enableThinking && response.output_parsed.thinking) {
@@ -1822,6 +1874,9 @@ var Gpt5Agent = class extends AbstractAgent {
1822
1874
  return [response.output_parsed, reasoningContent, tokenUsage];
1823
1875
  } catch (error) {
1824
1876
  this.logger(this.logTemplates.error(this.name, error));
1877
+ if (error instanceof ModelError) {
1878
+ throw error;
1879
+ }
1825
1880
  throw new Error(this.errorMessages.apiError(error));
1826
1881
  }
1827
1882
  }
@@ -1847,6 +1902,14 @@ var Gpt5Agent = class extends AbstractAgent {
1847
1902
  });
1848
1903
  const content = response.output_text;
1849
1904
  if (!content) {
1905
+ if (response.status === "incomplete") {
1906
+ const reason = response.incomplete_details?.reason ?? "unknown";
1907
+ throw new ModelInvalidResponseError(
1908
+ this.model,
1909
+ `empty response, incomplete (${reason}) at max_output_tokens=${this.maxOutputTokens}`,
1910
+ reason === "max_output_tokens"
1911
+ );
1912
+ }
1850
1913
  throw new Error(this.errorMessages.emptyResponse);
1851
1914
  }
1852
1915
  let tokenUsage;
@@ -1879,6 +1942,9 @@ var Gpt5Agent = class extends AbstractAgent {
1879
1942
  return [content, "", tokenUsage];
1880
1943
  } catch (error) {
1881
1944
  this.logger(this.logTemplates.error(this.name, error));
1945
+ if (error instanceof ModelError) {
1946
+ throw error;
1947
+ }
1882
1948
  throw new Error(this.errorMessages.apiError(error));
1883
1949
  }
1884
1950
  }
@@ -4217,6 +4283,7 @@ var AgentFactory = class {
4217
4283
  case LLM_CONSTANTS.CLAUDE_HAIKU:
4218
4284
  return new ClaudeAgent(name, instruction, model.modelApiName, key, shouldEnableThinking);
4219
4285
  // Always-on reasoning models
4286
+ case LLM_CONSTANTS.GPT_ASTRA:
4220
4287
  case LLM_CONSTANTS.GPT_SOL:
4221
4288
  case LLM_CONSTANTS.GPT:
4222
4289
  case LLM_CONSTANTS.GPT_MINI:
@@ -4294,6 +4361,7 @@ export {
4294
4361
  MistralAgent,
4295
4362
  ModelAuthenticationError,
4296
4363
  ModelError,
4364
+ ModelInvalidResponseError,
4297
4365
  ModelOverloadError,
4298
4366
  ModelQuotaExceededError,
4299
4367
  ModelRateLimitError,