@agentfield/sdk 0.1.137-rc.9 → 0.1.137

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
@@ -879,6 +879,7 @@ declare class AgentFieldClient {
879
879
  status: string;
880
880
  result?: any;
881
881
  error?: string;
882
+ statusReason?: string;
882
883
  errorDetails?: unknown;
883
884
  durationMs?: number;
884
885
  completedAt?: string;
package/dist/index.js CHANGED
@@ -4492,6 +4492,7 @@ var AgentFieldClient = class {
4492
4492
  };
4493
4493
  if (payload.result !== void 0) body.result = wrapResult(payload.result);
4494
4494
  if (payload.error !== void 0) body.error = payload.error;
4495
+ if (payload.statusReason !== void 0) body.status_reason = payload.statusReason;
4495
4496
  if (payload.errorDetails !== void 0) body.error_details = payload.errorDetails;
4496
4497
  if (payload.usage !== void 0) body.usage = payload.usage;
4497
4498
  const bodyStr = JSON.stringify(body);
@@ -6530,12 +6531,18 @@ var Agent = class {
6530
6531
  return this.shutdownPromise;
6531
6532
  }
6532
6533
  async performShutdown() {
6534
+ const timeoutMs = parseShutdownTimeout(process.env.AGENTFIELD_SHUTDOWN_TIMEOUT);
6535
+ let timer;
6536
+ const timeout = new Promise((resolve3) => {
6537
+ timer = setTimeout(() => resolve3("timeout"), timeoutMs);
6538
+ });
6533
6539
  const listenerClosed = new Promise((resolve3, reject) => {
6534
6540
  if (!this.server) return resolve3();
6535
6541
  this.server.close((err) => {
6536
6542
  if (err) reject(err);
6537
6543
  else resolve3();
6538
6544
  });
6545
+ this.server.closeIdleConnections?.();
6539
6546
  });
6540
6547
  try {
6541
6548
  await this.agentFieldClient.shutdown(this.config.nodeId);
@@ -6545,14 +6552,13 @@ var Agent = class {
6545
6552
  if (this.heartbeatTimer) {
6546
6553
  clearInterval(this.heartbeatTimer);
6547
6554
  }
6548
- await listenerClosed;
6549
- const timeoutMs = parseShutdownTimeout(process.env.AGENTFIELD_SHUTDOWN_TIMEOUT);
6550
- let timer;
6551
- const timeout = new Promise((resolve3) => {
6552
- timer = setTimeout(() => resolve3("timeout"), timeoutMs);
6553
- });
6554
6555
  const drained = Promise.allSettled([...this.inFlightExecutions.values()]).then(() => "drained");
6555
- if (await Promise.race([drained, timeout]) === "timeout") {
6556
+ const listenerSettled = listenerClosed.catch((err) => {
6557
+ console.warn("[Agent] HTTP listener close failed during shutdown:", err);
6558
+ });
6559
+ const closedAndDrained = Promise.all([listenerSettled, drained]).then(() => "drained");
6560
+ if (await Promise.race([closedAndDrained, timeout]) === "timeout") {
6561
+ this.server?.closeAllConnections?.();
6556
6562
  for (const executionId of this.inFlightExecutions.keys()) {
6557
6563
  this.cancelRegistry.cancel(executionId, "shutdown_timeout");
6558
6564
  }
@@ -7041,6 +7047,10 @@ var Agent = class {
7041
7047
  }
7042
7048
  }
7043
7049
  async executeSkill(req, res, name) {
7050
+ if (this.shuttingDown) {
7051
+ res.status(503).json({ error: "agent shutting down" });
7052
+ return;
7053
+ }
7044
7054
  try {
7045
7055
  await this.executeInvocation({
7046
7056
  targetName: name,
@@ -7442,10 +7452,12 @@ var Agent = class {
7442
7452
  usage: usage()
7443
7453
  });
7444
7454
  } else if (controller.signal.aborted) {
7455
+ const shutdownCancel = controller.signal.reason === "shutdown_timeout";
7445
7456
  await this.agentFieldClient.reportExecutionResult(executionId, {
7446
7457
  status: "cancelled",
7447
- error: "cancelled_by_control_plane",
7448
- errorDetails: { reason: "cancelled" },
7458
+ error: shutdownCancel ? "cancelled during graceful shutdown" : "cancelled_by_control_plane",
7459
+ statusReason: shutdownCancel ? "shutdown timeout exceeded" : "cancelled",
7460
+ errorDetails: { reason: shutdownCancel ? "shutdown" : "cancelled" },
7449
7461
  durationMs,
7450
7462
  completedAt: completedAt(),
7451
7463
  reasoner: reasonerName,