@alan-ai-hq/agent-manager-darwin-arm64 0.1.168 → 0.1.170

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/alan-agent.cjs CHANGED
@@ -58209,7 +58209,7 @@ var import_node_worker_threads2 = require("worker_threads");
58209
58209
  // package.json
58210
58210
  var package_default = {
58211
58211
  name: "@alan-ai-hq/agent-manager",
58212
- version: "0.1.168",
58212
+ version: "0.1.170",
58213
58213
  private: true,
58214
58214
  type: "module",
58215
58215
  description: "Alan machine runtime (alan-agent): identity, link, reconciler, session holders, run log, uploader, local API",
@@ -58779,6 +58779,7 @@ function createHttpTransport() {
58779
58779
  init_runtime_v2();
58780
58780
  init_zod();
58781
58781
  var REQUEST_TIMEOUT_MS = 3e4;
58782
+ var PROBE_TIMEOUT_MS = 5e3;
58782
58783
  var errorBodySchema = external_exports.object({ error: external_exports.string() });
58783
58784
  var PROBE_RENEWAL_TOKEN = "alan_runtime_renew_probe_not_a_token";
58784
58785
  function isTransportFailure(error62) {
@@ -58859,8 +58860,14 @@ function createEnrollmentClient({
58859
58860
  },
58860
58861
  servesMachineRoutes: async (signal) => {
58861
58862
  const body = { renewalToken: PROBE_RENEWAL_TOKEN };
58862
- const response = await post(MACHINE_PATHS.renew, body, signal);
58863
- return response.status === 401 && errorCode(response) === "invalid_renewal_token";
58863
+ const bounded = AbortSignal.any([signal, AbortSignal.timeout(PROBE_TIMEOUT_MS)]);
58864
+ try {
58865
+ const response = await post(MACHINE_PATHS.renew, body, bounded);
58866
+ return response.status === 401 && errorCode(response) === "invalid_renewal_token";
58867
+ } catch (error62) {
58868
+ if (signal.aborted || !isTransportFailure(error62)) throw error62;
58869
+ return false;
58870
+ }
58864
58871
  },
58865
58872
  renew: async (renewalToken, signal) => {
58866
58873
  const body = { renewalToken };
@@ -59037,10 +59044,21 @@ function credentialFailureMessage(response, fallback) {
59037
59044
  return fallback;
59038
59045
  }
59039
59046
  }
59047
+ function credentialRetryDelay(response, attempt2, now) {
59048
+ const hint = headerValue(response, "retry-after")?.trim();
59049
+ let minimum = 250 * 2 ** attempt2;
59050
+ if (hint) {
59051
+ const seconds = Number(hint);
59052
+ const delay4 = Number.isFinite(seconds) && seconds >= 0 ? seconds * 1e3 : Date.parse(hint) - now;
59053
+ if (Number.isFinite(delay4)) minimum = Math.max(minimum, delay4);
59054
+ }
59055
+ return minimum + Math.random() * minimum * 0.2;
59056
+ }
59040
59057
  function createHolderApiClient({
59041
59058
  apiUrl,
59042
59059
  accessToken,
59043
- transport
59060
+ transport,
59061
+ clock = systemClock
59044
59062
  }) {
59045
59063
  const request2 = (method, path4, signal, json2) => transport.send({
59046
59064
  method,
@@ -59052,6 +59070,18 @@ function createHolderApiClient({
59052
59070
  ...json2 === void 0 ? {} : { body: JSON.stringify(json2) },
59053
59071
  signal: AbortSignal.any([signal, AbortSignal.timeout(REQUEST_TIMEOUT_MS3)])
59054
59072
  });
59073
+ const readProviderCredential = async (runId, signal) => {
59074
+ const deadline = clock.monotonic() + REQUEST_TIMEOUT_MS3;
59075
+ const budgetSignal = AbortSignal.any([signal, AbortSignal.timeout(REQUEST_TIMEOUT_MS3)]);
59076
+ for (let attempt2 = 0; ; attempt2 += 1) {
59077
+ budgetSignal.throwIfAborted();
59078
+ const response = await request2("GET", runProviderCredentialPath(runId), budgetSignal);
59079
+ if (attempt2 >= 2 || ![429, 502, 503, 504].includes(response.status)) return response;
59080
+ const delay4 = credentialRetryDelay(response, attempt2, clock.now());
59081
+ if (clock.monotonic() + delay4 >= deadline) return response;
59082
+ await clock.sleep(delay4, budgetSignal);
59083
+ }
59084
+ };
59055
59085
  return {
59056
59086
  downloadAttachment: async (runId, attachmentId, signal) => {
59057
59087
  const response = await request2("GET", runAttachmentPath(runId, attachmentId), signal);
@@ -59064,7 +59094,7 @@ function createHolderApiClient({
59064
59094
  return response.body;
59065
59095
  },
59066
59096
  fetchProviderCredential: async (runId, signal) => {
59067
- const response = await request2("GET", runProviderCredentialPath(runId), signal);
59097
+ const response = await readProviderCredential(runId, signal);
59068
59098
  if (response.status === 404) return { env: {} };
59069
59099
  if (!isOk(response)) {
59070
59100
  throw new RuntimeFault(
@@ -60365,7 +60395,7 @@ var import_node_child_process3 = require("child_process");
60365
60395
  var import_promises8 = require("fs/promises");
60366
60396
  var import_node_util3 = require("util");
60367
60397
  var execFileAsync3 = (0, import_node_util3.promisify)(import_node_child_process3.execFile);
60368
- var PROBE_TIMEOUT_MS = 2e3;
60398
+ var PROBE_TIMEOUT_MS2 = 2e3;
60369
60399
  async function readProcessRss(pid) {
60370
60400
  if (process.platform === "linux") {
60371
60401
  const status = await (0, import_promises8.readFile)(`/proc/${pid}/status`, "utf8").catch(() => null);
@@ -60382,7 +60412,7 @@ async function readProcessRss(pid) {
60382
60412
  "-Command",
60383
60413
  `(Get-Process -Id ${pid} -ErrorAction Stop).WorkingSet64`
60384
60414
  ],
60385
- { timeout: PROBE_TIMEOUT_MS, windowsHide: true }
60415
+ { timeout: PROBE_TIMEOUT_MS2, windowsHide: true }
60386
60416
  );
60387
60417
  const bytes = Number(stdout.trim());
60388
60418
  return stdout.trim() && Number.isFinite(bytes) && bytes > 0 ? bytes : null;
@@ -60392,7 +60422,7 @@ async function readProcessRss(pid) {
60392
60422
  }
60393
60423
  try {
60394
60424
  const { stdout } = await execFileAsync3("ps", ["-o", "rss=", "-p", String(pid)], {
60395
- timeout: PROBE_TIMEOUT_MS
60425
+ timeout: PROBE_TIMEOUT_MS2
60396
60426
  });
60397
60427
  const kilobytes = Number(stdout.trim());
60398
60428
  return stdout.trim().length > 0 && Number.isFinite(kilobytes) ? kilobytes * 1024 : null;
@@ -60410,7 +60440,7 @@ async function processMemoryRows() {
60410
60440
  "-Command",
60411
60441
  "Get-CimInstance Win32_Process | Select-Object ProcessId,ParentProcessId,WorkingSetSize | ConvertTo-Json -Compress"
60412
60442
  ],
60413
- { timeout: PROBE_TIMEOUT_MS, maxBuffer: 8 * 1024 * 1024, windowsHide: true }
60443
+ { timeout: PROBE_TIMEOUT_MS2, maxBuffer: 8 * 1024 * 1024, windowsHide: true }
60414
60444
  );
60415
60445
  const parsed = JSON.parse(stdout2);
60416
60446
  if (!Array.isArray(parsed)) return [];
@@ -60427,7 +60457,7 @@ async function processMemoryRows() {
60427
60457
  });
60428
60458
  }
60429
60459
  const { stdout } = await execFileAsync3("ps", ["-A", "-o", "pid=,ppid=,rss="], {
60430
- timeout: PROBE_TIMEOUT_MS,
60460
+ timeout: PROBE_TIMEOUT_MS2,
60431
60461
  maxBuffer: 8 * 1024 * 1024
60432
60462
  });
60433
60463
  return stdout.trim().split("\n").flatMap((line) => {
@@ -74767,6 +74797,9 @@ async function installedServiceSpec(ctx) {
74767
74797
  }
74768
74798
  return spec;
74769
74799
  }
74800
+ function sameOrigin(requested, configured) {
74801
+ return URL.canParse(requested) && new URL(requested).origin === new URL(configured).origin;
74802
+ }
74770
74803
  function flagValue(argv, name) {
74771
74804
  const index = argv.indexOf(name);
74772
74805
  if (index !== -1) {
@@ -75323,6 +75356,10 @@ async function scrubLegacyInstall(install2) {
75323
75356
  await (0, import_promises76.rm)(install2.configPath, { force: true });
75324
75357
  await (0, import_promises76.rm)(install2.ownerLeasePath, { force: true });
75325
75358
  }
75359
+ async function retireLegacyInstall(install2) {
75360
+ await (0, import_promises76.rename)(install2.configPath, `${install2.configPath}.retired-v1`);
75361
+ await (0, import_promises76.rm)(install2.ownerLeasePath, { force: true });
75362
+ }
75326
75363
  async function exchangeCredential(deps) {
75327
75364
  const { config: config2 } = deps.install;
75328
75365
  if (deps.setup !== void 0) {
@@ -75507,7 +75544,7 @@ async function runStatus(argv, ctx = cliContext()) {
75507
75544
  }
75508
75545
 
75509
75546
  // src/cli/commands/doctor.ts
75510
- var PROBE_TIMEOUT_MS2 = 1e4;
75547
+ var PROBE_TIMEOUT_MS3 = 1e4;
75511
75548
  var LOCAL_TIMEOUT_MS = 3e3;
75512
75549
  var DISK_WARN_BYTES = 1024 ** 3;
75513
75550
  var DISK_FAIL_BYTES = 100 * 1024 ** 2;
@@ -75599,7 +75636,7 @@ async function credentialCheck(ctx) {
75599
75636
  async function serverCheck(facts) {
75600
75637
  const api = createApiClient({ apiUrl: facts.apiUrl, accessToken: () => facts.accessToken });
75601
75638
  try {
75602
- const desired = await api.fetchDesired(AbortSignal.timeout(PROBE_TIMEOUT_MS2));
75639
+ const desired = await api.fetchDesired(AbortSignal.timeout(PROBE_TIMEOUT_MS3));
75603
75640
  return check2("server", "ok", `${facts.apiUrl} accepts this machine's credential`, {
75604
75641
  machineId: facts.machineId,
75605
75642
  desiredRuns: desired.runs.length
@@ -75625,7 +75662,7 @@ function isStale(machine, now) {
75625
75662
  async function machinesCheck(facts) {
75626
75663
  const api = createApiClient({ apiUrl: facts.apiUrl, accessToken: () => facts.accessToken });
75627
75664
  try {
75628
- const machines = await api.listSiblings(AbortSignal.timeout(PROBE_TIMEOUT_MS2));
75665
+ const machines = await api.listSiblings(AbortSignal.timeout(PROBE_TIMEOUT_MS3));
75629
75666
  if (machines === null) {
75630
75667
  return check2("machines", "skipped", `${facts.apiUrl} does not list machines`);
75631
75668
  }
@@ -75655,7 +75692,7 @@ async function releaseCheck(ctx, facts) {
75655
75692
  const apiUrl = facts?.apiUrl ?? ctx.config.apiUrl;
75656
75693
  const api = createApiClient({ apiUrl, accessToken: () => facts?.accessToken ?? "" });
75657
75694
  try {
75658
- const release2 = await api.currentRelease(AbortSignal.timeout(PROBE_TIMEOUT_MS2));
75695
+ const release2 = await api.currentRelease(AbortSignal.timeout(PROBE_TIMEOUT_MS3));
75659
75696
  const layout = installLayout(ctx.config.installDir, ctx.config.profile);
75660
75697
  const plan2 = planUpdate({
75661
75698
  current: package_default.version,
@@ -76349,10 +76386,32 @@ var import_node_path80 = require("path");
76349
76386
  init_zod();
76350
76387
 
76351
76388
  // src/cli/legacy.ts
76389
+ async function staleLegacyReason(ctx, install2) {
76390
+ if (!sameOrigin(install2.config.apiUrl, ctx.config.apiUrl)) return "other_server";
76391
+ const registered = await readMachineFile(ctx.paths) !== null || (await readInstallation(ctx.paths))?.machineId !== void 0;
76392
+ return registered ? "already_on_v2" : null;
76393
+ }
76352
76394
  async function adoptLegacyInstall(ctx, deps, adoption) {
76353
76395
  if (!ctx.config.adoptsLegacyInstall) return null;
76354
76396
  const install2 = await findLegacyInstall(ctx.config.home, ctx.config.profile);
76355
76397
  if (install2 === null) return null;
76398
+ const stale = await staleLegacyReason(ctx, install2);
76399
+ if (stale !== null) {
76400
+ if (adoption.dryRun === true) {
76401
+ return {
76402
+ kind: "planned",
76403
+ steps: ["remove the v1 service", `move ${install2.configPath} aside (${stale})`]
76404
+ };
76405
+ }
76406
+ const removal = await removeLegacyService(ctx.host, ctx.config.profile);
76407
+ await retireLegacyInstall(install2);
76408
+ deps.log.info("legacy.retired", {
76409
+ reason: stale,
76410
+ apiUrl: install2.config.apiUrl,
76411
+ serviceFound: removal.found
76412
+ });
76413
+ return { kind: "retired", reason: stale };
76414
+ }
76356
76415
  return migrateFromV1({
76357
76416
  install: install2,
76358
76417
  removeService: () => removeLegacyService(ctx.host, ctx.config.profile),
@@ -81648,7 +81707,7 @@ function refusalFailure(refusal2) {
81648
81707
  var import_promises82 = require("dns/promises");
81649
81708
  var import_node_net5 = require("net");
81650
81709
  var import_node_tls2 = require("tls");
81651
- var PROBE_TIMEOUT_MS3 = 5e3;
81710
+ var PROBE_TIMEOUT_MS4 = 5e3;
81652
81711
  function openSocket(url3) {
81653
81712
  const secure = url3.protocol === "https:" || url3.protocol === "wss:";
81654
81713
  const host = url3.hostname;
@@ -81669,7 +81728,7 @@ async function connectOnce(url3, clock) {
81669
81728
  socket.once(ready, () => resolve14(null));
81670
81729
  socket.once("error", (error62) => resolve14(classifyTransportFailure(error62)));
81671
81730
  }),
81672
- clock.sleep(PROBE_TIMEOUT_MS3, timer.signal).then(
81731
+ clock.sleep(PROBE_TIMEOUT_MS4, timer.signal).then(
81673
81732
  () => "connection_timeout",
81674
81733
  () => null
81675
81734
  )
@@ -83581,9 +83640,6 @@ async function startMachinePlane(deps) {
83581
83640
  // src/cli/commands/machine-slot.ts
83582
83641
  var NOT_SET_UP_LINK = { state: "stopped" };
83583
83642
  var FINAL_UPLOAD_WAIT_MS = 2e4;
83584
- function sameOrigin(requested, configured) {
83585
- return URL.canParse(requested) && new URL(requested).origin === new URL(configured).origin;
83586
- }
83587
83643
  function faultMessage(error62) {
83588
83644
  return error62 instanceof Error ? error62.message : String(error62);
83589
83645
  }
package/alan-holder.cjs CHANGED
@@ -48411,10 +48411,21 @@ function credentialFailureMessage(response, fallback) {
48411
48411
  return fallback;
48412
48412
  }
48413
48413
  }
48414
+ function credentialRetryDelay(response, attempt, now) {
48415
+ const hint = headerValue(response, "retry-after")?.trim();
48416
+ let minimum = 250 * 2 ** attempt;
48417
+ if (hint) {
48418
+ const seconds = Number(hint);
48419
+ const delay4 = Number.isFinite(seconds) && seconds >= 0 ? seconds * 1e3 : Date.parse(hint) - now;
48420
+ if (Number.isFinite(delay4)) minimum = Math.max(minimum, delay4);
48421
+ }
48422
+ return minimum + Math.random() * minimum * 0.2;
48423
+ }
48414
48424
  function createHolderApiClient({
48415
48425
  apiUrl,
48416
48426
  accessToken,
48417
- transport
48427
+ transport,
48428
+ clock = systemClock
48418
48429
  }) {
48419
48430
  const request2 = (method, path, signal, json2) => transport.send({
48420
48431
  method,
@@ -48426,6 +48437,18 @@ function createHolderApiClient({
48426
48437
  ...json2 === void 0 ? {} : { body: JSON.stringify(json2) },
48427
48438
  signal: AbortSignal.any([signal, AbortSignal.timeout(REQUEST_TIMEOUT_MS)])
48428
48439
  });
48440
+ const readProviderCredential = async (runId, signal) => {
48441
+ const deadline = clock.monotonic() + REQUEST_TIMEOUT_MS;
48442
+ const budgetSignal = AbortSignal.any([signal, AbortSignal.timeout(REQUEST_TIMEOUT_MS)]);
48443
+ for (let attempt = 0; ; attempt += 1) {
48444
+ budgetSignal.throwIfAborted();
48445
+ const response = await request2("GET", runProviderCredentialPath(runId), budgetSignal);
48446
+ if (attempt >= 2 || ![429, 502, 503, 504].includes(response.status)) return response;
48447
+ const delay4 = credentialRetryDelay(response, attempt, clock.now());
48448
+ if (clock.monotonic() + delay4 >= deadline) return response;
48449
+ await clock.sleep(delay4, budgetSignal);
48450
+ }
48451
+ };
48429
48452
  return {
48430
48453
  downloadAttachment: async (runId, attachmentId, signal) => {
48431
48454
  const response = await request2("GET", runAttachmentPath(runId, attachmentId), signal);
@@ -48438,7 +48461,7 @@ function createHolderApiClient({
48438
48461
  return response.body;
48439
48462
  },
48440
48463
  fetchProviderCredential: async (runId, signal) => {
48441
- const response = await request2("GET", runProviderCredentialPath(runId), signal);
48464
+ const response = await readProviderCredential(runId, signal);
48442
48465
  if (response.status === 404) return { env: {} };
48443
48466
  if (!isOk(response)) {
48444
48467
  throw new RuntimeFault(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alan-ai-hq/agent-manager-darwin-arm64",
3
- "version": "0.1.168",
3
+ "version": "0.1.170",
4
4
  "description": "Alan machine runtime (alan-agent) for one platform: the official Node.js binary, the runtime bundle and its launcher. Installed by @alan-ai-hq/agent-manager.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "homepage": "https://tryalan.ai",