@agents-js/host
v0.4.0
Published
Host orchestration for the agents-js A2A gateway: ACP-backed A2A executor, AG-UI fetch handler, WebSocket bridge, and surface broadcaster.
Maintainers
Readme
@agents-js/host
Host orchestration for the agents-js A2A gateway: ACP-backed A2A executor, AG-UI fetch handler, WebSocket bridge, and surface broadcaster.
Installation
bun add @agents-js/hostAPI
Classes
AguiRunBusyError— Thrown by {AguiRunCoordinator.acquire} when a run is already active. Endpoint code maps this to HTTP 409 (Conflict) before opening the SSE stream.AguiRunCoordinator— Single-active-run coordinator for the shared primary controller. Concurrency model: AG-UI run-session work runs in the JavaScript event loop (no shared-memory concurrency to worry about), so the "i...HostA2AExecutor— Bridges A2A execution requests to an ACPSessionController. Unlike ACPtoA2AExecutor which manages raw ACP streams, this executor delegates all lifecycle management to the controller and focuses on t...
Functions
applyEnvRuntimeProfilebuildHostRuntimeEnvPolicy— Build the {HostEnvPolicyInput} for the gateway host. With no baseline keys, the policy is exactly the runtime's declaredauthEnvKeys(or empty when the runtime declares none). The host has the ha...buildRuntimeProfileConfigEnvcreateAguiFetchHandler— Build a(req: Request) => Promise<Response | null>handler suitable forUniversalA2AServerOptions.additionalFetch. Returnsnullwhen the request is not for this handler — the caller then fall...createEnsureSessionCoordinatorcreateGatewaySurfaceBroadcastercreateGatewayTestServer— Construct a running gateway test server bound to the given ACP command. This assembles the same three layers as the production gateway: 1.ACPSessionControllerwith Node file adapters + empty per...createHostSessioncreateRuntimeSwitchCoordinatorcreateStandaloneHostController— Spawn a standaloneGatewayHostControllerdetached from anyHostSession. Used byHostA2AExecutor's Phase-2 controller factory: every distinct A2AcontextIdgets its own freshly-started contr...createTranslatorStatecreateWSBridgeenqueueAguiEvent— Validate an AG-UI event and enqueue it as an SSE frame. Invalid events are logged and dropped — the always-on validation gate is a core contract, so silently skipping a bad frame is safer than emit...fetchRuntimeModelsformatAguiSseFramegetEnvRuntimeProfileNameloadRegistryFromDisk— Load the agent registry from disk. Reads fromAGENTS_JS_REGISTRYenv var or~/.agents-js/registry.json. Returns an empty map on any read/parse error (this silent fallback is intentional: a miss...resolveHostWorkspaceFlagrunAguiSession— Run one AG-UI run from start to finish. Caller is responsible for enqueuing the leadingRUN_STARTEDframe and closing the sink after this promise resolves. Why the sink is injected rather than ow...switchHostSessionRuntimetranslateAcpEvent— Translate a singleACPSessionEventinto zero or more AG-UI events. Mutates only the caller-ownedstate(specifically, the embeddedAguiEventStream's open-message + dedup tracking).
Interfaces
AguiEndpointOptionsAguiRunLease— Lease handle returned by {AguiRunCoordinator.acquire}.release()is idempotent so callers can wire it into both the happy-pathfinallyand a separate abort-cancellation handler without worrying...GatewaySurfaceBroadcaster— Adapter that plugs into the ACP host session and, once attached to a live broadcaster, forwards every lifecycle message to that broadcaster.GatewaySurfaceBroadcasterConfigGatewayTestServerHandleGatewayTestServerOptionsHostA2AExecutorOptionsHostSessionHostSessionConfigRunSessionOptionsRunSessionResult— Result of running an AG-UI run session to completion.RuntimeBridgeSnapshotRuntimeModelInfo— Fetches and caches the list of available models from a runtime CLI command. Runs<command> modelsand parses the output into structured model info. Results are cached in memory so repeated calls ...RuntimeSnapshotInfoRuntimeSwapResultRuntimeSwitchStateTranslatorState— Mutable state carried across translator invocations for a single run. The translator delegates open-message tracking and tool-call dedup to the sharedcreateAguiEventStreambuilder so this surfac...WSBridgeConfigWSBridgeHandle
Types
AgentRegistryMap— Name-keyed agent map used by the gateway's dispatch path.AuditEmitterAuditEventAuditEventInputAuditLoggerCorrelationIdGatewayHostControllerRuntimeSwitchOriginSurfaceBroadcastFn— Fan-out callback handed to the broadcaster by the WS bridge.WSBridgeStateWSClientMessage— Client-to-server messagesWSServerMessage— Server-to-client messages
Constants
__testing_AUDIT_EVENT_NO_SENSITIVE_PAYLOADBASELINE_AGENT_SECRET_ENV_KEYS— Baseline secret keys forwarded to every ACP runtime regardless of harness. Empty by design. Earlier revisions forwardedANTHROPIC_API_KEYandMATRIX_ACCESS_TOKENto every runtime as a conve...createAuditEmitterCURATED_RUNTIME_IDSE2E_RUNTIME_PROFILE_CONFIG_HOME_ENVE2E_RUNTIME_PROFILE_DATA_HOME_ENVE2E_RUNTIME_PROFILE_PREFIX_ENVE2E_RUNTIME_PROFILE_RUNTIMES_ENVE2E_RUNTIME_PROFILE_STATE_HOME_ENVnewCorrelationId
Exports
type AgentRegistryMaptype AguiEndpointOptionstype HostA2AExecutorOptionstype RuntimeModelInfo
Dependencies
@a2a-js/sdk@agentclientprotocol/sdk@agents-js/a2a@agents-js/a2a-client@agents-js/a2ui-host@agents-js/a2ui-types@agents-js/acp@agents-js/acp-host@agents-js/agui-types@agents-js/gateway-runtime@agents-js/policy@agents-js/validation
License
MIT
