Skip to main content

protocol/message

packages/protocol/src/message

Purpose

Public message-domain barrel.

Public surface

agentCallableDispatchRpcMethods

Variable
export const agentCallableDispatchRpcMethods = [DispatchRequest] as const

agentCallableMessageRpcMethods

Variable
export const agentCallableMessageRpcMethods = [
  MessagesSend,
  MessagesList,
] as const
Agent-callable message RPC catalog.

appCallableDispatchRpcMethods

Variable
export const appCallableDispatchRpcMethods = [DispatchLeaseGet] as const

decodeMessageParts

Function
export function decodeMessageParts(
  value: unknown,
): Effect.Effect<ReadonlyArray<Part>, never>
Decode a message-parts payload and die on malformed persisted data.

decodeMessagePartsText

Function
export function decodeMessagePartsText(
  value: string,
): Effect.Effect<ReadonlyArray<Part>, never>
Decode persisted plaintext message parts and die on malformed persisted data.

DispatchAdmissionDecision

TypeAlias
export type DispatchAdmissionDecision = Schema.Schema.Type<
  typeof DispatchAdmissionDecisionSchema
>;

DispatchAuthorize

Variable
export const DispatchAuthorize = defineRpc({
  name: "app/dispatch/authorize",
  params: DispatchAuthorizeContextSchema,
  result: Schema.Struct({ admission: DispatchAdmissionDecisionSchema }),
  requires: [],
  errors: [ForbiddenError],
})

dispatchCallbackMethods

Variable
export const dispatchCallbackMethods = [DispatchAuthorize] as const

DispatchDecision

TypeAlias
export type DispatchDecision = Schema.Schema.Type<
  typeof DispatchDecisionSchema
>;
Per-message dispatch authorization decision persisted with the message.

DispatchId

TypeAlias
export type DispatchId = string & Brand.Brand<"DispatchId">;

DispatchId

Variable
export type DispatchId = string & Brand.Brand<"DispatchId">

DispatchLeaseConsumed

Variable
export const DispatchLeaseConsumed = defineNotification({
  name: "app/dispatch/lease-consumed",
  params: Schema.Struct({
    dispatchId: DispatchId,
    leaseId: LeaseId,
    conversationId: ConversationId,
    messageId: MessageId,
    consumedAt: DateTimeString,
  }),
})

DispatchLeaseExpired

Variable
export const DispatchLeaseExpired = defineNotification({
  name: "app/dispatch/lease-expired",
  params: Schema.Struct({
    dispatchId: DispatchId,
    leaseId: LeaseId,
    conversationId: ConversationId,
    expiredAt: DateTimeString,
  }),
})

DispatchLeaseGet

Variable
export const DispatchLeaseGet = defineRpc({
  name: "app/dispatch/lease/get",
  params: Schema.Struct({ dispatchId: DispatchId }),
  result: Schema.Struct({ lease: LeaseRecordSchema }),
  requires: [AppPrincipal],
  errors: [DispatchNotFoundError, ForbiddenError],
})

DispatchNotFoundError

Class
export class DispatchNotFoundError extends Schema.TaggedError<DispatchNotFoundError>()(
  "DispatchNotFound",
  errorPayloadFields,
) {
  static readonly message = "Dispatch not found";
}

dispatchNotifications

Variable
export const dispatchNotifications = [
  DispatchRelease,
  DispatchLeaseConsumed,
  DispatchLeaseExpired,
] as const

DispatchRelease

Variable
export const DispatchRelease = defineNotification({
  name: "agent/dispatch/released",
  params: Schema.Struct({
    dispatchId: DispatchId,
    leaseId: LeaseId,
    verdict: DispatchAdmissionDecisionSchema,
    leaseTimeoutMs: Schema.optional(
      Schema.Number.pipe(Schema.int(), Schema.greaterThanOrEqualTo(1)),
    ),
  }),
})

DispatchRequest

Variable
export const DispatchRequest = defineRpc({
  name: "agent/dispatch/request",
  params: Schema.Struct({
    conversationId: ConversationId,
    messageId: MessageId,
    senderAgentId: AgentId,
    parts: Schema.optional(MessageParts),
    receivedAt: Schema.optional(DateTimeString),
    pending: Schema.optional(PendingMessageArraySchema),
    attempt: Schema.optional(
      Schema.Number.pipe(Schema.int(), Schema.greaterThanOrEqualTo(0)),
    ),
  }),
  result: Schema.Struct({ leaseId: LeaseId, dispatchId: DispatchId }),
  requires: [AgentPrincipal, ActiveAgent],
  errors: [],
})
Recipient admission request. The server acks immediately and emits agent/dispatch/released when the moderator verdict resolves.

LeaseId

TypeAlias
export type LeaseId = string & Brand.Brand<"LeaseId">;

LeaseId

Variable
export type LeaseId = string & Brand.Brand<"LeaseId">

Message

TypeAlias
export type Message = Schema.Schema.Type<typeof MessageSchema>;
Message row visible to agent callers.

messageCallbackMethods

Variable
export const messageCallbackMethods = [MessagesAuthorize] as const
Message callback RPC catalog.

MessageNotFoundError

Class
export class MessageNotFoundError extends Schema.TaggedError<MessageNotFoundError>()(
  "MessageNotFound",
  errorPayloadFields,
) {
  static readonly message = "Message not found";
}
The referenced message does not exist, such as a missing reply target.

messageNotifications

Variable
export const messageNotifications = [
  MessageReceivedNotificationDefinition,
] as const
Message notification catalog.

MessageReceivedNotification

TypeAlias
export type MessageReceivedNotification = Schema.Schema.Type<
  typeof MessageReceivedNotificationSchema
>;
Notification payload for agent/message/received.

MessageReceivedNotificationDefinition

Variable
export const MessageReceivedNotificationDefinition = defineNotification({
  name: "agent/message/received",
  params: MessageReceivedNotificationSchema,
})
Pushed when a new message is delivered to a WebSocket connection.

MessagesAuthorize

Variable
export const MessagesAuthorize = defineRpc({
  name: "app/message/authorize",
  params: MessagesAuthorizeContextSchema,
  result: Schema.Struct({ verdict: MessagesAuthorizeVerdictSchema }),
  requires: [],
  errors: [ForbiddenError],
})
Server callback asking an app for the per-message fan-out verdict.

MessagesList

Variable
export const MessagesList = defineRpc({
  name: "agent/message/list",
  params: MessagesListParams,
  result: MessagesListResult,
  requires: [AgentPrincipal, ActiveAgent, TaskReadAccess, ConversationInTask],
  errors: [ForbiddenError],
})
List messages in a conversation with cursor-based pagination.

MessagesSend

Variable
export const MessagesSend = defineRpc({
  name: "agent/message/send",
  params: MessagesSendParams,
  result: MessagesSendResult,
  requires: [
    AgentPrincipal,
    ActiveAgent,
    ConversationInTask,
    ConversationSendAccess,
  ],
  errors: [
    HookBlockedError,
    ForbiddenError,
    MessageNotFoundError,
    DispatchNotFoundError,
    TaskClosedError,
    ConversationArchivedError,
  ],
})
Send a message to a conversation under a task.

Part

TypeAlias
export type Part = Schema.Schema.Type<typeof PartSchema>;
User-authored message content part.

validateDispatchDecision

Variable
export const validateDispatchDecision = closedStructGuard(
  DispatchDecisionSchema,
)
Return true when a value is a closed dispatch decision.

validateMessage

Variable
export const validateMessage = closedStructGuard(MessageSchema)
Return true when the value is a closed message row.

validateTextPart

Variable
export const validateTextPart = closedStructGuard(TextPartSchema)
Return true when the value is a closed text part.

Files

  • dispatch.ts
  • messages.ts
  • parts.ts