@byok-sdk/client 0.7.0 → 0.8.0-beta.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.
@@ -2,7 +2,7 @@
2
2
  import { randomUUID, createHash, randomBytes, timingSafeEqual, createHmac, createPrivateKey, generateKeyPairSync, sign } from 'crypto';
3
3
  import { readFileSync, promises, linkSync, fstatSync, lstatSync, unlinkSync, constants, readSync, openSync, writeFileSync, fchmodSync, fsyncSync, closeSync, opendirSync, existsSync, realpathSync, mkdirSync, renameSync, chmodSync, statSync, readdirSync } from 'fs';
4
4
  import path, { isAbsolute, join } from 'path';
5
- import { AGENT_CONTENT_ARTIFACT_READ_CAPABILITY, AGENT_CONTENT_TRANSCRIPT_READ_CAPABILITY, AGENT_CONTENT_WORKSPACE_READ_CAPABILITY, TASK_STATES, AgentEgressPolicySchema, CONFIGURED_TOOLSETS_MAX_ITEMS, ToolsetIdSchema, AgentRefSchema, AgentContentReceiptPayloadSchema, BYOK_PAIR_PATH, PairResponseSchema, BYOK_CHALLENGE_PATH, BYOK_TOKEN_PATH, partitionAgentEvents, TASK_TRANSITIONS, encodeEnvelope, PROTOCOL_VERSION, createEnvelope, AGENT_EGRESS_RELIABLE_ACK_CAPABILITY, byokBlobUrlPath, BYOK_BLOBS_PATH, byokBlobFinalizePath, AGENT_EGRESS_POLICY_CAPABILITY, parseMessage, checkResultDocument, MAX_MESSAGES_PER_BATCH, BYOK_CAPABILITIES_PATH, BYOK_PRESENCE_PATH, RuntimeIdSchema, TERMINAL_INFERENCE_USAGE_MAX_DURATION_MS, TERMINAL_INFERENCE_USAGE_MAX_TOKENS, RESULT_DOCUMENT_MAX_BYTES, decodeEnvelope, BYOK_EVENTS_PATH, BYOK_MESSAGES_PATH, MessagesSendResponseSchema, UnknownMessageTypeError, BYOK_WS_PATH } from '@byok-sdk/protocol';
5
+ import { AGENT_CONTENT_ARTIFACT_READ_CAPABILITY, AGENT_CONTENT_TRANSCRIPT_READ_CAPABILITY, AGENT_CONTENT_WORKSPACE_READ_CAPABILITY, TASK_STATES, AgentEgressPolicySchema, CONFIGURED_TOOLSETS_MAX_ITEMS, ToolsetIdSchema, AgentRefSchema, AgentContentReceiptPayloadSchema, BYOK_PAIR_PATH, PairResponseSchema, BYOK_CHALLENGE_PATH, BYOK_TOKEN_PATH, partitionAgentEvents, TASK_TRANSITIONS, encodeEnvelope, PROTOCOL_VERSION, createEnvelope, AGENT_EGRESS_RELIABLE_ACK_CAPABILITY, byokBlobUrlPath, BYOK_BLOBS_PATH, byokBlobFinalizePath, AGENT_EGRESS_POLICY_CAPABILITY, AGENT_EGRESS_FRESH_SESSION_CAPABILITY, parseMessage, checkResultDocument, MAX_MESSAGES_PER_BATCH, BYOK_CAPABILITIES_PATH, BYOK_PRESENCE_PATH, RuntimeIdSchema, TERMINAL_INFERENCE_USAGE_MAX_DURATION_MS, TERMINAL_INFERENCE_USAGE_MAX_TOKENS, RESULT_DOCUMENT_MAX_BYTES, decodeEnvelope, BYOK_EVENTS_PATH, BYOK_MESSAGES_PATH, MessagesSendResponseSchema, UnknownMessageTypeError, BYOK_WS_PATH } from '@byok-sdk/protocol';
6
6
  import { execFile, spawn } from 'child_process';
7
7
  import os from 'os';
8
8
  import { isTenantId, DEVICE_ASSERTION_AUDIENCE_MAX_BYTES, DEVICE_ASSERTION_DEFAULT_TTL_MS, DEVICE_ASSERTION_MAX_TTL_MS, nonceSigningBytes, CapabilityDeclarationSchema, hasCapability, DeviceAssertionClaimsSchema, deviceAssertionSigningInput, DEVICE_ASSERTION_SCHEMA_ID } from '@byok-sdk/core';
@@ -9910,6 +9910,11 @@ function offeredAgentRef(payload) {
9910
9910
  if (!Object.prototype.hasOwnProperty.call(payload, "agentRef")) return void 0;
9911
9911
  return validateAgentRef(payload.agentRef);
9912
9912
  }
9913
+ function offeredSessionRef(payload) {
9914
+ if (!Object.prototype.hasOwnProperty.call(payload, "sessionRef")) return void 0;
9915
+ const value = payload.sessionRef;
9916
+ return typeof value === "string" ? value : void 0;
9917
+ }
9913
9918
  function errorMessage4(err) {
9914
9919
  return err instanceof Error ? err.message : String(err);
9915
9920
  }
@@ -10278,6 +10283,9 @@ var TaskRunner = class {
10278
10283
  case "task.offer_for_agent_with_egress":
10279
10284
  await this.handleOffer(envelope.task_id, envelope.payload, true);
10280
10285
  return;
10286
+ case "task.offer_for_agent_with_egress_fresh":
10287
+ await this.handleOffer(envelope.task_id, envelope.payload, true);
10288
+ return;
10281
10289
  case "task.cancel":
10282
10290
  await this.handleCancel(envelope.task_id, envelope.payload.reason);
10283
10291
  return;
@@ -10319,6 +10327,7 @@ var TaskRunner = class {
10319
10327
  const decline = (reason, retryable) => {
10320
10328
  this.decline(taskId, reason, retryable, agentRef);
10321
10329
  };
10330
+ const sessionRef = offeredSessionRef(payload);
10322
10331
  if ("egressPolicy" in payload) {
10323
10332
  if (this.deps.agentEgressPolicy === void 0 || !sameEgressPolicy(this.deps.agentEgressPolicy, payload.egressPolicy)) {
10324
10333
  decline("Agent egress offer policy is not exactly enabled by this daemon", false);
@@ -10420,11 +10429,11 @@ var TaskRunner = class {
10420
10429
  let plainWorkspaceNeedsResolve = false;
10421
10430
  if (agentBinding !== void 0) {
10422
10431
  workspaceDir = agentBinding.lease.cwd;
10423
- if (payload.sessionRef !== void 0) {
10432
+ if (sessionRef !== void 0) {
10424
10433
  try {
10425
10434
  await this.deps.agentSessionHandoffs.requireMatch({
10426
10435
  agentRef: agentBinding.resolution.agentRef,
10427
- sessionRef: payload.sessionRef,
10436
+ sessionRef,
10428
10437
  runtimeId: pick.descriptor.id,
10429
10438
  cwd: workspaceDir
10430
10439
  });
@@ -10446,15 +10455,15 @@ var TaskRunner = class {
10446
10455
  return;
10447
10456
  }
10448
10457
  } else if (this.deps.gitWorkspaceManager && this.deps.gitWorkspaceStore) {
10449
- known = payload.sessionRef ? await this.deps.sessionWorkspaces.get(payload.sessionRef) : void 0;
10458
+ known = sessionRef ? await this.deps.sessionWorkspaces.get(sessionRef) : void 0;
10450
10459
  const gitManager = this.deps.gitWorkspaceManager;
10451
10460
  const gitStore = this.deps.gitWorkspaceStore;
10452
- if (payload.sessionRef) {
10453
- const ledger = await gitStore.findBySessionAnyPhase(payload.sessionRef).catch(() => void 0);
10461
+ if (sessionRef) {
10462
+ const ledger = await gitStore.findBySessionAnyPhase(sessionRef).catch(() => void 0);
10454
10463
  const sameProtocolTask = ledger?.taskId === taskId;
10455
10464
  const interruptedOldTask = ledger?.phase === "interrupted" && sameProtocolTask;
10456
10465
  const activeDifferentTask = ledger !== void 0 && ledger.taskId !== taskId && (ledger.phase === "preparing" || ledger.phase === "active");
10457
- if (!known || known.workspaceKind !== "git" || !known.gitWorkspaceId || !ledger || ledger.workspaceId !== known.gitWorkspaceId || ledger.sessionRef !== payload.sessionRef || path.resolve(ledger.workspaceDir) !== path.resolve(known.workspaceDir) || interruptedOldTask || activeDifferentTask) {
10466
+ if (!known || known.workspaceKind !== "git" || !known.gitWorkspaceId || !ledger || ledger.workspaceId !== known.gitWorkspaceId || ledger.sessionRef !== sessionRef || path.resolve(ledger.workspaceDir) !== path.resolve(known.workspaceDir) || interruptedOldTask || activeDifferentTask) {
10458
10467
  decline("session is incompatible with Git workspace mode", true);
10459
10468
  return;
10460
10469
  }
@@ -10473,13 +10482,13 @@ var TaskRunner = class {
10473
10482
  gitWorkspaceId = randomUUID();
10474
10483
  }
10475
10484
  try {
10476
- gitLease = await gitManager.acquireLease(workspaceDir, payload.sessionRef);
10485
+ gitLease = await gitManager.acquireLease(workspaceDir, sessionRef);
10477
10486
  } catch {
10478
10487
  decline("workspace is busy or unavailable", true);
10479
10488
  return;
10480
10489
  }
10481
10490
  } else if (!this.deps.gitWorkspaceManager && !this.deps.gitWorkspaceStore) {
10482
- known = payload.sessionRef ? await this.deps.sessionWorkspaces.get(payload.sessionRef) : void 0;
10491
+ known = sessionRef ? await this.deps.sessionWorkspaces.get(sessionRef) : void 0;
10483
10492
  workspaceDir = known?.workspaceDir ?? path.join(this.deps.workspaceRoot, taskId);
10484
10493
  plainWorkspaceNeedsResolve = true;
10485
10494
  } else {
@@ -10498,7 +10507,7 @@ var TaskRunner = class {
10498
10507
  policy: decision.policy,
10499
10508
  requiredToolsetIds: requiredToolsets ?? [],
10500
10509
  ...offered.dispatchSelection === void 0 ? {} : { dispatchSelection: offered.dispatchSelection },
10501
- ...payload.sessionRef === void 0 || known === void 0 && agentBinding === void 0 ? {} : { sessionRef: payload.sessionRef },
10510
+ ...sessionRef === void 0 || known === void 0 && agentBinding === void 0 ? {} : { sessionRef },
10502
10511
  ...agentBinding === void 0 ? {} : {
10503
10512
  agentRef: agentBinding.resolution.agentRef,
10504
10513
  cwd: agentBinding.lease.cwd,
@@ -10601,7 +10610,7 @@ var TaskRunner = class {
10601
10610
  workspaceId,
10602
10611
  taskId,
10603
10612
  workspaceDir,
10604
- sessionRef: payload.sessionRef,
10613
+ sessionRef,
10605
10614
  phase,
10606
10615
  baseline: gitBaseline ?? observation.head,
10607
10616
  current: observation.head,
@@ -13568,7 +13577,13 @@ function computeCapabilities(adapters, agentHomeConfigured = false, agentEgressC
13568
13577
  flags.push("toolset-selection");
13569
13578
  }
13570
13579
  if (agentHomeConfigured) flags.push("agent-home-contract");
13571
- if (agentEgressConfigured) flags.push(AGENT_EGRESS_POLICY_CAPABILITY, AGENT_EGRESS_RELIABLE_ACK_CAPABILITY);
13580
+ if (agentEgressConfigured) {
13581
+ flags.push(
13582
+ AGENT_EGRESS_POLICY_CAPABILITY,
13583
+ AGENT_EGRESS_RELIABLE_ACK_CAPABILITY,
13584
+ AGENT_EGRESS_FRESH_SESSION_CAPABILITY
13585
+ );
13586
+ }
13572
13587
  if (contentReadPolicies !== void 0) {
13573
13588
  for (const surface of Object.keys(AGENT_CONTENT_READ_CAPABILITIES)) {
13574
13589
  const policy = contentReadPolicies[surface];
@@ -14773,7 +14788,7 @@ function buildDaemonWithAdapters(config, adapters, overrides = {}, assertionProb
14773
14788
  connection.send(sanitized.envelope);
14774
14789
  }
14775
14790
  async function publishReliableAgentEgress(input) {
14776
- if (config.agentEgress === void 0 || agentHomeManager === void 0) {
14791
+ if (config.agentEgress === void 0 || agentHomeManager === void 0 || agentSessionHandoffs === void 0) {
14777
14792
  throw new Error("Agent reliable egress is not configured");
14778
14793
  }
14779
14794
  if (tenantRebinding) {
@@ -14782,12 +14797,21 @@ function buildDaemonWithAdapters(config, adapters, overrides = {}, assertionProb
14782
14797
  const binding = await agentHomeManager.acquire(input.agentRef);
14783
14798
  try {
14784
14799
  await agentHomeManager.initialize(binding);
14800
+ const handoff = await agentSessionHandoffs.requireMatch({
14801
+ agentRef: binding.resolution.agentRef,
14802
+ sessionRef: input.sessionRef,
14803
+ runtimeId: input.runtimeId,
14804
+ cwd: binding.resolution.canonicalHome
14805
+ });
14806
+ if (handoff.taskId !== input.taskId) {
14807
+ throw new Error("Agent reliable egress taskId does not match the durable session handoff");
14808
+ }
14785
14809
  const appended = await agentEgress.appendReliable({
14786
14810
  homeDir: binding.resolution.canonicalHome,
14787
14811
  agentRef: binding.resolution.agentRef,
14788
14812
  sessionRef: input.sessionRef,
14789
14813
  payload: input.payload,
14790
- ...input.taskId === void 0 ? {} : { taskId: input.taskId },
14814
+ taskId: input.taskId,
14791
14815
  ...input.eventId === void 0 ? {} : { eventId: input.eventId }
14792
14816
  });
14793
14817
  if (appended.ok) dispatchReliableRecord(appended.record);
@@ -15452,7 +15476,7 @@ function createServiceLifecycle(def, opts = {}) {
15452
15476
 
15453
15477
  // src/bin/official-release.ts
15454
15478
  var OFFICIAL_LOCAL_AGENT_RELEASE = resolveLocalAgentReleaseIdentity({
15455
- version: "0.7.0"
15479
+ version: "0.8.0-beta.0"
15456
15480
  });
15457
15481
 
15458
15482
  // src/bin/config.ts