@hackerrank/astra-cli 0.1.7 → 0.1.8

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/model.js +5 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hackerrank/astra-cli",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Minimal zero-dependency AI coding agent for the HackerRank AI Gateway.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/model.js CHANGED
@@ -42,7 +42,7 @@ export class GatewayModel {
42
42
  * @param {number} [opts.maxRetries]
43
43
  * @param {(info:object)=>void} [opts.onRetry] called before each retry sleep
44
44
  */
45
- constructor({ model, baseUrl, apiKey, modelKwargs = {}, maxRetries = 5, maxTokens = 8192, onRetry } = {}) {
45
+ constructor({ model, baseUrl, apiKey, modelKwargs = {}, maxRetries = 5, maxTokens = 8192, requestTimeoutMs = 300000, onRetry } = {}) {
46
46
  if (!model) throw new Error("GatewayModel: `model` is required");
47
47
  this.model = model;
48
48
  this.maxTokens = maxTokens;
@@ -50,6 +50,7 @@ export class GatewayModel {
50
50
  this.apiKey = apiKey || process.env.ASTRA_GATEWAY_API_KEY || "";
51
51
  this.modelKwargs = modelKwargs;
52
52
  this.maxRetries = maxRetries;
53
+ this.requestTimeoutMs = requestTimeoutMs;
53
54
  this.onRetry = onRetry || (() => {});
54
55
  this.nCalls = 0;
55
56
  // Cumulative token usage across all calls (exact, from the API).
@@ -96,6 +97,8 @@ export class GatewayModel {
96
97
  let lastErr;
97
98
  for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
98
99
  try {
100
+ const timeoutSignal = AbortSignal.timeout(this.requestTimeoutMs);
101
+ const signal = this.signal ? AbortSignal.any([this.signal, timeoutSignal]) : timeoutSignal;
99
102
  const res = await fetch(`${this.baseUrl}/chat/completions`, {
100
103
  method: "POST",
101
104
  headers: {
@@ -103,7 +106,7 @@ export class GatewayModel {
103
106
  Authorization: `Bearer ${this.apiKey}`,
104
107
  },
105
108
  body: JSON.stringify(body),
106
- signal: this.signal || undefined,
109
+ signal,
107
110
  });
108
111
 
109
112
  if (!res.ok) {