Skip to content
reaatechREAATECH

@reaatech/a2a-reference-core

npm v0.1.0

Provides canonical TypeScript types, Zod schemas, and custom error classes for the Agent-to-Agent (A2A) protocol. It serves as a shared library for validating agent cards, tasks, messages, and artifacts at runtime.

@reaatech/a2a-reference-core

npm version License: MIT CI

Status: Pre-1.0 — APIs may change in minor versions. Pin to a specific version in production.

Canonical TypeScript types, Zod schemas, and error classes for the Agent-to-Agent (A2A) protocol. This package is the single source of truth for all A2A protocol shapes used throughout the @reaatech/a2a-reference-* ecosystem.

Installation

terminal
npm install @reaatech/a2a-reference-core
# or
pnpm add @reaatech/a2a-reference-core

Feature Overview

  • 70+ exported types and schemas — every A2A protocol shape has a corresponding Zod schema for runtime validation
  • 35 Zod schemas — parse and validate agent cards, tasks, messages, artifacts, and stream events at the boundary
  • 9 typed error classesTaskNotFoundError, UnsupportedOperationError, VersionNotSupportedError, and more
  • Zero runtime dependencies beyond zod — lightweight and tree-shakeable
  • Dual ESM/CJS output — works with import and require

Quick Start

typescript
import { TaskSchema, type TaskState, A2AError } from "@reaatech/a2a-reference-core";
 
// Validate a task at the boundary
const rawTask = JSON.parse(incomingJson);
const task = TaskSchema.parse(rawTask);
 
// Check terminal states (TaskState is a string union: "submitted" | "working" | ...)
if (task.status.state === "completed") {
  console.log("Task finished:", task.artifacts);
}
 
// Throw typed errors
throw new A2AError("CUSTOM_ERROR", "Something went wrong", { extra: "context" });

Exports

Content Parts

The atomic content unit in A2A. All messages and artifacts are composed of parts.

ExportDescription
PartSchema / PartDiscriminated union of TextPart, FilePart, DataPart
TextPartSchema / TextPart{ kind: "text", text: string, metadata?: Record<string, unknown> }
FilePartSchema / FilePart{ kind: "file", file: { name?, mimeType?, bytes?, uri? }, metadata? }
DataPartSchema / DataPart{ kind: "data", data: Record<string, unknown>, metadata? }

Tasks & Messages

ExportDescription
TaskSchema / TaskCentral entity: id, contextId?, status, artifacts?, history?, metadata?
TaskStatusSchema / TaskStatus{ state: TaskState, message?, timestamp? }
TaskState / TaskStateSchemaEnum: submitted, working, input-required, completed, failed, canceled, rejected, auth-required
MessageSchema / Message{ messageId, role: "user" | "agent", parts: Part[], contextId?, taskId? }
ArtifactSchema / Artifact{ artifactId?, name?, description?, parts: Part[], metadata? }

Agent Card

ExportDescription
AgentCardSchema / AgentCardFull agent descriptor: name, description, url, capabilities, skills, security, interfaces
SkillSchema / SkillA declared skill: id, name, description, tags, parameters?
CapabilitySchema / Capability{ streaming?, pushNotifications?, stateTransitionHistory? }
AgentInterfaceSchema / AgentInterface{ url, protocolBinding, protocolVersion }

Security Schemes

ExportDescription
SecuritySchemeSchema / SecuritySchemeUnion of all four scheme types
ApiKeySecurityScheme / SchemaAPI key in header, query, or cookie
HttpSecurityScheme / SchemaHTTP Bearer authentication
OAuth2SecurityScheme / SchemaOAuth2 with flows and scopes
OpenIdConnectSecurityScheme / SchemaOpenID Connect with discovery URL

Streaming Events

ExportDescription
StreamResponseSchema / StreamResponseSSE event union: task, message, status, artifact
TaskStatusUpdateEventSchema / TaskStatusUpdateEvent{ kind: "status", taskId?, status: TaskStatus, final? }
TaskArtifactUpdateEventSchema / TaskArtifactUpdateEvent{ kind: "artifact", taskId?, artifact: Artifact, append?, lastChunk? }

A2A API Requests & Responses

ExportDescription
SendMessageRequest / ResponseSend a message to an agent, returns a Task
GetTaskRequest / ResponseRetrieve a task by ID
ListTasksRequest / ResponsePaginated task listing with optional filters
CancelTaskRequest / ResponseCancel an in-progress task
SubscribeToTaskRequestSubscribe to task SSE stream
TaskPushNotificationConfigWebhook push notification configuration

Error Classes

All errors extend A2AError which includes code: string, message: string, and optional details?: unknown.

ClassCodeWhen
A2AError(custom)Base class for all A2A errors
TaskNotFoundErrorTaskNotFoundErrorRequested task does not exist
TaskNotCancelableErrorTaskNotCancelableErrorTask is in a terminal state
PushNotificationNotSupportedErrorPushNotificationNotSupportedErrorAgent lacks push notification capability
UnsupportedOperationErrorUnsupportedOperationErrorOperation not implemented by agent
ContentTypeNotSupportedErrorContentTypeNotSupportedErrorContent type not accepted
InvalidAgentResponseErrorInvalidAgentResponseErrorDownstream agent returned invalid response
ExtendedAgentCardNotConfiguredErrorExtendedAgentCardNotConfiguredErrorExtended card retrieval not configured
ExtensionSupportRequiredErrorExtensionSupportRequiredErrorRequired protocol extension not supported
VersionNotSupportedErrorVersionNotSupportedErrorUnsupported protocol version

Usage Pattern

Every schema export has a matching type export. Use the schema for runtime validation and the type for compile-time checking:

typescript
import { TaskSchema, type Task } from "@reaatech/a2a-reference-core";
 
function handleResponse(raw: unknown): Task {
  // Parse at the boundary — throws ZodError on invalid data
  return TaskSchema.parse(raw);
}

License

MIT