@agentfield/sdk 0.1.143 → 0.1.144-rc.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/dist/index.d.ts CHANGED
@@ -838,7 +838,14 @@ declare class AgentFieldClient {
838
838
  durationMs?: number;
839
839
  }): Promise<void>;
840
840
  publishExecutionLogs(payload: ExecutionLogTransportPayload): void;
841
- updateExecutionStatus(executionId: string, update: ExecutionStatusUpdate): Promise<void>;
841
+ updateExecutionStatus(executionId: string, update: ExecutionStatusUpdate, maxRetries?: number): Promise<void>;
842
+ /**
843
+ * POST a status update, matching the Go SDK's postExecutionStatus: retry
844
+ * transport errors, 408, 429 and 5xx with 1s, 2s, 4s, 8s backoff; any other
845
+ * status (e.g. 404 unknown execution, 409 terminal-status conflict) will not
846
+ * change on a resend, so it fails fast. Throws the last error on failure.
847
+ */
848
+ private postExecutionStatus;
842
849
  /** Build the `X-*` dispatch headers shared by execute / executeAsync. */
843
850
  private buildExecuteHeaders;
844
851
  /**
package/dist/index.js CHANGED
@@ -5439,7 +5439,7 @@ var AgentFieldClient = class {
5439
5439
  }).catch(() => {
5440
5440
  });
5441
5441
  }
5442
- async updateExecutionStatus(executionId, update) {
5442
+ async updateExecutionStatus(executionId, update, maxRetries = 5) {
5443
5443
  if (!executionId) {
5444
5444
  throw new Error("executionId is required to update workflow status");
5445
5445
  }
@@ -5451,11 +5451,36 @@ var AgentFieldClient = class {
5451
5451
  progress: update.progress !== void 0 ? Math.round(update.progress) : void 0,
5452
5452
  status_reason: update.statusReason
5453
5453
  };
5454
- const bodyStr = JSON.stringify(payload);
5455
- const authHeaders = this.didAuthenticator.signRequest(Buffer.from(bodyStr));
5456
- await this.http.post(`/api/v1/executions/${executionId}/status`, bodyStr, {
5457
- headers: this.mergeHeaders({ "Content-Type": "application/json", ...authHeaders })
5458
- });
5454
+ await this.postExecutionStatus(executionId, JSON.stringify(payload), maxRetries);
5455
+ }
5456
+ /**
5457
+ * POST a status update, matching the Go SDK's postExecutionStatus: retry
5458
+ * transport errors, 408, 429 and 5xx with 1s, 2s, 4s, 8s backoff; any other
5459
+ * status (e.g. 404 unknown execution, 409 terminal-status conflict) will not
5460
+ * change on a resend, so it fails fast. Throws the last error on failure.
5461
+ */
5462
+ async postExecutionStatus(executionId, bodyStr, maxRetries) {
5463
+ let lastErr;
5464
+ for (let attempt = 0; attempt < maxRetries; attempt++) {
5465
+ const authHeaders = this.didAuthenticator.signRequest(Buffer.from(bodyStr));
5466
+ try {
5467
+ await this.http.post(`/api/v1/executions/${encodeURIComponent(executionId)}/status`, bodyStr, {
5468
+ headers: this.mergeHeaders({ "Content-Type": "application/json", ...authHeaders }),
5469
+ timeout: 3e4
5470
+ });
5471
+ return;
5472
+ } catch (err) {
5473
+ lastErr = err;
5474
+ const status = axios5.isAxiosError(err) ? err.response?.status : void 0;
5475
+ if (status !== void 0 && !isRetryableStatus(status)) {
5476
+ throw err;
5477
+ }
5478
+ }
5479
+ if (attempt < maxRetries - 1) {
5480
+ await sleep2(2 ** attempt * 1e3);
5481
+ }
5482
+ }
5483
+ throw lastErr;
5459
5484
  }
5460
5485
  /** Build the `X-*` dispatch headers shared by execute / executeAsync. */
5461
5486
  buildExecuteHeaders(metadata) {
@@ -5649,28 +5674,12 @@ var AgentFieldClient = class {
5649
5674
  if (payload.statusReason !== void 0) body.status_reason = payload.statusReason;
5650
5675
  if (payload.errorDetails !== void 0) body.error_details = payload.errorDetails;
5651
5676
  if (payload.usage !== void 0) body.usage = payload.usage;
5652
- const bodyStr = JSON.stringify(body);
5653
- const authHeaders = this.didAuthenticator.signRequest(Buffer.from(bodyStr));
5654
- for (let attempt = 0; attempt < maxRetries; attempt++) {
5655
- try {
5656
- const res = await this.http.post(
5657
- `/api/v1/executions/${encodeURIComponent(executionId)}/status`,
5658
- bodyStr,
5659
- {
5660
- headers: this.mergeHeaders({ "Content-Type": "application/json", ...authHeaders }),
5661
- timeout: 3e4
5662
- }
5663
- );
5664
- if (res.status >= 200 && res.status < 300) {
5665
- return true;
5666
- }
5667
- } catch {
5668
- }
5669
- if (attempt < maxRetries - 1) {
5670
- await sleep2(2 ** attempt * 1e3);
5671
- }
5677
+ try {
5678
+ await this.postExecutionStatus(executionId, JSON.stringify(body), maxRetries);
5679
+ return true;
5680
+ } catch {
5681
+ return false;
5672
5682
  }
5673
- return false;
5674
5683
  }
5675
5684
  async discoverCapabilities(options = {}) {
5676
5685
  const format = (options.format ?? "json").toLowerCase();
@@ -5849,6 +5858,9 @@ var AgentFieldClient = class {
5849
5858
  });
5850
5859
  }
5851
5860
  };
5861
+ function isRetryableStatus(status) {
5862
+ return status === 408 || status === 429 || status >= 500;
5863
+ }
5852
5864
  function sleep2(ms) {
5853
5865
  return new Promise((resolve3) => setTimeout(resolve3, ms));
5854
5866
  }