MACP

Session Classes API Reference

All session classes follow the same base pattern. They differ only in their mode-specific methods.

Common Pattern

Every session class:

  1. Constructor: new XxxSession(client, options?)
  2. Properties: client, sessionId, modeVersion, configurationVersion, policyVersion, auth, projection
  3. Lifecycle: start(input) → mode-specific methods → commit(input)
  4. Metadata: metadata(auth?) queries session state from runtime
  5. Projection: session.projection provides typed local state

Common Options

interface SessionOptions {
  sessionId?: string;             // default: auto-generated UUIDv4
  modeVersion?: string;           // default: '1.0.0'
  configurationVersion?: string;  // default: 'config.default'
  policyVersion?: string;         // default: 'policy.default'
  auth?: AuthConfig;              // default: uses client.auth
}

Common start() Input

{
  intent: string;                                    // session purpose
  participants: string[];                            // participant identifiers
  ttlMs: number;                                     // time-to-live in milliseconds
  context?: Buffer | string | Record<string, unknown>; // optional bound context
  roots?: { uri: string; name?: string }[];          // optional coordination roots
  sender?: string;                                   // optional sender override
}

Common commit() Input

{
  action: string;          // outcome descriptor (e.g., 'deployment.approved')
  authorityScope: string;  // scope of authority
  reason: string;          // auditable reason
  commitmentId?: string;   // default: auto-generated UUID
  sender?: string;
  auth?: AuthConfig;
}

Session Classes Summary

ClassModeKey Methods
DecisionSessionmacp.mode.decision.v1propose, evaluate, raiseObjection, vote
ProposalSessionmacp.mode.proposal.v1propose, counterPropose, accept, reject, withdraw
TaskSessionmacp.mode.task.v1request, acceptTask, rejectTask, update, complete, fail
HandoffSessionmacp.mode.handoff.v1offer, sendContext, acceptHandoff, decline
QuorumSessionmacp.mode.quorum.v1requestApproval, approve, reject, abstain

Per-Method Auth Override

All mode-specific methods accept optional sender and auth fields:

await session.vote({
  proposalId: 'p1',
  vote: 'approve',
  sender: 'alice',                // populate envelope.sender
  auth: Auth.devAgent('alice'),   // use alice's credentials for this call
});

This enables a single process to act on behalf of multiple agents within the same session.

Projection Integration

Each sendAndTrack() call:

  1. Builds an envelope with buildEnvelope() + ProtoRegistry.encodeKnownPayload()
  2. Sends via MacpClient.send() (throws MacpAckError on nack)
  3. On success (ack.ok === true), applies the envelope to the projection

Rejected messages are never applied to the projection.

For full details on each session class, see the Mode documentation.