@byok-sdk/client 0.9.0 → 0.10.0

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.
@@ -6057,13 +6057,15 @@ var AuthManager = class {
6057
6057
  }
6058
6058
  const keyPair = existing ? { privateKey: importPrivateKeyPem(existing.devicePrivateKeyPem), publicKeyBase64Url: existing.devicePublicKey } : generateDeviceKeyPair();
6059
6059
  const url = new URL(BYOK_PAIR_PATH, toHttpBase(this.opts.serverUrl));
6060
+ const machineId = await this.opts.machineId?.();
6060
6061
  const res = await fetch(url, {
6061
6062
  method: "POST",
6062
6063
  headers: { "content-type": "application/json" },
6063
6064
  body: JSON.stringify({
6064
6065
  pairingCode,
6065
6066
  deviceName: this.opts.deviceName ?? os__default.hostname(),
6066
- devicePublicKey: keyPair.publicKeyBase64Url
6067
+ devicePublicKey: keyPair.publicKeyBase64Url,
6068
+ ...machineId === void 0 ? {} : { machineId }
6067
6069
  })
6068
6070
  });
6069
6071
  if (!res.ok) {
@@ -6372,6 +6374,67 @@ var BlobClient = class {
6372
6374
  throw lastFailure;
6373
6375
  }
6374
6376
  };
6377
+ var DEFAULT_TIMEOUT_MS2 = 2e3;
6378
+ var DARWIN_UUID_RE = /"IOPlatformUUID"\s*=\s*"([^"]+)"/u;
6379
+ var WIN32_GUID_RE = /MachineGuid\s+REG_SZ\s+(\S+)/u;
6380
+ var LINUX_MACHINE_ID_PATHS = ["/etc/machine-id", "/var/lib/dbus/machine-id"];
6381
+ async function probeDarwin(run) {
6382
+ const result = await run("ioreg", ["-rd1", "-c", "IOPlatformExpertDevice"]);
6383
+ if (result.exitCode !== 0) return void 0;
6384
+ return DARWIN_UUID_RE.exec(result.stdout)?.[1];
6385
+ }
6386
+ async function probeLinux(readFile3) {
6387
+ for (const path41 of LINUX_MACHINE_ID_PATHS) {
6388
+ try {
6389
+ const contents = (await readFile3(path41)).trim();
6390
+ if (contents.length > 0) return contents;
6391
+ } catch {
6392
+ }
6393
+ }
6394
+ return void 0;
6395
+ }
6396
+ async function probeWin32(run) {
6397
+ const result = await run("reg", [
6398
+ "query",
6399
+ "HKLM\\SOFTWARE\\Microsoft\\Cryptography",
6400
+ "/v",
6401
+ "MachineGuid"
6402
+ ]);
6403
+ if (result.exitCode !== 0) return void 0;
6404
+ return WIN32_GUID_RE.exec(result.stdout)?.[1];
6405
+ }
6406
+ async function withTimeout(probe, timeoutMs) {
6407
+ let timer;
6408
+ const expiry = new Promise((resolve) => {
6409
+ timer = setTimeout(() => resolve(void 0), timeoutMs);
6410
+ timer.unref?.();
6411
+ });
6412
+ try {
6413
+ return await Promise.race([probe, expiry]);
6414
+ } finally {
6415
+ if (timer !== void 0) clearTimeout(timer);
6416
+ }
6417
+ }
6418
+ async function resolveMachineId(options) {
6419
+ const platform = options.platform ?? process.platform;
6420
+ const run = options.run ?? runDeviceCommand;
6421
+ const readFile3 = options.readFile ?? ((path41) => fs12.readFile(path41, "utf8"));
6422
+ let probe;
6423
+ if (platform === "darwin") probe = probeDarwin(run);
6424
+ else if (platform === "linux") probe = probeLinux(readFile3);
6425
+ else if (platform === "win32") probe = probeWin32(run);
6426
+ if (probe === void 0) return void 0;
6427
+ let raw;
6428
+ try {
6429
+ raw = await withTimeout(probe, options.timeoutMs ?? DEFAULT_TIMEOUT_MS2);
6430
+ } catch {
6431
+ return void 0;
6432
+ }
6433
+ const trimmed = raw?.trim();
6434
+ if (trimmed === void 0 || trimmed.length === 0) return void 0;
6435
+ return createHash("sha256").update(`${options.productId}
6436
+ ${trimmed}`, "utf8").digest("hex");
6437
+ }
6375
6438
  var PRESENCE_HINTS_CAPABILITY = "presence.hints";
6376
6439
  var CapabilityDiscoveryError = class extends Error {
6377
6440
  constructor(message, options) {
@@ -11005,7 +11068,7 @@ async function readPinnedFile(directory, fileName, maxBytes = AGENT_MEMORY_MAX_F
11005
11068
  });
11006
11069
  }
11007
11070
  }
11008
- async function readFile(context, relativePath, maxBytes = AGENT_MEMORY_MAX_FILE_BYTES) {
11071
+ async function readFile2(context, relativePath, maxBytes = AGENT_MEMORY_MAX_FILE_BYTES) {
11009
11072
  if (context.filesystem !== void 0) return context.filesystem.read(relativePath, maxBytes);
11010
11073
  return withMemoryParent(context, relativePath, (directory, fileName) => readPinnedFile(directory, fileName, maxBytes));
11011
11074
  }
@@ -11173,7 +11236,7 @@ var AgentMemoryService = class {
11173
11236
  const context = taskContext(this.input);
11174
11237
  const relativePath = validateAgentMemoryPath(input.path);
11175
11238
  if (input.ifRevision !== void 0 && !revision(input.ifRevision)) throw new AgentMemoryError("ifRevision must be a sha256 content revision");
11176
- const current = await readFile(context, relativePath);
11239
+ const current = await readFile2(context, relativePath);
11177
11240
  if (!current.exists) throw new AgentMemoryError("memory file does not exist");
11178
11241
  if (input.ifRevision !== void 0 && current.revision !== input.ifRevision) throw new AgentMemoryRevisionConflictError(input.ifRevision, current.revision);
11179
11242
  const auditWarning = await exclusiveAgentMemoryHome(context.canonicalHome, () => recordAuditWarning(context, "recall", {
@@ -11260,7 +11323,7 @@ async function captureAgentMemorySnapshot(input) {
11260
11323
  const files = [];
11261
11324
  let totalBytes = 0;
11262
11325
  for (const relativePath of paths) {
11263
- const current = await readFile(context, relativePath);
11326
+ const current = await readFile2(context, relativePath);
11264
11327
  if (!current.exists) {
11265
11328
  if (relativePath === "MEMORY.md") throw new AgentMemoryError("MEMORY.md disappeared before snapshot");
11266
11329
  continue;
@@ -13108,8 +13171,49 @@ var TaskRunner = class {
13108
13171
  if (this.tasks.get(active.taskId) !== active || active.beingTornDown) return;
13109
13172
  if (active.messageRequirement !== void 0 && active.messageAccepted !== true) {
13110
13173
  active.pendingMessageCompletion = { finalOutput, ...outcome.document === void 0 ? {} : { document: outcome.document } };
13111
- const record = active.messageOutbox?.get(active.taskId);
13112
- if (record !== void 0) this.sendAgentMessageRecord(active.messageOutbox, record);
13174
+ const outbox = active.messageOutbox;
13175
+ const record = outbox?.get(active.taskId);
13176
+ if (record !== void 0) {
13177
+ this.sendAgentMessageRecord(outbox, record);
13178
+ return;
13179
+ }
13180
+ const body = finalOutput.trim();
13181
+ if (outbox === void 0 || active.agentRef === void 0) {
13182
+ active.pendingMessageCompletion = void 0;
13183
+ await this.fail(active.taskId, "required Agent message lane is unavailable for this task", false);
13184
+ return;
13185
+ }
13186
+ if (body === "") {
13187
+ active.pendingMessageCompletion = void 0;
13188
+ await this.fail(active.taskId, "runtime produced no reply text for the required Agent message", false);
13189
+ return;
13190
+ }
13191
+ try {
13192
+ await outbox.appendDraft({
13193
+ taskId: active.taskId,
13194
+ tenantId: this.deps.tenantId,
13195
+ agentRef: active.agentRef,
13196
+ requirement: active.messageRequirement,
13197
+ contentType: active.messageRequirement.contentType,
13198
+ body,
13199
+ maxPendingEvents: 64,
13200
+ maxPendingBytes: 4 * 1024 * 1024
13201
+ });
13202
+ if (this.tasks.get(active.taskId) !== active || active.beingTornDown) return;
13203
+ const activated = await outbox.activate(active.taskId, active.session.sessionRef);
13204
+ if (this.tasks.get(active.taskId) !== active || active.beingTornDown) return;
13205
+ if (activated === void 0) throw new Error("Agent message draft disappeared before activation");
13206
+ this.sendAgentMessageRecord(outbox, activated);
13207
+ } catch (err) {
13208
+ if (this.tasks.get(active.taskId) !== active || active.beingTornDown) return;
13209
+ const raced = outbox.get(active.taskId);
13210
+ if (raced !== void 0 && raced.sessionRef !== void 0) {
13211
+ this.sendAgentMessageRecord(outbox, raced);
13212
+ return;
13213
+ }
13214
+ active.pendingMessageCompletion = void 0;
13215
+ await this.fail(active.taskId, `failed to deliver the required Agent message: ${errorMessage4(err)}`, false);
13216
+ }
13113
13217
  return;
13114
13218
  }
13115
13219
  await this.publishSuccessfulCompletion(active, finalOutput, outcome.document);
@@ -16201,6 +16305,7 @@ function buildDaemonWithAdapters(config, adapters, overrides = {}, assertionProb
16201
16305
  serverUrl: config.serverUrl,
16202
16306
  store,
16203
16307
  deviceName: config.deviceName,
16308
+ machineId: config.machineId ?? (() => resolveMachineId({ productId: config.productId })),
16204
16309
  onRevoked: () => {
16205
16310
  connectionState = "revoked";
16206
16311
  }
@@ -17499,7 +17604,7 @@ function connectAndHandshake(endpoint, token, opts) {
17499
17604
  });
17500
17605
  });
17501
17606
  }
17502
- function withTimeout(promise, ms, message) {
17607
+ function withTimeout2(promise, ms, message) {
17503
17608
  return new Promise((resolve, reject) => {
17504
17609
  const timer = setTimeout(() => reject(new Error(message)), ms);
17505
17610
  timer.unref?.();
@@ -17578,7 +17683,7 @@ function createControlClient(socket, reader, opts) {
17578
17683
  async request(method, params) {
17579
17684
  if (closed) throw new Error("control connection is closed");
17580
17685
  const { promise } = send(method, params);
17581
- const result = await withTimeout(promise, opts.requestTimeoutMs ?? 1e4, `control request "${method}" timed out`);
17686
+ const result = await withTimeout2(promise, opts.requestTimeoutMs ?? 1e4, `control request "${method}" timed out`);
17582
17687
  return result;
17583
17688
  },
17584
17689
  subscribe(method, params, onEvent) {
@@ -17688,7 +17793,7 @@ ${args.map((a) => ` ${plistString(a)}`).join("\n")}
17688
17793
  }
17689
17794
  function createLaunchdLifecycle(def, deps = {}) {
17690
17795
  const run = deps.run ?? defaultRunner;
17691
- const fs30 = deps.fs ?? promises;
17796
+ const fs31 = deps.fs ?? promises;
17692
17797
  const homedir = deps.homedir ?? (() => os__default.homedir());
17693
17798
  const getuid = deps.getuid ?? (() => {
17694
17799
  if (typeof process.getuid !== "function") {
@@ -17702,7 +17807,7 @@ function createLaunchdLifecycle(def, deps = {}) {
17702
17807
  const serviceTarget = () => `${domainTarget()}/${label}`;
17703
17808
  async function fileExists(p) {
17704
17809
  try {
17705
- await fs30.stat(p);
17810
+ await fs31.stat(p);
17706
17811
  return true;
17707
17812
  } catch {
17708
17813
  return false;
@@ -17710,9 +17815,9 @@ function createLaunchdLifecycle(def, deps = {}) {
17710
17815
  }
17711
17816
  async function writePlist(program) {
17712
17817
  const xml = generateLaunchdPlist({ label, program, logDir: def.logDir });
17713
- await fs30.mkdir(path3__default.dirname(plistPath()), { recursive: true });
17714
- await fs30.mkdir(def.logDir, { recursive: true });
17715
- await fs30.writeFile(plistPath(), xml, "utf8");
17818
+ await fs31.mkdir(path3__default.dirname(plistPath()), { recursive: true });
17819
+ await fs31.mkdir(def.logDir, { recursive: true });
17820
+ await fs31.writeFile(plistPath(), xml, "utf8");
17716
17821
  }
17717
17822
  async function install(opts = {}) {
17718
17823
  await writePlist(opts.program ?? def.program);
@@ -17723,7 +17828,7 @@ function createLaunchdLifecycle(def, deps = {}) {
17723
17828
  }
17724
17829
  async function uninstall() {
17725
17830
  await runIdempotent(run, "launchctl", ["bootout", serviceTarget()], "launchctl bootout", LAUNCHD_NOT_LOADED);
17726
- await fs30.rm(plistPath(), { force: true });
17831
+ await fs31.rm(plistPath(), { force: true });
17727
17832
  }
17728
17833
  async function start() {
17729
17834
  if (!await fileExists(plistPath())) {
@@ -17807,14 +17912,14 @@ WantedBy=default.target
17807
17912
  }
17808
17913
  function createSystemdLifecycle(def, deps = {}) {
17809
17914
  const run = deps.run ?? defaultRunner;
17810
- const fs30 = deps.fs ?? promises;
17915
+ const fs31 = deps.fs ?? promises;
17811
17916
  const homedir = deps.homedir ?? (() => os__default.homedir());
17812
17917
  const name = sanitizeServiceName(def.name);
17813
17918
  const unitName = `${name}.service`;
17814
17919
  const unitPath = () => path3__default.join(homedir(), ".config", "systemd", "user", unitName);
17815
17920
  async function fileExists(p) {
17816
17921
  try {
17817
- await fs30.stat(p);
17922
+ await fs31.stat(p);
17818
17923
  return true;
17819
17924
  } catch {
17820
17925
  return false;
@@ -17822,9 +17927,9 @@ function createSystemdLifecycle(def, deps = {}) {
17822
17927
  }
17823
17928
  async function writeUnit(program) {
17824
17929
  const unit = generateSystemdUnit({ name, displayName: def.displayName ?? def.name, program, logDir: def.logDir });
17825
- await fs30.mkdir(path3__default.dirname(unitPath()), { recursive: true });
17826
- await fs30.mkdir(def.logDir, { recursive: true });
17827
- await fs30.writeFile(unitPath(), unit, "utf8");
17930
+ await fs31.mkdir(path3__default.dirname(unitPath()), { recursive: true });
17931
+ await fs31.mkdir(def.logDir, { recursive: true });
17932
+ await fs31.writeFile(unitPath(), unit, "utf8");
17828
17933
  }
17829
17934
  async function install(opts = {}) {
17830
17935
  await writeUnit(opts.program ?? def.program);
@@ -17833,7 +17938,7 @@ function createSystemdLifecycle(def, deps = {}) {
17833
17938
  }
17834
17939
  async function uninstall() {
17835
17940
  await runIdempotent(run, "systemctl", ["--user", "disable", "--now", unitName], "systemctl disable --now", SYSTEMD_NOT_LOADED);
17836
- await fs30.rm(unitPath(), { force: true });
17941
+ await fs31.rm(unitPath(), { force: true });
17837
17942
  await run("systemctl", ["--user", "daemon-reload"]);
17838
17943
  }
17839
17944
  async function start() {
@@ -17896,7 +18001,7 @@ ${argXml}${cwdXml}
17896
18001
  }
17897
18002
  function createWinswLifecycle(def, deps = {}) {
17898
18003
  const run = deps.run ?? defaultRunner;
17899
- const fs30 = deps.fs ?? promises;
18004
+ const fs31 = deps.fs ?? promises;
17900
18005
  const windows = def.windows;
17901
18006
  if (!windows) {
17902
18007
  throw new Error("WinSW service lifecycle requires `ServiceDefinition.windows.winswBin` (the product-bundled WinSW executable path)");
@@ -17908,7 +18013,7 @@ function createWinswLifecycle(def, deps = {}) {
17908
18013
  const xmlPath = path3__default.join(installDir, `${id}.xml`);
17909
18014
  async function fileExists(p) {
17910
18015
  try {
17911
- await fs30.stat(p);
18016
+ await fs31.stat(p);
17912
18017
  return true;
17913
18018
  } catch {
17914
18019
  return false;
@@ -17916,10 +18021,10 @@ function createWinswLifecycle(def, deps = {}) {
17916
18021
  }
17917
18022
  async function writeFiles(program) {
17918
18023
  const xml = generateWinswXml({ id, displayName: def.displayName ?? def.name, program, logDir: def.logDir });
17919
- await fs30.mkdir(installDir, { recursive: true });
17920
- await fs30.mkdir(def.logDir, { recursive: true });
17921
- await fs30.copyFile(winswBin, exePath);
17922
- await fs30.writeFile(xmlPath, xml, "utf8");
18024
+ await fs31.mkdir(installDir, { recursive: true });
18025
+ await fs31.mkdir(def.logDir, { recursive: true });
18026
+ await fs31.copyFile(winswBin, exePath);
18027
+ await fs31.writeFile(xmlPath, xml, "utf8");
17923
18028
  }
17924
18029
  async function install(opts = {}) {
17925
18030
  await writeFiles(opts.program ?? def.program);
@@ -17929,8 +18034,8 @@ function createWinswLifecycle(def, deps = {}) {
17929
18034
  async function uninstall() {
17930
18035
  await runIdempotent(run, exePath, ["stop"], "winsw stop", WINSW_NOT_INSTALLED);
17931
18036
  await runIdempotent(run, exePath, ["uninstall"], "winsw uninstall", WINSW_NOT_INSTALLED);
17932
- await fs30.rm(exePath, { force: true });
17933
- await fs30.rm(xmlPath, { force: true });
18037
+ await fs31.rm(exePath, { force: true });
18038
+ await fs31.rm(xmlPath, { force: true });
17934
18039
  }
17935
18040
  async function start() {
17936
18041
  if (!await fileExists(xmlPath)) {
@@ -17975,7 +18080,7 @@ function createServiceLifecycle(def, opts = {}) {
17975
18080
 
17976
18081
  // src/bin/official-release.ts
17977
18082
  var OFFICIAL_LOCAL_AGENT_RELEASE = resolveLocalAgentReleaseIdentity({
17978
- version: "0.9.0"
18083
+ version: "0.10.0"
17979
18084
  });
17980
18085
 
17981
18086
  // src/bin/config.ts