/** * Envelope layer — the v2/v3 message envelope wrapping every command and event. * * {@link MessageV2} is the canonical envelope; the name is retained from the * v2 rollout for symbol stability. Protocol v3 keeps the envelope structure * unchanged but swaps the payload contents: * * - `ConfigureCommandV2` (deleted) is replaced by {@link SessionInitCommand}. * - Several v2 commands (`provision_secrets`, `request_access_token`, * `add_resource`, `remove_resource`, `set_log_level`, `state_action`, * `lifecycle`, `remount_mount`, `compact`, `reconfigure_agent`) are * removed; their semantics ride on `session_init` and the * `host.*` / `runner.*` capability families. * * Spec: `_devlog/specs/2026-05-10-deterministic-session-bootstrap.md`. * * @see {@link MessageMeta} for the metadata block carried under `meta` * @see {@link Capability} for the new wire surface * * @category Envelope * @since 2.0.0 */ import type { CapabilityApproveCommand, CapabilityDeregisterCommand, CapabilityDeregisterEvent, CapabilityInvokedEvent, CapabilityRegisterCommand, CapabilityRegisterEvent, CapabilityResultCommand, RenderInvokedEvent } from "./capabilities.js"; import type { AgentEvent } from "./events.js"; import type { IncompatibleProtocolEvent, ProtocolInfoEvent, SessionInitAckEvent, SessionInitCommand, SessionInitMismatchEvent } from "./lifecycle.js"; import type { MessageMeta } from "./messaging.js"; import type { AgentCommand } from "./protocol.js"; /** * Capability commands added in v2. These are appended to the v2 payload * union; the v1 {@link AgentCommand} is left untouched. * * @category Envelope * @since 2.0.0 * @docLink packages/types/protocol-v2#envelope-unions */ export type CapabilityCommand = CapabilityRegisterCommand | CapabilityDeregisterCommand | CapabilityResultCommand | CapabilityApproveCommand; /** * Capability and lifecycle events carried in the v2/v3 envelope. * * Adds the v3 session-init lifecycle events alongside the v2 protocol * info / mismatch events. * * @category Envelope * @since 2.0.0 * @docLink packages/types/protocol-v3#envelope-unions */ export type CapabilityEvent = CapabilityRegisterEvent | CapabilityDeregisterEvent | CapabilityInvokedEvent | RenderInvokedEvent | IncompatibleProtocolEvent | ProtocolInfoEvent | SessionInitAckEvent | SessionInitMismatchEvent; /** * Union of every command the v2/v3 envelope can carry. Plain * {@link AgentCommand} plus the capability commands plus the v3 * {@link SessionInitCommand}. * * @category Envelope * @since 2.0.0 * @docLink packages/types/protocol-v3#envelope-unions */ export type AgentCommandV2 = AgentCommand | CapabilityCommand | SessionInitCommand; /** * Union of every event the v2/v3 envelope can carry. Equivalent to plain * {@link AgentEvent} plus the v2/v3 capability/lifecycle events. * * @category Envelope * @since 2.0.0 * @docLink packages/types/protocol-v3#envelope-unions */ export type AgentEventV2 = AgentEvent | CapabilityEvent; /** * The v2 message envelope. A structural superset of v1's {@link Message}: * `senderId`, `mentions`, and `reactions` move under `meta` (typed via * {@link MessageMeta}), and `recipientIds` plus `reply` are added. * * The envelope is **generic over a `TMetaExtensions` type parameter** so * host platforms can attach typed metadata fields (e.g. `priority`, * `archived`) without forking the framework. Framework-side code uses the * default form (`MessageV2` with no type argument). * * @example Framework-side usage: * ```ts * const msg: MessageV2 = { * id: 'msg_01', * seq: 7, * timestamp: new Date().toISOString(), * sessionId: 'sess_42', * payload: { type: 'text', content: 'hi' }, * }; * ``` * * @example Platform-side usage with typed extensions: * ```ts * type PlatformMetaExtensions = { priority?: 'low' | 'normal' | 'high' }; * type PlatformMessage = MessageV2; * const msg: PlatformMessage = { * ..., * meta: { priority: 'high', senderId: 'u_42' }, * }; * ``` * * @typeParam TMetaExtensions - platform-specific extension fields on `meta`. * * @see {@link MessageMeta} for the meta block contract (round-trip preservation) * * @category Envelope * @since 2.0.0 * @docLink packages/types/messages#message-v2 */ export type MessageV2> = { /** UUID — stable identity for this envelope. */ id: string; /** Monotonic per-session sequence number. */ seq: number; /** ISO 8601 emission timestamp. */ timestamp: string; /** Session this envelope belongs to. */ sessionId: string; /** The wrapped command or event payload. Discriminate via `payload.type`. */ payload: AgentCommandV2 | AgentEventV2; /** Optional metadata block; minimal clients omit. See round-trip contract on {@link MessageMeta}. */ meta?: MessageMeta; }; //# sourceMappingURL=envelope.d.ts.map