@byok-sdk/protocol 0.5.0 → 0.6.1

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
@@ -6,14 +6,16 @@ export { PermissionPolicySchema, PERMISSION_MODES } from './permission';
6
6
  export type { PermissionPolicy, PermissionMode } from './permission';
7
7
  export { AgentEventSchema, UnknownAgentEventSchema, AgentEventOrUnknownSchema, KNOWN_AGENT_EVENT_TYPES, isKnownAgentEvent, partitionAgentEvents, } from './agent-event';
8
8
  export type { AgentEvent, UnknownAgentEvent, AgentEventOrUnknown } from './agent-event';
9
+ export { AgentEgressPolicySchema, AgentEgressActivityPolicySchema, AgentReliableQuotaPolicySchema, ContentReadPolicySchema, AgentEgressLaneSchema, AgentEgressDropReasonSchema, AgentContentReadSurfaceSchema, AgentContentActorKindSchema, AgentContentActorSchema, AgentContentDecodeAsSchema, AgentContentMimeTypeSchema, AgentContentReadDecisionSchema, AgentContentReadDenialReasonSchema, AgentEgressContentHashSchema, AgentEgressPolicyRevisionSchema, AGENT_EGRESS_POLICY_CAPABILITY, AGENT_EGRESS_RELIABLE_ACK_CAPABILITY, AGENT_CONTENT_WORKSPACE_READ_CAPABILITY, AGENT_CONTENT_TRANSCRIPT_READ_CAPABILITY, AGENT_CONTENT_ARTIFACT_READ_CAPABILITY, } from './agent-egress';
10
+ export type { AgentEgressPolicy, AgentEgressActivityPolicy, AgentReliableQuotaPolicy, ContentReadPolicy, AgentEgressLane, AgentEgressDropReason, AgentContentReadSurface, AgentContentActorKind, AgentContentActor, AgentContentDecodeAs, AgentContentReadDecision, AgentContentReadDenialReason, } from './agent-egress';
9
11
  export { TASK_STATES, TASK_TRANSITIONS, canTransition } from './task-state';
10
12
  export type { TaskState } from './task-state';
11
- export { MESSAGE_TYPES, MESSAGE_PAYLOAD_SCHEMAS, SERVER_TO_DAEMON_TYPES, DAEMON_TO_SERVER_TYPES, RuntimeIdSchema, RuntimeInfoSchema, RuntimeCapabilitiesSchema, DispatchSelectionSchema, ToolsetIdSchema, ConfiguredToolsetsSchema, RequiredToolsetsSchema, CONFIGURED_TOOLSETS_MAX_ITEMS, ConnHelloPayloadSchema, ConnAckPayloadSchema, TaskOfferPayloadSchema, TaskOfferWithToolsetsPayloadSchema, TaskApprovePayloadSchema, TaskRejectPayloadSchema, TaskCancelPayloadSchema, TaskSteerPayloadSchema, TaskClaimPayloadSchema, TaskStartedPayloadSchema, TaskDeclinePayloadSchema, TaskProgressPayloadSchema, TaskArtifactPayloadSchema, TaskAwaitApprovalPayloadSchema, TaskCompletePayloadSchema, TaskFailPayloadSchema, TaskCancelledPayloadSchema, TaskApprovalResolvedPayloadSchema, RESULT_DOCUMENT_MAX_BYTES, checkResultDocument, } from './messages';
12
- export type { ResultDocumentCheck, MessageType, RuntimeId, RuntimeInfo, RuntimeCapabilities, DispatchSelection, ToolsetId, ConnHelloPayload, ConnAckPayload, TaskOfferPayload, TaskOfferWithToolsetsPayload, TaskApprovePayload, TaskRejectPayload, TaskCancelPayload, TaskSteerPayload, TaskClaimPayload, TaskStartedPayload, TaskDeclinePayload, TaskProgressPayload, TaskArtifactPayload, TaskAwaitApprovalPayload, TaskCompletePayload, TaskFailPayload, TaskCancelledPayload, TaskApprovalResolvedPayload, } from './messages';
13
+ export { MESSAGE_TYPES, MESSAGE_PAYLOAD_SCHEMAS, SERVER_TO_DAEMON_TYPES, DAEMON_TO_SERVER_TYPES, RuntimeIdSchema, ProtocolVersionNumberSchema, RuntimeInfoSchema, RuntimeCapabilitiesSchema, AgentRefSchema, AGENT_REF_MAX_BYTES, DispatchSelectionSchema, ToolsetIdSchema, ConfiguredToolsetsSchema, RequiredToolsetsSchema, CONFIGURED_TOOLSETS_MAX_ITEMS, ConnHelloPayloadSchema, ConnAckPayloadSchema, TaskOfferPayloadSchema, TaskOfferWithToolsetsPayloadSchema, TaskOfferForAgentPayloadSchema, TaskOfferForAgentWithEgressPayloadSchema, AgentEgressReliablePayloadSchema, AgentEgressAckPayloadSchema, AgentContentReadPayloadSchema, AgentContentReceiptPayloadSchema, TaskApprovePayloadSchema, TaskRejectPayloadSchema, TaskCancelPayloadSchema, TaskSteerPayloadSchema, TaskClaimPayloadSchema, TaskStartedPayloadSchema, TaskDeclinePayloadSchema, TaskProgressPayloadSchema, TaskArtifactPayloadSchema, TaskAwaitApprovalPayloadSchema, TaskCompletePayloadSchema, TaskFailPayloadSchema, TaskCancelledPayloadSchema, TaskApprovalResolvedPayloadSchema, RESULT_DOCUMENT_MAX_BYTES, checkResultDocument, TerminalInferenceUsageSchema, TERMINAL_INFERENCE_USAGE_MAX_TOKENS, TERMINAL_INFERENCE_USAGE_MAX_DURATION_MS, TERMINAL_INFERENCE_USAGE_PROVIDER_MAX_LENGTH, TERMINAL_INFERENCE_USAGE_MODEL_MAX_LENGTH, TERMINAL_INFERENCE_USAGE_CLIENT_VERSION_MAX_LENGTH, } from './messages';
14
+ export type { ResultDocumentCheck, MessageType, RuntimeId, RuntimeInfo, RuntimeCapabilities, AgentRef, DispatchSelection, ToolsetId, ConnHelloPayload, ConnAckPayload, TaskOfferPayload, TaskOfferWithToolsetsPayload, TaskOfferForAgentPayload, TaskOfferForAgentWithEgressPayload, AgentEgressReliablePayload, AgentEgressAckPayload, AgentContentReadPayload, AgentContentReceiptPayload, TaskApprovePayload, TaskRejectPayload, TaskCancelPayload, TaskSteerPayload, TaskClaimPayload, TaskStartedPayload, TaskDeclinePayload, TaskProgressPayload, TaskArtifactPayload, TaskAwaitApprovalPayload, TaskCompletePayload, TaskFailPayload, TaskCancelledPayload, TaskApprovalResolvedPayload, TerminalInferenceUsage, } from './messages';
13
15
  export { EnvelopeSchema, isServerToDaemonType } from './envelope';
14
16
  export type { Envelope } from './envelope';
15
17
  export { ProtocolError, EnvelopeParseError, UnknownMessageTypeError, EnvelopeValidationError, } from './errors';
16
18
  export { encodeEnvelope, decodeEnvelope, createEnvelope, parseMessage } from './codec';
17
19
  export type { CreateEnvelopeOptions } from './codec';
18
- export { PairRequestSchema, PairResponseSchema, ChallengeRequestSchema, ChallengeResponseSchema, TokenRequestSchema, TokenResponseSchema, CreateBlobRequestSchema, CreateBlobResponseSchema, BlobDownloadUrlResponseSchema, EventsPollQuerySchema, EventsPollResponseSchema, MessagesSendRequestSchema, MessagesSendResponseSchema, MAX_MESSAGES_PER_BATCH, BYOK_WS_PATH, BYOK_PAIR_PATH, BYOK_CHALLENGE_PATH, BYOK_TOKEN_PATH, BYOK_CAPABILITIES_PATH, BYOK_EVENTS_PATH, BYOK_MESSAGES_PATH, BYOK_PRESENCE_PATH, BYOK_ACTIVITY_PATH, BYOK_BOARD_PATH, BYOK_BOARD_STREAM_PATH, BYOK_BOARD_CLAIM_ROUTE, BYOK_BOARD_UNCLAIM_ROUTE, BYOK_BOARD_STATUS_ROUTE, BYOK_RECORDS_PATH, BYOK_RECORD_ROUTE, byokRecordPath, BYOK_SKILL_PACKS_PATH, BYOK_SKILL_PACK_FILE_ROUTE, byokSkillPackFilePath, BYOK_BLOBS_PATH, BYOK_BLOB_FINALIZE_ROUTE, BYOK_BLOB_URL_ROUTE, BYOK_BLOB_CONTENT_ROUTE, byokBlobFinalizePath, byokBlobUrlPath, byokBlobContentPath, } from './http-api';
19
- export type { PairRequest, PairResponse, ChallengeRequest, ChallengeResponse, TokenRequest, TokenResponse, CreateBlobRequest, CreateBlobResponse, BlobDownloadUrlResponse, EventsPollQuery, EventsPollResponse, MessagesSendRequest, MessagesSendResponse, } from './http-api';
20
+ export { PairRequestSchema, PairResponseSchema, ChallengeRequestSchema, ChallengeResponseSchema, TokenRequestSchema, TokenResponseSchema, PresencePublishRequestSchema, CreateBlobRequestSchema, CreateBlobResponseSchema, BlobDownloadUrlResponseSchema, EventsPollQuerySchema, EventsPollResponseSchema, MessagesSendRequestSchema, MessagesSendResponseSchema, MAX_MESSAGES_PER_BATCH, BYOK_WS_PATH, BYOK_PAIR_PATH, BYOK_CHALLENGE_PATH, BYOK_TOKEN_PATH, BYOK_CAPABILITIES_PATH, BYOK_EVENTS_PATH, BYOK_MESSAGES_PATH, BYOK_PRESENCE_PATH, BYOK_ACTIVITY_PATH, BYOK_BOARD_PATH, BYOK_BOARD_STREAM_PATH, BYOK_BOARD_CLAIM_ROUTE, BYOK_BOARD_UNCLAIM_ROUTE, BYOK_BOARD_STATUS_ROUTE, BYOK_RECORDS_PATH, BYOK_RECORD_ROUTE, byokRecordPath, BYOK_SKILL_PACKS_PATH, BYOK_SKILL_PACK_FILE_ROUTE, byokSkillPackFilePath, BYOK_BLOBS_PATH, BYOK_BLOB_FINALIZE_ROUTE, BYOK_BLOB_URL_ROUTE, BYOK_BLOB_CONTENT_ROUTE, byokBlobFinalizePath, byokBlobUrlPath, byokBlobContentPath, } from './http-api';
21
+ export type { PairRequest, PairResponse, ChallengeRequest, ChallengeResponse, TokenRequest, TokenResponse, PresencePublishRequest, CreateBlobRequest, CreateBlobResponse, BlobDownloadUrlResponse, EventsPollQuery, EventsPollResponse, MessagesSendRequest, MessagesSendResponse, } from './http-api';
package/dist/index.js CHANGED
@@ -1,5 +1,89 @@
1
1
  import { z } from 'zod';
2
2
 
3
+ // src/agent-egress.ts
4
+ var AGENT_EGRESS_POLICY_CAPABILITY = "agent-egress-policy";
5
+ var AGENT_EGRESS_RELIABLE_ACK_CAPABILITY = "agent-egress-reliable-ack";
6
+ var AGENT_CONTENT_WORKSPACE_READ_CAPABILITY = "agent-content-workspace-read";
7
+ var AGENT_CONTENT_TRANSCRIPT_READ_CAPABILITY = "agent-content-transcript-read";
8
+ var AGENT_CONTENT_ARTIFACT_READ_CAPABILITY = "agent-content-artifact-read";
9
+ var POLICY_REVISION = z.string().min(1).max(160).regex(/^[^\u0000-\u001f\u007f\r\n]+$/u, "policyRevision must not contain control characters");
10
+ var POSITIVE_LIMIT = z.number().int().positive().max(2147483647);
11
+ var AgentContentMimeTypeSchema = z.string().min(3).max(255).regex(/^[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+$/iu, "MIME types must be explicit type/subtype values");
12
+ var ContentReadPolicySchema = z.object({
13
+ maxBytes: POSITIVE_LIMIT,
14
+ allowedMimeTypes: z.array(AgentContentMimeTypeSchema).min(1).max(32)
15
+ }).strict();
16
+ var AgentEgressActivityPolicySchema = z.discriminatedUnion("mode", [
17
+ z.object({
18
+ mode: z.literal("metadata-status"),
19
+ delivery: z.literal("latest-value")
20
+ }).strict(),
21
+ z.object({
22
+ mode: z.literal("contentful-trajectory"),
23
+ delivery: z.literal("latest-value"),
24
+ maxCoalesceMs: POSITIVE_LIMIT,
25
+ maxEventBytes: POSITIVE_LIMIT
26
+ }).strict()
27
+ ]);
28
+ var AgentReliableQuotaPolicySchema = z.object({
29
+ maxPendingEventsPerAgent: POSITIVE_LIMIT,
30
+ maxPendingBytesPerAgent: POSITIVE_LIMIT,
31
+ maxPendingBytesPerTenant: POSITIVE_LIMIT
32
+ }).strict();
33
+ var AgentEgressPolicySchema = z.object({
34
+ policyRevision: POLICY_REVISION,
35
+ activity: AgentEgressActivityPolicySchema,
36
+ reliable: AgentReliableQuotaPolicySchema,
37
+ transfers: z.object({
38
+ workspace: z.union([z.literal("disabled"), ContentReadPolicySchema]),
39
+ transcript: z.union([z.literal("disabled"), ContentReadPolicySchema]),
40
+ artifact: z.union([z.literal("disabled"), ContentReadPolicySchema])
41
+ }).strict()
42
+ }).strict();
43
+ var AgentEgressLaneSchema = z.enum(["reliable", "latest-value"]);
44
+ var AgentEgressDropReasonSchema = z.enum([
45
+ "policy_denied",
46
+ "capability_missing",
47
+ "sanitizer_rejected",
48
+ "quota_exceeded",
49
+ "backpressure",
50
+ "coalesced",
51
+ "disconnected",
52
+ "invalid_envelope",
53
+ "ack_mismatch"
54
+ ]);
55
+ var AgentContentReadSurfaceSchema = z.enum(["workspace", "transcript", "artifact"]);
56
+ var AgentContentActorKindSchema = z.enum(["user", "agent", "system"]);
57
+ var AgentContentActorSchema = z.object({
58
+ kind: AgentContentActorKindSchema,
59
+ id: z.string().min(1).max(512).regex(/^[^\u0000-\u001f\u007f]+$/u, "actor id must not contain control characters")
60
+ }).strict();
61
+ var AgentContentDecodeAsSchema = z.enum(["bytes", "utf8"]);
62
+ var AgentContentReadDecisionSchema = z.enum(["allowed", "denied"]);
63
+ var AgentContentReadDenialReasonSchema = z.enum([
64
+ "invalid-request",
65
+ "policy-disabled",
66
+ "capability-missing",
67
+ "policy-revision-mismatch",
68
+ "absolute-target",
69
+ "non-relative-target",
70
+ "dot-segment",
71
+ "sensitive-name",
72
+ "root-not-allowlisted",
73
+ "root-invalid",
74
+ "path-escape",
75
+ "target-missing",
76
+ "symlink",
77
+ "not-regular-file",
78
+ "byte-limit",
79
+ "mime-not-allowlisted",
80
+ "text-not-allowlisted",
81
+ "text-decode-failed",
82
+ "identity-mismatch"
83
+ ]);
84
+ var AgentEgressContentHashSchema = z.string().regex(/^sha256:[a-f0-9]{64}$/u, "contentHash must be a lowercase SHA-256 digest");
85
+ var AgentEgressPolicyRevisionSchema = POLICY_REVISION;
86
+
3
87
  // src/version.ts
4
88
  var PROTOCOL_VERSION = 1;
5
89
  var CAPABILITY_FLAGS = [
@@ -10,7 +94,13 @@ var CAPABILITY_FLAGS = [
10
94
  "approval-targeting",
11
95
  "result-document",
12
96
  "dispatch-selection",
13
- "toolset-selection"
97
+ "toolset-selection",
98
+ "agent-home-contract",
99
+ AGENT_EGRESS_POLICY_CAPABILITY,
100
+ AGENT_EGRESS_RELIABLE_ACK_CAPABILITY,
101
+ AGENT_CONTENT_WORKSPACE_READ_CAPABILITY,
102
+ AGENT_CONTENT_TRANSCRIPT_READ_CAPABILITY,
103
+ AGENT_CONTENT_ARTIFACT_READ_CAPABILITY
14
104
  ];
15
105
  var CONTENT_HASH_RE = /^sha256:[0-9a-f]{64}$/;
16
106
  var BlobRefSchema = z.object({
@@ -111,6 +201,7 @@ function isWithinInlineByteLimit(value) {
111
201
  return new TextEncoder().encode(value).length <= MAX_INLINE_BYTES;
112
202
  }
113
203
  var RuntimeIdSchema = z.enum(["pi", "claude", "codex"]);
204
+ var ProtocolVersionNumberSchema = z.number().int().nonnegative().max(2147483647);
114
205
  var RuntimeCapabilitiesSchema = z.object({
115
206
  steer: z.boolean().optional(),
116
207
  resume: z.boolean().optional(),
@@ -128,6 +219,21 @@ var RuntimeInfoSchema = z.object({
128
219
  });
129
220
  var CONFIGURED_TOOLSETS_MAX_ITEMS = 64;
130
221
  var ToolsetIdSchema = z.string().min(1).max(128).regex(/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/u, "toolset ids must be lowercase logical identifiers");
222
+ var AGENT_REF_MAX_BYTES = 160;
223
+ var AGENT_REF_VALUE = z.string().min(1).max(AGENT_REF_MAX_BYTES).refine((value) => new TextEncoder().encode(value).byteLength <= AGENT_REF_MAX_BYTES, {
224
+ message: `AgentRef values must not exceed ${AGENT_REF_MAX_BYTES} UTF-8 bytes`
225
+ }).regex(/^[^\u0000-\u001f\u007f\r\n]+$/u, "AgentRef values must not contain control characters");
226
+ var WINDOWS_RESERVED_AGENT_SEGMENT = /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\..*)?$/iu;
227
+ var AgentRefSchema = z.object({
228
+ agentId: AGENT_REF_VALUE.regex(/^[^\\/:<>"|?*]+$/u, "agentId must be one portable pathname segment").refine(
229
+ (value) => value !== "." && value !== "..",
230
+ "agentId must not be a dot segment"
231
+ ).refine(
232
+ (value) => !/[. ]$/u.test(value) && !WINDOWS_RESERVED_AGENT_SEGMENT.test(value),
233
+ "agentId must be a portable Windows-safe pathname segment"
234
+ ),
235
+ profileRevision: AGENT_REF_VALUE
236
+ }).strict();
131
237
  function rejectDuplicateToolsets(ids, ctx, label) {
132
238
  const seen = /* @__PURE__ */ new Set();
133
239
  for (const [index, id] of ids.entries()) {
@@ -139,10 +245,12 @@ function rejectDuplicateToolsets(ids, ctx, label) {
139
245
  }
140
246
  var ConfiguredToolsetsSchema = z.array(ToolsetIdSchema).max(CONFIGURED_TOOLSETS_MAX_ITEMS).superRefine((ids, ctx) => rejectDuplicateToolsets(ids, ctx, "configured"));
141
247
  var ConnHelloPayloadSchema = z.object({
142
- protocolVersions: z.array(z.number().int()),
248
+ protocolVersions: z.array(ProtocolVersionNumberSchema).max(16),
143
249
  capabilities: z.array(z.string()),
144
250
  deviceId: z.string(),
145
251
  productId: z.string(),
252
+ /** U4a Local Agent release identity; this is the sole client-version authority. */
253
+ clientVersion: z.string().min(1).max(128).optional(),
146
254
  /** Runtimes detected on this device (M1 gap #4; replaces `agents`). */
147
255
  runtimes: z.array(RuntimeInfoSchema).optional(),
148
256
  /** Validated logical IDs configured on this device; definitions and secrets stay local. */
@@ -192,6 +300,117 @@ var RequiredToolsetsSchema = z.array(ToolsetIdSchema).min(1).max(16).superRefine
192
300
  var TaskOfferWithToolsetsPayloadSchema = TaskOfferPayloadSchema.extend({
193
301
  requiredToolsets: RequiredToolsetsSchema
194
302
  }).strict();
303
+ var TaskOfferForAgentPayloadSchema = z.object({
304
+ instruction: z.union([z.string(), InstructionBlobRefSchema]),
305
+ policy: PermissionPolicySchema,
306
+ agentRef: AgentRefSchema,
307
+ requiredToolsets: RequiredToolsetsSchema.optional(),
308
+ runtime: RuntimeIdSchema.optional(),
309
+ dispatchSelection: DispatchSelectionSchema.optional(),
310
+ sessionRef: z.string().optional(),
311
+ limits: z.object({
312
+ maxDurationMs: z.number().int().positive().optional(),
313
+ maxTokens: z.number().int().positive().optional()
314
+ }).optional()
315
+ }).strict();
316
+ var TaskOfferForAgentWithEgressPayloadSchema = TaskOfferForAgentPayloadSchema.extend({
317
+ sessionRef: z.string().min(1).max(512),
318
+ egressPolicy: AgentEgressPolicySchema
319
+ }).strict();
320
+ var EGRESS_SAFE_VALUE = z.json().refine(
321
+ (value) => new TextEncoder().encode(JSON.stringify(value)).byteLength <= 256 * 1024,
322
+ "sanitized egress payload exceeds 256KiB"
323
+ );
324
+ var EGRESS_SESSION_REF = z.string().min(1).max(512);
325
+ var AgentEgressReliablePayloadSchema = z.object({
326
+ agentRef: AgentRefSchema,
327
+ sessionRef: EGRESS_SESSION_REF,
328
+ policyRevision: AgentEgressPolicyRevisionSchema,
329
+ eventId: z.uuid(),
330
+ cursor: z.number().int().positive(),
331
+ payload: EGRESS_SAFE_VALUE,
332
+ contentHash: AgentEgressContentHashSchema,
333
+ byteCount: z.number().int().nonnegative().max(256 * 1024)
334
+ }).strict();
335
+ var AgentEgressAckPayloadSchema = z.object({
336
+ agentRef: AgentRefSchema,
337
+ sessionRef: EGRESS_SESSION_REF,
338
+ policyRevision: AgentEgressPolicyRevisionSchema,
339
+ eventId: z.uuid(),
340
+ cursor: z.number().int().positive(),
341
+ receiptId: z.uuid()
342
+ }).strict();
343
+ var AGENT_CONTENT_TARGET = z.string().min(1).max(1024).regex(/^[^\u0000-\u001f\u007f]+$/u, "content target must not contain control characters").refine(
344
+ (value) => !value.startsWith("/") && !value.includes("\\") && value.split("/").every((segment) => segment.length > 0 && segment !== "." && segment !== ".."),
345
+ "content target must be a portable relative path without dot segments"
346
+ );
347
+ var AGENT_CONTENT_CWD = z.string().min(1).max(4096).regex(/^[^\u0000-\u001f\u007f]+$/u, "cwd must not contain control characters").regex(/^(?:\/|[A-Za-z]:[\\/])/u, "cwd must be absolute");
348
+ var AgentContentReadPayloadSchema = z.object({
349
+ requestId: z.uuid(),
350
+ surface: AgentContentReadSurfaceSchema,
351
+ actor: AgentContentActorSchema,
352
+ agentRef: AgentRefSchema,
353
+ sessionRef: EGRESS_SESSION_REF,
354
+ runtime: RuntimeIdSchema,
355
+ cwd: AGENT_CONTENT_CWD,
356
+ policyRevision: AgentEgressPolicyRevisionSchema,
357
+ target: AGENT_CONTENT_TARGET,
358
+ mimeType: AgentContentMimeTypeSchema,
359
+ decodeAs: AgentContentDecodeAsSchema,
360
+ policy: ContentReadPolicySchema
361
+ }).strict();
362
+ var AgentContentReceiptPayloadSchema = z.discriminatedUnion("decision", [
363
+ z.object({
364
+ requestId: z.uuid(),
365
+ /** Stable reliable-delivery identity. Content receipts use their requestId. */
366
+ eventId: z.uuid(),
367
+ /** Stable positive cursor allocated by the durable Agent spool. */
368
+ cursor: z.number().int().positive(),
369
+ surface: AgentContentReadSurfaceSchema,
370
+ actor: AgentContentActorSchema,
371
+ agentRef: AgentRefSchema,
372
+ sessionRef: EGRESS_SESSION_REF,
373
+ runtime: RuntimeIdSchema,
374
+ cwd: AGENT_CONTENT_CWD,
375
+ policyRevision: AgentEgressPolicyRevisionSchema,
376
+ target: AGENT_CONTENT_TARGET,
377
+ mimeType: AgentContentMimeTypeSchema,
378
+ decodeAs: AgentContentDecodeAsSchema,
379
+ decision: z.literal("allowed"),
380
+ byteCount: z.number().int().nonnegative(),
381
+ contentHash: AgentEgressContentHashSchema,
382
+ blobRef: BlobRefSchema
383
+ }).strict(),
384
+ z.object({
385
+ requestId: z.uuid(),
386
+ eventId: z.uuid(),
387
+ cursor: z.number().int().positive(),
388
+ surface: AgentContentReadSurfaceSchema,
389
+ actor: AgentContentActorSchema,
390
+ agentRef: AgentRefSchema,
391
+ sessionRef: EGRESS_SESSION_REF,
392
+ runtime: RuntimeIdSchema,
393
+ cwd: AGENT_CONTENT_CWD,
394
+ policyRevision: AgentEgressPolicyRevisionSchema,
395
+ target: AGENT_CONTENT_TARGET,
396
+ mimeType: AgentContentMimeTypeSchema,
397
+ decodeAs: AgentContentDecodeAsSchema,
398
+ decision: z.literal("denied"),
399
+ byteCount: z.literal(0),
400
+ reason: AgentContentReadDenialReasonSchema
401
+ }).strict()
402
+ ]).superRefine((value, ctx) => {
403
+ if (value.decision !== "allowed") return;
404
+ if (value.blobRef.size !== value.byteCount) {
405
+ ctx.addIssue({ code: "custom", path: ["blobRef", "size"], message: "blobRef size must equal byteCount" });
406
+ }
407
+ if (value.blobRef.contentHash !== value.contentHash) {
408
+ ctx.addIssue({ code: "custom", path: ["blobRef", "contentHash"], message: "blobRef contentHash must equal contentHash" });
409
+ }
410
+ if (value.blobRef.contentType !== value.mimeType) {
411
+ ctx.addIssue({ code: "custom", path: ["blobRef", "contentType"], message: "blobRef contentType must equal mimeType" });
412
+ }
413
+ });
195
414
  var TaskApprovePayloadSchema = z.object({
196
415
  approvalId: z.string().optional()
197
416
  });
@@ -208,13 +427,15 @@ var TaskSteerPayloadSchema = z.object({
208
427
  var TaskClaimPayloadSchema = z.object({
209
428
  deviceId: z.string(),
210
429
  agentId: z.string().optional(),
430
+ agentRef: AgentRefSchema.optional(),
211
431
  runtime: RuntimeIdSchema.optional(),
212
432
  capabilities: RuntimeCapabilitiesSchema.optional()
213
433
  });
214
434
  var TaskStartedPayloadSchema = z.object({});
215
435
  var TaskDeclinePayloadSchema = z.object({
216
436
  reason: z.string(),
217
- retryable: z.boolean().optional()
437
+ retryable: z.boolean().optional(),
438
+ agentRef: AgentRefSchema.optional()
218
439
  });
219
440
  var TaskProgressPayloadSchema = z.object({
220
441
  seq: z.number().int(),
@@ -280,20 +501,52 @@ function checkResultDocument(document) {
280
501
  if (!isSameJsonData(document, canonical)) return { ok: false, reason: "not-plain-json" };
281
502
  return { ok: true, bytes, canonical };
282
503
  }
504
+ var TERMINAL_INFERENCE_USAGE_MAX_TOKENS = 1e9;
505
+ var TERMINAL_INFERENCE_USAGE_MAX_DURATION_MS = 6048e5;
506
+ var TERMINAL_INFERENCE_USAGE_PROVIDER_MAX_LENGTH = 160;
507
+ var TERMINAL_INFERENCE_USAGE_MODEL_MAX_LENGTH = 160;
508
+ var TERMINAL_INFERENCE_USAGE_CLIENT_VERSION_MAX_LENGTH = 128;
509
+ var TerminalInferenceUsageNumberSchema = z.number().int().safe().nonnegative().max(TERMINAL_INFERENCE_USAGE_MAX_TOKENS);
510
+ var TerminalInferenceUsageDurationSchema = z.number().int().safe().nonnegative().max(TERMINAL_INFERENCE_USAGE_MAX_DURATION_MS);
511
+ var TerminalInferenceReportedAtSchema = z.iso.datetime({ offset: true, precision: 3 }).refine((value) => value.endsWith("Z"), "reportedAt must be canonical UTC (Z)");
512
+ var TerminalInferenceUsageSchema = z.object({
513
+ /** The adapter that actually started this task, never a requested fallback. */
514
+ runtime: RuntimeIdSchema,
515
+ /** Omitted unless the adapter itself exposed this provider observation. */
516
+ provider: z.string().min(1).max(TERMINAL_INFERENCE_USAGE_PROVIDER_MAX_LENGTH).optional(),
517
+ /** Omitted unless the adapter itself exposed this model observation. */
518
+ model: z.string().min(1).max(TERMINAL_INFERENCE_USAGE_MODEL_MAX_LENGTH).optional(),
519
+ /** Direct projection of the runtime's final observed input token count. */
520
+ promptTokens: TerminalInferenceUsageNumberSchema.optional(),
521
+ /** Direct projection of the runtime's final observed output token count. */
522
+ completionTokens: TerminalInferenceUsageNumberSchema.optional(),
523
+ /** Device-observed elapsed duration for the started task. */
524
+ durationMs: TerminalInferenceUsageDurationSchema.optional(),
525
+ /** Process-immutable Local Agent release version, owned outside the protocol. */
526
+ clientVersion: z.string().min(1).max(TERMINAL_INFERENCE_USAGE_CLIENT_VERSION_MAX_LENGTH),
527
+ /** Device observation time, never server receipt time. */
528
+ reportedAt: TerminalInferenceReportedAtSchema
529
+ });
283
530
  var TaskCompletePayloadSchema = z.object({
284
531
  summary: z.string(),
285
532
  sessionRef: z.string(),
286
533
  artifactRefs: z.array(BlobRefSchema).optional(),
287
534
  document: z.unknown().optional().refine((value) => value === void 0 || checkResultDocument(value).ok, {
288
535
  message: `task.complete.document must be plain JSON data (equal to its own JSON round trip) and at most ${RESULT_DOCUMENT_MAX_BYTES} bytes as canonical JSON (UTF-8)`
289
- })
536
+ }),
537
+ usage: TerminalInferenceUsageSchema.optional(),
538
+ agentRef: AgentRefSchema.optional()
290
539
  });
291
540
  var TaskFailPayloadSchema = z.object({
292
541
  reason: z.string(),
293
- retryable: z.boolean().optional()
542
+ retryable: z.boolean().optional(),
543
+ usage: TerminalInferenceUsageSchema.optional(),
544
+ agentRef: AgentRefSchema.optional()
294
545
  });
295
546
  var TaskCancelledPayloadSchema = z.object({
296
- reason: z.string().optional()
547
+ reason: z.string().optional(),
548
+ usage: TerminalInferenceUsageSchema.optional(),
549
+ agentRef: AgentRefSchema.optional()
297
550
  });
298
551
  var TaskApprovalResolvedPayloadSchema = z.object({
299
552
  approvalId: z.string(),
@@ -306,6 +559,12 @@ var MESSAGE_PAYLOAD_SCHEMAS = {
306
559
  "conn.ack": ConnAckPayloadSchema,
307
560
  "task.offer": TaskOfferPayloadSchema,
308
561
  "task.offer_with_toolsets": TaskOfferWithToolsetsPayloadSchema,
562
+ "task.offer_for_agent": TaskOfferForAgentPayloadSchema,
563
+ "task.offer_for_agent_with_egress": TaskOfferForAgentWithEgressPayloadSchema,
564
+ "agent.egress.reliable": AgentEgressReliablePayloadSchema,
565
+ "agent.egress.ack": AgentEgressAckPayloadSchema,
566
+ "agent.content.read": AgentContentReadPayloadSchema,
567
+ "agent.content.receipt": AgentContentReceiptPayloadSchema,
309
568
  "task.approve": TaskApprovePayloadSchema,
310
569
  "task.reject": TaskRejectPayloadSchema,
311
570
  "task.cancel": TaskCancelPayloadSchema,
@@ -326,6 +585,10 @@ var SERVER_TO_DAEMON_TYPES = [
326
585
  "conn.ack",
327
586
  "task.offer",
328
587
  "task.offer_with_toolsets",
588
+ "task.offer_for_agent",
589
+ "task.offer_for_agent_with_egress",
590
+ "agent.egress.ack",
591
+ "agent.content.read",
329
592
  "task.approve",
330
593
  "task.reject",
331
594
  "task.cancel",
@@ -341,7 +604,9 @@ var DAEMON_TO_SERVER_TYPES = [
341
604
  "task.complete",
342
605
  "task.fail",
343
606
  "task.cancelled",
344
- "task.approval_resolved"
607
+ "task.approval_resolved",
608
+ "agent.egress.reliable",
609
+ "agent.content.receipt"
345
610
  ];
346
611
  var REQUIRED_TASK_ID = z.string().min(1);
347
612
  var OPTIONAL_TASK_ID = REQUIRED_TASK_ID.optional();
@@ -369,6 +634,10 @@ var EnvelopeSchema = z.discriminatedUnion("type", [
369
634
  // (per-device redelivery cursor).
370
635
  envelopeShape("task.offer", REQUIRED_TASK_ID, REQUIRED_SEQ),
371
636
  envelopeShape("task.offer_with_toolsets", REQUIRED_TASK_ID, REQUIRED_SEQ),
637
+ envelopeShape("task.offer_for_agent", REQUIRED_TASK_ID, REQUIRED_SEQ),
638
+ envelopeShape("task.offer_for_agent_with_egress", REQUIRED_TASK_ID, REQUIRED_SEQ),
639
+ envelopeShape("agent.egress.ack", OPTIONAL_TASK_ID, REQUIRED_SEQ),
640
+ envelopeShape("agent.content.read", OPTIONAL_TASK_ID, REQUIRED_SEQ),
372
641
  envelopeShape("task.approve", REQUIRED_TASK_ID, REQUIRED_SEQ),
373
642
  envelopeShape("task.reject", REQUIRED_TASK_ID, REQUIRED_SEQ),
374
643
  envelopeShape("task.cancel", REQUIRED_TASK_ID, REQUIRED_SEQ),
@@ -385,7 +654,9 @@ var EnvelopeSchema = z.discriminatedUnion("type", [
385
654
  envelopeShape("task.complete", REQUIRED_TASK_ID, OPTIONAL_SEQ),
386
655
  envelopeShape("task.fail", REQUIRED_TASK_ID, OPTIONAL_SEQ),
387
656
  envelopeShape("task.cancelled", REQUIRED_TASK_ID, OPTIONAL_SEQ),
388
- envelopeShape("task.approval_resolved", REQUIRED_TASK_ID, OPTIONAL_SEQ)
657
+ envelopeShape("task.approval_resolved", REQUIRED_TASK_ID, OPTIONAL_SEQ),
658
+ envelopeShape("agent.egress.reliable", OPTIONAL_TASK_ID, OPTIONAL_SEQ),
659
+ envelopeShape("agent.content.receipt", OPTIONAL_TASK_ID, OPTIONAL_SEQ)
389
660
  ]);
390
661
  function isServerToDaemonType(type) {
391
662
  return SERVER_TO_DAEMON_TYPES.includes(type);
@@ -502,6 +773,23 @@ var TokenResponseSchema = z.object({
502
773
  accessToken: z.string(),
503
774
  expiresAt: z.iso.datetime({ offset: true })
504
775
  });
776
+ var PRESENCE_DETAIL_MAX_LENGTH = 512;
777
+ var PRESENCE_RUNTIME_VERSION_MAX_LENGTH = 128;
778
+ var PresenceRuntimeFactSchema = z.object({
779
+ id: RuntimeIdSchema,
780
+ version: z.string().min(1).max(PRESENCE_RUNTIME_VERSION_MAX_LENGTH).optional(),
781
+ authPresent: z.boolean().optional()
782
+ });
783
+ var PresencePublishRequestSchema = z.object({
784
+ level: z.enum(["online", "thinking", "working", "error", "offline"]),
785
+ detail: z.string().max(PRESENCE_DETAIL_MAX_LENGTH).optional(),
786
+ configuredToolsets: ConfiguredToolsetsSchema.optional(),
787
+ /** U4a Local Agent release version; never inferred from a host package. */
788
+ clientVersion: z.string().min(1).max(128).optional(),
789
+ protocolVersions: z.array(ProtocolVersionNumberSchema).max(16).optional(),
790
+ /** Runtime version/auth facts from the same real probe as conn.hello. */
791
+ runtimes: z.array(PresenceRuntimeFactSchema).max(16).optional()
792
+ });
505
793
  var CreateBlobRequestSchema = z.object({
506
794
  size: z.number().int().nonnegative(),
507
795
  contentType: z.string(),
@@ -575,6 +863,6 @@ function byokBlobContentPath(blobId) {
575
863
  return `/byok/blobs/${blobId}/content`;
576
864
  }
577
865
 
578
- export { AgentEventOrUnknownSchema, AgentEventSchema, BYOK_ACTIVITY_PATH, BYOK_BLOBS_PATH, BYOK_BLOB_CONTENT_ROUTE, BYOK_BLOB_FINALIZE_ROUTE, BYOK_BLOB_URL_ROUTE, BYOK_BOARD_CLAIM_ROUTE, BYOK_BOARD_PATH, BYOK_BOARD_STATUS_ROUTE, BYOK_BOARD_STREAM_PATH, BYOK_BOARD_UNCLAIM_ROUTE, BYOK_CAPABILITIES_PATH, BYOK_CHALLENGE_PATH, BYOK_EVENTS_PATH, BYOK_MESSAGES_PATH, BYOK_PAIR_PATH, BYOK_PRESENCE_PATH, BYOK_RECORDS_PATH, BYOK_RECORD_ROUTE, BYOK_SKILL_PACKS_PATH, BYOK_SKILL_PACK_FILE_ROUTE, BYOK_TOKEN_PATH, BYOK_WS_PATH, BlobDownloadUrlResponseSchema, BlobRefSchema, CAPABILITY_FLAGS, CONFIGURED_TOOLSETS_MAX_ITEMS, CONTENT_HASH_RE, ChallengeRequestSchema, ChallengeResponseSchema, ConfiguredToolsetsSchema, ConnAckPayloadSchema, ConnHelloPayloadSchema, CreateBlobRequestSchema, CreateBlobResponseSchema, DAEMON_TO_SERVER_TYPES, DispatchSelectionSchema, EnvelopeParseError, EnvelopeSchema, EnvelopeValidationError, EventsPollQuerySchema, EventsPollResponseSchema, KNOWN_AGENT_EVENT_TYPES, MAX_MESSAGES_PER_BATCH, MESSAGE_PAYLOAD_SCHEMAS, MESSAGE_TYPES, MessagesSendRequestSchema, MessagesSendResponseSchema, PERMISSION_MODES, PROTOCOL_VERSION, PairRequestSchema, PairResponseSchema, PermissionPolicySchema, ProtocolError, RESULT_DOCUMENT_MAX_BYTES, RequiredToolsetsSchema, RuntimeCapabilitiesSchema, RuntimeIdSchema, RuntimeInfoSchema, SERVER_TO_DAEMON_TYPES, TASK_STATES, TASK_TRANSITIONS, TaskApprovalResolvedPayloadSchema, TaskApprovePayloadSchema, TaskArtifactPayloadSchema, TaskAwaitApprovalPayloadSchema, TaskCancelPayloadSchema, TaskCancelledPayloadSchema, TaskClaimPayloadSchema, TaskCompletePayloadSchema, TaskDeclinePayloadSchema, TaskFailPayloadSchema, TaskOfferPayloadSchema, TaskOfferWithToolsetsPayloadSchema, TaskProgressPayloadSchema, TaskRejectPayloadSchema, TaskStartedPayloadSchema, TaskSteerPayloadSchema, TokenRequestSchema, TokenResponseSchema, ToolsetIdSchema, UnknownAgentEventSchema, UnknownMessageTypeError, byokBlobContentPath, byokBlobFinalizePath, byokBlobUrlPath, byokRecordPath, byokSkillPackFilePath, canTransition, checkResultDocument, createEnvelope, decodeEnvelope, encodeEnvelope, isKnownAgentEvent, isServerToDaemonType, parseMessage, partitionAgentEvents };
866
+ export { AGENT_CONTENT_ARTIFACT_READ_CAPABILITY, AGENT_CONTENT_TRANSCRIPT_READ_CAPABILITY, AGENT_CONTENT_WORKSPACE_READ_CAPABILITY, AGENT_EGRESS_POLICY_CAPABILITY, AGENT_EGRESS_RELIABLE_ACK_CAPABILITY, AGENT_REF_MAX_BYTES, AgentContentActorKindSchema, AgentContentActorSchema, AgentContentDecodeAsSchema, AgentContentMimeTypeSchema, AgentContentReadDecisionSchema, AgentContentReadDenialReasonSchema, AgentContentReadPayloadSchema, AgentContentReadSurfaceSchema, AgentContentReceiptPayloadSchema, AgentEgressAckPayloadSchema, AgentEgressActivityPolicySchema, AgentEgressContentHashSchema, AgentEgressDropReasonSchema, AgentEgressLaneSchema, AgentEgressPolicyRevisionSchema, AgentEgressPolicySchema, AgentEgressReliablePayloadSchema, AgentEventOrUnknownSchema, AgentEventSchema, AgentRefSchema, AgentReliableQuotaPolicySchema, BYOK_ACTIVITY_PATH, BYOK_BLOBS_PATH, BYOK_BLOB_CONTENT_ROUTE, BYOK_BLOB_FINALIZE_ROUTE, BYOK_BLOB_URL_ROUTE, BYOK_BOARD_CLAIM_ROUTE, BYOK_BOARD_PATH, BYOK_BOARD_STATUS_ROUTE, BYOK_BOARD_STREAM_PATH, BYOK_BOARD_UNCLAIM_ROUTE, BYOK_CAPABILITIES_PATH, BYOK_CHALLENGE_PATH, BYOK_EVENTS_PATH, BYOK_MESSAGES_PATH, BYOK_PAIR_PATH, BYOK_PRESENCE_PATH, BYOK_RECORDS_PATH, BYOK_RECORD_ROUTE, BYOK_SKILL_PACKS_PATH, BYOK_SKILL_PACK_FILE_ROUTE, BYOK_TOKEN_PATH, BYOK_WS_PATH, BlobDownloadUrlResponseSchema, BlobRefSchema, CAPABILITY_FLAGS, CONFIGURED_TOOLSETS_MAX_ITEMS, CONTENT_HASH_RE, ChallengeRequestSchema, ChallengeResponseSchema, ConfiguredToolsetsSchema, ConnAckPayloadSchema, ConnHelloPayloadSchema, ContentReadPolicySchema, CreateBlobRequestSchema, CreateBlobResponseSchema, DAEMON_TO_SERVER_TYPES, DispatchSelectionSchema, EnvelopeParseError, EnvelopeSchema, EnvelopeValidationError, EventsPollQuerySchema, EventsPollResponseSchema, KNOWN_AGENT_EVENT_TYPES, MAX_MESSAGES_PER_BATCH, MESSAGE_PAYLOAD_SCHEMAS, MESSAGE_TYPES, MessagesSendRequestSchema, MessagesSendResponseSchema, PERMISSION_MODES, PROTOCOL_VERSION, PairRequestSchema, PairResponseSchema, PermissionPolicySchema, PresencePublishRequestSchema, ProtocolError, ProtocolVersionNumberSchema, RESULT_DOCUMENT_MAX_BYTES, RequiredToolsetsSchema, RuntimeCapabilitiesSchema, RuntimeIdSchema, RuntimeInfoSchema, SERVER_TO_DAEMON_TYPES, TASK_STATES, TASK_TRANSITIONS, TERMINAL_INFERENCE_USAGE_CLIENT_VERSION_MAX_LENGTH, TERMINAL_INFERENCE_USAGE_MAX_DURATION_MS, TERMINAL_INFERENCE_USAGE_MAX_TOKENS, TERMINAL_INFERENCE_USAGE_MODEL_MAX_LENGTH, TERMINAL_INFERENCE_USAGE_PROVIDER_MAX_LENGTH, TaskApprovalResolvedPayloadSchema, TaskApprovePayloadSchema, TaskArtifactPayloadSchema, TaskAwaitApprovalPayloadSchema, TaskCancelPayloadSchema, TaskCancelledPayloadSchema, TaskClaimPayloadSchema, TaskCompletePayloadSchema, TaskDeclinePayloadSchema, TaskFailPayloadSchema, TaskOfferForAgentPayloadSchema, TaskOfferForAgentWithEgressPayloadSchema, TaskOfferPayloadSchema, TaskOfferWithToolsetsPayloadSchema, TaskProgressPayloadSchema, TaskRejectPayloadSchema, TaskStartedPayloadSchema, TaskSteerPayloadSchema, TerminalInferenceUsageSchema, TokenRequestSchema, TokenResponseSchema, ToolsetIdSchema, UnknownAgentEventSchema, UnknownMessageTypeError, byokBlobContentPath, byokBlobFinalizePath, byokBlobUrlPath, byokRecordPath, byokSkillPackFilePath, canTransition, checkResultDocument, createEnvelope, decodeEnvelope, encodeEnvelope, isKnownAgentEvent, isServerToDaemonType, parseMessage, partitionAgentEvents };
579
867
  //# sourceMappingURL=index.js.map
580
868
  //# sourceMappingURL=index.js.map