@byok-sdk/cloud 0.19.0 → 0.21.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.
@@ -73,7 +73,7 @@ export declare const CLOUD_CAPABILITIES: {
73
73
  * DEVICE's only way to discharge a mailbox row this same deployment handed
74
74
  * it — withholding it would strand the device's redelivery cursor rather
75
75
  * than degrade a feature. For the same reason the completion route asserts
76
- * no DEVICE capability either: the device-level `agent-input-preparation`
76
+ * no DEVICE capability either: the device-level `agent-input-preparation-v6`
77
77
  * flag gates ADMISSION (`enqueueInputPreparation`) and nothing else, so an
78
78
  * unconfigured device is refused a row instead of being handed one whose
79
79
  * only honest answer — `input_preparation_unconfigured` — it could not then
package/dist/cloud.d.ts CHANGED
@@ -171,6 +171,8 @@ export interface PreparedDispatchInput {
171
171
  readonly taskId?: string;
172
172
  /** Instruction-free strict payload naming the preparation this Execution consumes. */
173
173
  readonly payload: TaskOfferPreparedPayload;
174
+ /** Host-only destination/freshness authority; never serialized to the daemon. */
175
+ readonly agentMessageContext?: AgentMessageServerContext;
174
176
  }
175
177
  /** Strict Agent dispatch that supplies the policy consumed by the typed egress lanes. */
176
178
  export interface AgentEgressDispatchInput {
@@ -283,7 +285,7 @@ export interface ByokCloud {
283
285
  * Host control plane: enqueue an offer for an already-counted preparation.
284
286
  *
285
287
  * Admission requires the device to durably advertise both the Agent-home
286
- * contract and `agent-input-preparation` — the second because only a device
288
+ * contract and `agent-input-preparation-v6` — the second because only a device
287
289
  * that can prepare holds the durable record this offer names. A device that
288
290
  * advertises neither never receives the message, and a device whose protocol
289
291
  * build predates the type skips it whole rather than running it as an
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { BOARD_STATUSES, CapabilityDeclarationSchema, NONCE_SIGNING_DOMAIN, hasCapability, isTenantId, tenantId, principalTenant, parseDeviceProofEnvelope, deviceProofSigningInput, contentHash, parseCapabilityDeclaration, ByokCoreError, tenantKey, PRESENCE_LEVELS, createInMemoryCoreStores, authenticateDeviceAssertion, authenticateTaskAssertion, assertCapability, isCoreConflictError, isCoreError, DEVICE_PROOF_HEADER, TRUTH_RECORD_KINDS, STORAGE_ERROR_CODES, STORAGE_ERROR_HTTP_STATUS } from '@byok-sdk/core';
2
2
  export { DEVICE_PROOF_HEADER, NONCE_SIGNING_DOMAIN, isTenantId, tenantId } from '@byok-sdk/core';
3
3
  import { z } from 'zod';
4
- import { AgentEventOrUnknownSchema, AgentMessageServerContextSchema, AgentMessageEgressRequirementSchema, AgentRefSchema, TaskOfferForAgentWithEgressFreshPayloadSchema, PROTOCOL_VERSION, DAEMON_TO_SERVER_TYPES, AGENT_EGRESS_RELIABLE_ACK_CAPABILITY, encodeEnvelope, decodeEnvelope, AgentHomeProjectionCompletionRequestSchema, AgentInputPreparationPayloadSchema, InputPreparationCompletionRequestSchema, BYOK_PAIR_PATH, BYOK_CHALLENGE_PATH, BYOK_TOKEN_PATH, BYOK_CAPABILITIES_PATH, BYOK_AGENT_MEMORY_PROJECTIONS_PATH, BYOK_EVENTS_PATH, BYOK_MESSAGES_PATH, BYOK_AGENT_HOME_PROJECTION_COMPLETION_ROUTE, BYOK_INPUT_PREPARATION_COMPLETION_ROUTE, BYOK_INPUT_PREPARATION_STATUS_ROUTE, BYOK_BOARD_PATH, BYOK_BOARD_CLAIM_ROUTE, BYOK_BOARD_UNCLAIM_ROUTE, BYOK_BOARD_STATUS_ROUTE, BYOK_BOARD_STREAM_PATH, BYOK_PRESENCE_PATH, BYOK_ACTIVITY_PATH, BYOK_RECORDS_PATH, BYOK_RECORD_ROUTE, BYOK_SKILL_PACKS_PATH, BYOK_SKILL_PACK_FILE_ROUTE, BYOK_BLOBS_PATH, BYOK_BLOB_FINALIZE_ROUTE, BYOK_BLOB_URL_ROUTE, BYOK_BLOB_CONTENT_ROUTE, AgentMessagePublishPayloadSchema, isTaskOfferType, MESSAGE_PAYLOAD_SCHEMAS, createEnvelope, AgentHomeProjectionPayloadSchema, AgentContentReadPayloadSchema, AGENT_EGRESS_POLICY_CAPABILITY, AGENT_MESSAGE_EGRESS_CAPABILITY, TERMINAL_PROJECTION_SELECTION_CAPABILITY, TaskOfferForAgentWithEgressPayloadSchema, AGENT_INPUT_PREPARATION_CAPABILITY, TaskOfferPreparedPayloadSchema, TaskOfferForAgentPayloadSchema, AgentMemoryProjectionMutationSchema, AgentMemoryProjectionReceiptSchema, AGENT_MEMORY_PROJECTION_MAX_ORDERING_VALUE, AgentMemoryProjectionEraseResultSchema, HarnessIdSchema, STRICT_AGENT_ONLY_CAPABILITY, AGENT_CONTENT_ARTIFACT_READ_CAPABILITY, AGENT_CONTENT_TRANSCRIPT_READ_CAPABILITY, AGENT_CONTENT_WORKSPACE_READ_CAPABILITY, AGENT_HOME_PROJECTION_CAPABILITY, AGENT_EGRESS_FRESH_SESSION_CAPABILITY, PairRequestSchema, PairResponseSchema, ChallengeRequestSchema, TokenRequestSchema, AgentMemoryProjectionCommitRequestSchema, agentMemoryProjectionBase64UrlByteLength, MAILBOX_READ_AHEAD_MAX_SEQS, MAILBOX_READ_AHEAD_CAPABILITY, MessagesSendRequestSchema, InputPreparationStatusQuerySchema, PresencePublishRequestSchema, CreateBlobRequestSchema, byokBlobContentPath, AgentMessageDispositionPayloadSchema, AgentEgressAckPayloadSchema, AgentContentReceiptPayloadSchema } from '@byok-sdk/protocol';
4
+ import { AgentEventOrUnknownSchema, AgentMessageServerContextSchema, AgentMessageEgressRequirementSchema, AgentRefSchema, TaskOfferForAgentWithEgressFreshPayloadSchema, PROTOCOL_VERSION, DAEMON_TO_SERVER_TYPES, AGENT_EGRESS_RELIABLE_ACK_CAPABILITY, encodeEnvelope, decodeEnvelope, AgentHomeProjectionCompletionRequestSchema, AgentInputPreparationPayloadSchema, InputPreparationCompletionRequestSchema, BYOK_PAIR_PATH, BYOK_CHALLENGE_PATH, BYOK_TOKEN_PATH, BYOK_CAPABILITIES_PATH, BYOK_AGENT_MEMORY_PROJECTIONS_PATH, BYOK_EVENTS_PATH, BYOK_MESSAGES_PATH, BYOK_AGENT_HOME_PROJECTION_COMPLETION_ROUTE, BYOK_INPUT_PREPARATION_COMPLETION_ROUTE, BYOK_INPUT_PREPARATION_STATUS_ROUTE, BYOK_BOARD_PATH, BYOK_BOARD_CLAIM_ROUTE, BYOK_BOARD_UNCLAIM_ROUTE, BYOK_BOARD_STATUS_ROUTE, BYOK_BOARD_STREAM_PATH, BYOK_PRESENCE_PATH, BYOK_ACTIVITY_PATH, BYOK_RECORDS_PATH, BYOK_RECORD_ROUTE, BYOK_SKILL_PACKS_PATH, BYOK_SKILL_PACK_FILE_ROUTE, BYOK_BLOBS_PATH, BYOK_BLOB_FINALIZE_ROUTE, BYOK_BLOB_URL_ROUTE, BYOK_BLOB_CONTENT_ROUTE, AgentMessagePublishPayloadSchema, isTaskOfferType, MESSAGE_PAYLOAD_SCHEMAS, createEnvelope, AgentHomeProjectionPayloadSchema, AgentContentReadPayloadSchema, AGENT_EGRESS_POLICY_CAPABILITY, AGENT_MESSAGE_EGRESS_CAPABILITY, TERMINAL_PROJECTION_SELECTION_CAPABILITY, TaskOfferForAgentWithEgressPayloadSchema, AGENT_INPUT_PREPARATION_CAPABILITY, AGENT_EGRESS_FRESH_SESSION_CAPABILITY, TaskOfferPreparedPayloadSchema, TaskOfferForAgentPayloadSchema, AgentMemoryProjectionMutationSchema, AgentMemoryProjectionReceiptSchema, AGENT_MEMORY_PROJECTION_MAX_ORDERING_VALUE, AgentMemoryProjectionEraseResultSchema, HarnessIdSchema, STRICT_AGENT_ONLY_CAPABILITY, AGENT_CONTENT_ARTIFACT_READ_CAPABILITY, AGENT_CONTENT_TRANSCRIPT_READ_CAPABILITY, AGENT_CONTENT_WORKSPACE_READ_CAPABILITY, AGENT_HOME_PROJECTION_CAPABILITY, PairRequestSchema, PairResponseSchema, ChallengeRequestSchema, TokenRequestSchema, AgentMemoryProjectionCommitRequestSchema, agentMemoryProjectionBase64UrlByteLength, MAILBOX_READ_AHEAD_MAX_SEQS, MAILBOX_READ_AHEAD_CAPABILITY, MessagesSendRequestSchema, InputPreparationStatusQuerySchema, PresencePublishRequestSchema, CreateBlobRequestSchema, byokBlobContentPath, AgentMessageDispositionPayloadSchema, AgentEgressAckPayloadSchema, AgentContentReceiptPayloadSchema } from '@byok-sdk/protocol';
5
5
  import { Hono } from 'hono';
6
6
 
7
7
  // src/index.ts
@@ -1217,7 +1217,7 @@ var CLOUD_CAPABILITIES = {
1217
1217
  * DEVICE's only way to discharge a mailbox row this same deployment handed
1218
1218
  * it — withholding it would strand the device's redelivery cursor rather
1219
1219
  * than degrade a feature. For the same reason the completion route asserts
1220
- * no DEVICE capability either: the device-level `agent-input-preparation`
1220
+ * no DEVICE capability either: the device-level `agent-input-preparation-v6`
1221
1221
  * flag gates ADMISSION (`enqueueInputPreparation`) and nothing else, so an
1222
1222
  * unconfigured device is refused a row instead of being handed one whose
1223
1223
  * only honest answer — `input_preparation_unconfigured` — it could not then
@@ -2966,6 +2966,7 @@ function projectTerminalResult(taskId, receipt) {
2966
2966
  ...envelope.payload.document !== void 0 ? { document: envelope.payload.document } : {},
2967
2967
  ...envelope.payload.harnessId === void 0 ? {} : { harnessId: envelope.payload.harnessId },
2968
2968
  ...envelope.payload.usage !== void 0 ? { usage: envelope.payload.usage } : {},
2969
+ ...envelope.payload.preparedObservation === void 0 ? {} : { preparedObservation: envelope.payload.preparedObservation },
2969
2970
  recordedAt: receipt.recordedAt
2970
2971
  };
2971
2972
  case "task.fail":
@@ -2979,6 +2980,7 @@ function projectTerminalResult(taskId, receipt) {
2979
2980
  ...envelope.payload.retryable !== void 0 ? { retryable: envelope.payload.retryable } : {},
2980
2981
  ...envelope.payload.harnessId === void 0 ? {} : { harnessId: envelope.payload.harnessId },
2981
2982
  ...envelope.payload.usage !== void 0 ? { usage: envelope.payload.usage } : {},
2983
+ ...envelope.payload.preparedObservation === void 0 ? {} : { preparedObservation: envelope.payload.preparedObservation },
2982
2984
  recordedAt: receipt.recordedAt
2983
2985
  };
2984
2986
  // `task.decline` is the pre-claim terminal (§3.2, `Offered -> Failed`).
@@ -3788,6 +3790,25 @@ function createByokCloud(options) {
3788
3790
  throw new ByokCloudError("mailbox_receipt_mismatch", "Agent message disposition mailbox readback mismatched.");
3789
3791
  }
3790
3792
  }
3793
+ function agentMessageOfferWriter(deviceId, payload, context) {
3794
+ if (payload.messageEgress === void 0) {
3795
+ if (context !== void 0) throw new Error("agentMessageContext requires messageEgress");
3796
+ return void 0;
3797
+ }
3798
+ const messageContext = AgentMessageServerContextSchema.parse(context);
3799
+ const body = JSON.stringify({
3800
+ agentRef: payload.agentRef,
3801
+ ...payload.sessionRef === void 0 ? {} : { sessionRef: payload.sessionRef },
3802
+ requirement: payload.messageEgress,
3803
+ context: messageContext
3804
+ });
3805
+ return async (stores, taskId) => {
3806
+ const recorded = await stores.receipts.record({ key: `agent-message-offer:${deviceId}:${taskId}`, body });
3807
+ if (!recorded.created && recorded.receipt.body !== body) {
3808
+ throw new ByokCloudError("agent_content_request_mismatch", `Task ${taskId} already has a different Agent message context.`);
3809
+ }
3810
+ };
3811
+ }
3791
3812
  async function enqueueFreshAgentEgressOffer(tenant, deviceId, input) {
3792
3813
  await assertAgentCapabilities(tenant, deviceId, [
3793
3814
  AGENT_HOME_CONTRACT_CAPABILITY,
@@ -3798,23 +3819,13 @@ function createByokCloud(options) {
3798
3819
  ...input.payload.terminalProjection === void 0 ? [] : [TERMINAL_PROJECTION_SELECTION_CAPABILITY]
3799
3820
  ]);
3800
3821
  const payload = TaskOfferForAgentWithEgressFreshPayloadSchema.parse(input.payload);
3801
- if (payload.messageEgress === void 0 && input.agentMessageContext !== void 0) {
3802
- throw new Error("agentMessageContext requires messageEgress");
3803
- }
3804
- const messageContext = payload.messageEgress === void 0 ? void 0 : AgentMessageServerContextSchema.parse(input.agentMessageContext);
3805
3822
  const enqueued = await enqueueTaskEnvelope(
3806
3823
  tenant,
3807
3824
  deviceId,
3808
3825
  input.taskId,
3809
3826
  payload.agentRef,
3810
3827
  (taskId, seq, messageId) => createEnvelope("task.offer_for_agent_with_egress_fresh", payload, { id: messageId, taskId, seq }),
3811
- payload.messageEgress === void 0 ? void 0 : async (stores, taskId) => {
3812
- const body = JSON.stringify({ agentRef: payload.agentRef, requirement: payload.messageEgress, context: messageContext });
3813
- const recorded = await stores.receipts.record({ key: `agent-message-offer:${deviceId}:${taskId}`, body });
3814
- if (!recorded.created && recorded.receipt.body !== body) {
3815
- throw new ByokCloudError("agent_content_request_mismatch", `Task ${taskId} already has a different Agent message context.`);
3816
- }
3817
- }
3828
+ agentMessageOfferWriter(deviceId, payload, input.agentMessageContext)
3818
3829
  );
3819
3830
  return enqueued;
3820
3831
  }
@@ -3864,6 +3875,10 @@ function createByokCloud(options) {
3864
3875
  await assertAgentCapabilities(tenant, deviceId, [
3865
3876
  AGENT_HOME_CONTRACT_CAPABILITY,
3866
3877
  AGENT_INPUT_PREPARATION_CAPABILITY,
3878
+ AGENT_EGRESS_POLICY_CAPABILITY,
3879
+ AGENT_EGRESS_RELIABLE_ACK_CAPABILITY,
3880
+ AGENT_EGRESS_FRESH_SESSION_CAPABILITY,
3881
+ ...input.payload.messageEgress === void 0 ? [] : [AGENT_MESSAGE_EGRESS_CAPABILITY],
3867
3882
  ...input.payload.terminalProjection === void 0 ? [] : [TERMINAL_PROJECTION_SELECTION_CAPABILITY]
3868
3883
  ]);
3869
3884
  const payload = TaskOfferPreparedPayloadSchema.parse(input.payload);
@@ -3872,7 +3887,8 @@ function createByokCloud(options) {
3872
3887
  deviceId,
3873
3888
  input.taskId,
3874
3889
  payload.agentRef,
3875
- (taskId, seq, messageId) => createEnvelope("task.offer_prepared", payload, { id: messageId, taskId, seq })
3890
+ (taskId, seq, messageId) => createEnvelope("task.offer_prepared", payload, { id: messageId, taskId, seq }),
3891
+ agentMessageOfferWriter(deviceId, payload, input.agentMessageContext)
3876
3892
  );
3877
3893
  },
3878
3894
  async enqueueAgentEgressOffer(tenant, deviceId, input) {
@@ -3884,23 +3900,13 @@ function createByokCloud(options) {
3884
3900
  ...input.payload.terminalProjection === void 0 ? [] : [TERMINAL_PROJECTION_SELECTION_CAPABILITY]
3885
3901
  ]);
3886
3902
  const payload = TaskOfferForAgentWithEgressPayloadSchema.parse(input.payload);
3887
- if (payload.messageEgress === void 0 && input.agentMessageContext !== void 0) {
3888
- throw new Error("agentMessageContext requires messageEgress");
3889
- }
3890
- const messageContext = payload.messageEgress === void 0 ? void 0 : AgentMessageServerContextSchema.parse(input.agentMessageContext);
3891
3903
  const enqueued = await enqueueTaskEnvelope(
3892
3904
  tenant,
3893
3905
  deviceId,
3894
3906
  input.taskId,
3895
3907
  payload.agentRef,
3896
3908
  (taskId, seq, messageId) => createEnvelope("task.offer_for_agent_with_egress", payload, { id: messageId, taskId, seq }),
3897
- payload.messageEgress === void 0 ? void 0 : async (stores, taskId) => {
3898
- const body = JSON.stringify({ agentRef: payload.agentRef, sessionRef: payload.sessionRef, requirement: payload.messageEgress, context: messageContext });
3899
- const recorded = await stores.receipts.record({ key: `agent-message-offer:${deviceId}:${taskId}`, body });
3900
- if (!recorded.created && recorded.receipt.body !== body) {
3901
- throw new ByokCloudError("agent_content_request_mismatch", `Task ${taskId} already has a different Agent message context.`);
3902
- }
3903
- }
3909
+ agentMessageOfferWriter(deviceId, payload, input.agentMessageContext)
3904
3910
  );
3905
3911
  return enqueued;
3906
3912
  },