@agents-js/host
v0.5.1
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...HarnessLaneManager— Owns harness-fleet bookkeeping for the gateway process: lazy-spawns per-session lane controllers via the injected factory, mutates the livegatewayCard.capabilities.harnessesslice in place to re...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
applyEnvRuntimeProfilebuildBridgeBusEvent— Build a bus envelope from a caller-supplied topic + payload. The returned envelope is ready for in-process publishing through {GatewayBus.publish}, or for serialization into the/admin/publishJS...buildGatewayBusEvent— Construct aGatewayBusEventenvelope with the standardid+tsfields populated. Publishers should use this rather than building envelopes inline so that the id generation + timestamp shape s...buildHostRuntimeEnvPolicy— 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...createBusPublishHandler— Build aPOST /admin/publishhandler that injects events onto the bus from operator tooling. Returnsnullfor non-matching paths. Body shape (generic — Matrix, Slack, GitHub bridges all share th...createBusSubscribeHandler— Build aGET /eventsSSE handler that streams every bus event to subscribed clients. Returnsnullfor non-matching paths so the caller can fall through to the next handler.createEnsureSessionCoordinatorcreateGatewayBus— Create a new in-process gateway bus. Each call returns an independent bus instance — typical gateway deployments instantiate exactly one and pass the handle to publishers and transport adapters.createGatewaySurfaceBroadcastercreateGatewayTestServer— 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...publishBridgeEventToBus— In-process convenience: build the envelope and publish it on the supplied bus. Returns the envelope so callers can inspect or assert on the server-populatedid+tsfields. Out-of-process bridg...publishHarnessCardChanged— Publish agateway.harness.card-changedevent onto the bus. Callers are responsible for diffing — this publisher does not. Including bothpreviousEntryandnewEntryin the payload keeps subscr...publishHarnessChildExited— Publish agateway.harness.child-exitedevent onto the bus. Thecrashboolean on the payload distinguishes gateway-initiated teardown from unexpected exit; both flow through this single publishe...publishHarnessChildSpawned— Publish agateway.harness.child-spawnedevent onto the bus. The source principal is annotated as{ kind: "harness", id: harnessId }so subscribers can route per-harness without inspecting the p...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).wrapAuditEmitterAsBusPublisher— Wrap an existing {AuditEmitter} so every recorded event is also published on the gateway bus. The wrapped emitter has the same shape as the underlying one — callers swap it in at construction and n...
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...BuildBridgeBusEventOptions— Options for {buildBridgeBusEvent}.BusEndpointOptions— Common construction options.CreateBusPublishHandlerOptions— Admin publish handler options.CreateBusSubscribeHandlerOptions— SSE subscribe handler options.CreateGatewayBusOptions— Optional construction-time hooks.GatewayBus— Public surface of the bus primitive.GatewayBusEvent— Typed envelope for every gateway bus event.GatewayHarnessCardChangedPayload— Payload forgateway.harness.card-changedbus events. Emitted when the per-harness slice ofcapabilities.harnesseschanges after subscribed lifecycle events (mode_changed, `permission_gating_s...GatewayHarnessChildExitedPayload— Payload forgateway.harness.child-exitedbus events. Emitted when the ACP child for a curated harness exits — either as part of gateway-initiated teardown (crash: false) or unexpectedly (`crash...GatewayHarnessChildSpawnedPayload— Payload forgateway.harness.child-spawnedbus events. Emitted when the gateway successfully spawns an ACP child process for a curated harness (whether eagerly at startup or lazily on first routed...GatewaySurfaceBroadcaster— Adapter that plugs into the ACP host session and, once attached to a live broadcaster, forwards every lifecycle message to that broadcaster.GatewaySurfaceBroadcasterConfigGatewayTestServerHandleGatewayTestServerOptionsHarnessFleetEntry— One entry in the operator-configured harness fleet.primary: truemarks the default routing target; {HarnessLaneManager.getPrimaryHarnessId} reads the (validated single) primary out of the entrie...HarnessLaneManagerOptions— Constructor options for {HarnessLaneManager}. Pass the livegatewayCardreference (the manager mutatescapabilities.harnessesin place), the in-processbus, and acreateControllerfactory t...HostA2AExecutorOptionsHostSessionHostSessionConfigIdentityPrincipal— Identity principal slot. Placeholder until the agents-js/identity phase-1 types land — at that point this alias is replaced with the imported type. Kept loose (open record) so the eventual replacem...PublishBridgeEventToBusOptions— Options for {publishBridgeEventToBus}.RunSessionOptionsRunSessionResult— 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...WrapAuditEmitterAsBusPublisherOptions— Options for the audit-emitter wrapper publisher.WSBridgeConfigWSBridgeHandle
Types
AgentRegistryMap— Name-keyed agent map used by the gateway's dispatch path.AuditEmitterAuditEventAuditEventInputAuditLoggerCorrelationIdGatewayBusSubscriber— Subscriber callback shape. Receives every published event.GatewayBusUnsubscribe— Unsubscribe handle returned fromsubscribe.GatewayHostControllerRuntimeSwitchOriginSurfaceBroadcastFn— 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
