@agents-js/a2a
v0.4.0
Published
A2A server — wraps an ACP agent as an HTTP JSON-RPC + SSE streaming endpoint with CORS support.
Maintainers
Readme
@agents-js/a2a
A2A server — wraps an ACP agent as an HTTP JSON-RPC + SSE streaming endpoint with CORS support.
Installation
bun add @agents-js/a2aAPI
Classes
ACPtoA2AExecutor— Bridges A2A execution requests to an ACP agent. Acts as an ACP Client.SessionIdStoreUniversalA2AServer
Functions
buildACPA2AContinuationMetadatabuildACPA2ATaskMetadatabuildAgentCardbuildAgentCardBaseUrlbuildStatusUpdate— Build a TaskStatusUpdateEvent for streaming status changes. Optionally includes a text message in the status.buildTerminalTask— Build a terminal Task snapshot with an agent message in the history. Used for final (completed/failed/rejected/canceled) task publications.createAuditEmitter— Build a bounded in-process audit emitter with structured logging.createConsoleLoggerextractACPA2AContinuationMetadataextractValidAgentMessageIdformatBindAddressformatErrorMessage— Extract a human-readable message from an unknown error value. Works with Error instances, plain objects with amessageproperty, and raw strings.formatHttpAuthorityHostgetMessageText— Extract text content from an A2A Message's parts arrayisACPAuthRequiredErrorisAgentEventMetadata— Type guard: does thismetadatacarry a known agent-event kind?mapCapabilities— Map ACP agentCapabilities and discovered resources into A2A AgentCardnewCorrelationId— Generate a fresh correlation id.normalizeAdvertisedHostnowIsoresolveAgentMessageIdselectPermissionOutcomeserveACPOverA2AwithAuthRetry— Retry an async operation when it fails with an ACP auth_required error. - The operation to attempt - Called on auth errors; returns true if auth was handled and retry should proceed - Maximum numbe...
Interfaces
A2AHttpServerHandleA2ALoggerACPA2AContinuationMetadataACPA2ATaskMetadataAuditEmitter— Public emitter handle.CommandsMetadata— Metadata for anavailable_commands_updatenotification — the set of slash-commands currently available from the harness. Uses the SDK's typedAvailableCommandshape so consumers get the full pe...DiscoveredPromptDiscoveredResourceExecutorHooks— Lifecycle hooks for the {ACPtoA2AExecutor}. Mirrors the subset of {import("-js/acp-host").SessionHooks} that applies to the A2A-to-ACP bridge. Hosts that want to transform prompt content before it ...InitializableExecutor— An AgentExecutor that also supports ACP initialization. Used by UniversalA2AServer to discover agent capabilities before serving the A2A agent card. Both ACPtoA2AExecutor and HostA2AExecutor implem...ModeChangedMetadata— Metadata for acurrent_mode_updatenotification — mode transitions like plan→execute or model swaps. ACP'sCurrentModeUpdateonly carries the newcurrentModeId; the available-modes list is de...PlanMetadata— Metadata for an ACPplannotification — the agent's structured todo-list. Always carries the FULL set of entries; consumers replace state wholesale on receipt. Entries reuse the SDK's typed `Plan...ServeACPOverA2AHandleServeACPOverA2AOptionsSessionInfoUpdatedMetadata— Metadata for asession_info_updatenotification — the harness mutating session-level metadata (title, last-activity timestamp). Three-state per field:undefined= no change,null= explicit c...ThoughtMetadata— Metadata for anagent_thought_chunkACP notification. Thedeltais the incremental text added by this chunk;cumulativeTextis the running concatenation permessageId.ToolCallEndMetadata— Metadata for a terminal tool-call transition (completed/failed). Receivers move the call from active to completed. Carries the full final ACPToolCallpayload so receivers don't need to ret...ToolCallProgressMetadata— Metadata for a non-terminal tool-call status transition (e.g.pending→in_progress) or a payload-only update (content / locations / raw I/O) without a status change. Receivers should update th...ToolCallStartMetadata— Metadata for the initial registration of a tool call. Carries the full ACPToolCallpayload so receivers can render rich detail (diff/terminal content, file locations, raw input/output, tool kind...UniversalA2AServerOptionsUsageMetadata— Metadata for ausage_updatenotification — token-budget telemetry.costreuses the SDK'sCosttype ({ amount: number; currency: string }) so structured multi-currency values are preserved e...
Types
AgentCardAgentEventKind— Allowed values forTaskStatusUpdateEvent.metadata.kind.AgentEventMetadata— Discriminated union of all agent-event metadata shapes that ride onTaskStatusUpdateEvent.metadata. Use this as the type formetadatawhen emitting a non-text agent event.AgentExecutorAuditEvent— Closed set of audit-event variants. Each carries only structural metadata and covers surfaces that emit records in source.AuditEventInputAuditLogger— Logger surface the emitter writes to. Compatible withconsole.AvailableCommand— Re-export the SDK schema types we ride on so consumers don't need to take a separate dependency on/sdkjust to read these.CorrelationId— Stable correlation token. UUIDv4 strings in practice; consumers should treat as opaque.Cost— Re-export the SDK schema types we ride on so consumers don't need to take a separate dependency on/sdkjust to read these.ExecutionEventBusGatewayAgentCapabilitiesGatewayAgentCardGatewayCardInputHttpStatus— Union of the numeric values in {HTTP_STATUS}. Useful for typing custom handler return values or status-code routing tables that should only accept codes the monorepo emits.MessagePlanEntry— Re-export the SDK schema types we ride on so consumers don't need to take a separate dependency on/sdkjust to read these.RequestContextTaskTaskStatusTaskStatusUpdateEventToolCallContent— Re-export the SDK schema types we ride on so consumers don't need to take a separate dependency on/sdkjust to read these.ToolCallEndStatus— Terminal status values for tool-call-end metadata. ACP definespending/in_progressas non-terminal andcompleted/failedas terminal. We accept any string here so receivers see what the ...ToolCallLocation— Re-export the SDK schema types we ride on so consumers don't need to take a separate dependency on/sdkjust to read these.ToolKind— Re-export the SDK schema types we ride on so consumers don't need to take a separate dependency on/sdkjust to read these.
Constants
_AUDIT_EVENT_NO_SENSITIVE_PAYLOADCURRENT_A2A_PROTOCOL_VERSIONDEFAULT_MAX_REQUEST_BODY_SIZE— Default maximum request body size in bytes (4 MB).DEFAULT_MAX_TEXT_BUFFER_SIZE— Default maximum text buffer size in bytes (256 KB).HTTP_STATUS— Centralized HTTP status code constants for any module in the monorepo that constructs aResponseobject. Inclusion policy: this list is intentionally narrow — only codes the monorepo actually...
Exports
type A2ALoggertype HttpStatus
Dependencies
@a2a-js/sdk@agentclientprotocol/sdk@agents-js/acp@agents-js/validation
License
MIT
