@agents-js/gateway-runtime
v0.4.0
Published
Gateway runtime config, env parsing, runtime registry/detection, install descriptors, and sub-session spawn helpers.
Maintainers
Readme
@agents-js/gateway-runtime
Gateway runtime config, env parsing, runtime registry/detection, install descriptors, and sub-session spawn helpers.
Installation
bun add @agents-js/gateway-runtimeAPI
Classes
SpawnSubSessionTimeoutError— Sentinel error used to disambiguate timeout vs ACP-layer error in the catch block. Exposed for tests that want to assert on it.
Functions
applyGatewayRuntimeProfileapplyRuntimeEnvOverrides— Apply merged overrides back intoprocess.envso downstream helpers that readprocess.envdirectly (e.g.resolveRuntimeArgs) observe the merged values. Returns a restore function that reverts ...buildExtendedPath— Merge {DEFAULT_EXTRA_BIN_PATHS} (plus any caller-supplied extras) onto a basePATHstring, de-duplicating while preserving order. Existing entries keep their position; new entries append in list ...createAcpHarness— Factory for building a well-formed {GatewayRuntimeDefinition}. The curated ACP harnesses are constructed via this factory so the per-harness duplication (binary name + install metadata + auth env k...createRuntimeSelectionFromArgsdetectInstalledGatewayRuntimesgenerateSpawnCorrelationId— Generate a stable-looking session id for callers that spawn multiple children and want local ordering even when the gateway's own session_id isn't yet assigned (e.g. when a harness_unavailable shor...getAgentsJsConfigPathsgetCliVersion— Helper for CLI bin scripts to read their package's version without triplicating string literals that drift from the actual published version. Usage from a bin script (one level deep, e.g. `packages...getConfiguredProfile— Wraps the internal profile lookup in the gateway-runtime config-paths shape so existing callers do not have to unpackloaded.configPaths.{user,project}ConfigPaththemselves. The returned profile ...getGatewayRuntimeDefinitionlistGatewayRuntimeIdsloadAgentsJsConfigmergeAgentsJsConfigmergeRuntimeEnvOverridesparseAgentsJsConfigparseCustomArgsJsonresolveAcpAgentEntryToRuntime— Bridge an ACP registry entry to a {ResolvedGatewayRuntime} suitable for passing toACPSessionController.start(). Used by the gateway's ACP-kind@path to spawn an ephemeral per-dispatch runtime.resolveAndApplyGatewayRuntime— Apply env overrides, resolve a runtime selection, optionally apply a configured runtime profile, and restore env. Returns the (optionally profile-merged)ResolvedGatewayRuntime. Errors thrown by ...resolveExistingCommandPathresolveGatewayRuntimeresolveGatewayRuntimeCommandresolveGatewayRuntimeProfile— Materialize a {GatewayRuntimeProfile} via the internal profile resolver. The narrower {GatewayRuntimeId} is preserved on the returned {ResolvedGatewayRuntimeProfile}.resolveGatewayRuntimeSelectionresolveRuntimeArgs— Resolve the runtime argv for a curated definition, honoring env-based overrides.runCommandspawnSubSession— Spawn a bounded-mode subagent session, run the subtask, return the terminal summary. See module-level docstring for v1 scope. Intentional invariant: cleanup runs on every path. The spawned child pr...writeAgentsJsConfig
Interfaces
AcpAgentEntryInput— Structural shape required byresolveAcpAgentEntryToRuntime. Defined locally (rather than imported from-js/a2a-client/node) to avoid introducing a new workspace dependency from `gateway-runtime...AgentsJsConfigAgentsJsConfigPathsAgentsJsServeConfigConfigPathOptionsCreateAcpHarnessInput— Input shape for {createAcpHarness}. Collocates the fields that a curated ACP harness needs to declare in one call site — binary name, npm package metadata, install hint, optional auth env keys, run...CuratedGatewayRuntimeSelectionCustomGatewayRuntimeSelectionGatewayRuntimeDefinitionGatewayRuntimeInstallGatewayRuntimeProfile— Gateway-runtime-flavored {RuntimeProfile}: identical shape, but theruntimefield is narrowed to {GatewayRuntimeId} so the curated runtime registry is the source of truth for legal harness ids in...GatewayRuntimeResolveArgsInputLoadedAgentsJsConfigProfileLookupContextResolveAndApplyGatewayRuntimeOptionsResolvedGatewayRuntimeResolvedGatewayRuntimeACPOptions— Host-flavored {ACPProcessOptions} used for wiring resolved gateway runtimes into-js/acp-host'screateHostACPProcess. Mirrors theHostACPProcessOptionsinterface exported from-js/acp-host...ResolvedGatewayRuntimeProfile— Gateway-runtime-flavored {ResolvedRuntimeProfile}, narrowed so that thedefinition.runtimefield carries {GatewayRuntimeId}.RunCommandOptions— CanonicalrunCommandhelper used by every gateway-runtime adjacent package (reporting,extras, future call sites). WrapsBun.spawnwith composable timeout + abort + stdin support and a unif...RunCommandResultRuntimeCommandResolverRuntimeEnvOverrides— runtime-env-overrides.ts — Apply CLI-flag overrides onto a process env bag. The gateway runtime helpers (resolveRuntimeArgs,internal-gatewayconfig loader, etc.) read AJS_* environment variabl...RuntimeResolutionOptionsRuntimeSelectionArgsSpawnSubSessionHints— Routing hints. All fields optional.harnessis explicit opt-in to a specific execution boundary; unset falls back to the default.worktree_isolation/modelare accepted in the shape for forw...SpawnSubSessionOptions— Dependency injection seams. All optional; defaults wire production behavior. Tests that don't supply these get real filesystem + real subprocess spawn.SpawnSubSessionParams— Input to {spawnSubSession}.parent_session_idis carried so downstream trace / audit surfaces can attribute the child to its spawning session; this layer does not enforce depth limits on it.SpawnSubSessionResult— Result of a bounded-mode {spawnSubSession} call.session_idis the ACP session id of the spawned child (empty string when the call short-circuited before session creation, e.g. harness_unavailabl...
Types
EnvSourceGatewayRuntimeIdGatewayRuntimeProfileRoots— Gateway-runtime alias for internal runtime profile roots. The shape is preserved so existing downstream imports keep compiling without churn.GatewayRuntimeSelectionHarnessSelectionPolicyResolveGatewayRuntimeFn— Runtime resolver shape. Factored out so tests can inject a resolver that returns cannedResolvedGatewayRuntimevalues without touching the filesystem.SpawnACPAgentFn— Abstraction overspawnACPAgentfor test injection. Shape matches the imported function; tests substitute a fake that returns a controlledStream/killhandle.SpawnSubSessionStatus— Terminal status of a {spawnSubSession} call. -completed— subagent returned anend_turnstopReason within the timeout. -errored— subagent returned a non-end_turnstopReason, or the ACP h...
Constants
CLAUDE_AGENT_ACP_PACKAGE_NAMECLAUDE_AGENT_ACP_VERSIONCODEX_ACP_PACKAGE_NAMECODEX_ACP_VERSIONDEFAULT_AGENTS_JS_CONFIGDEFAULT_EXTRA_BIN_PATHS— Browser-safe entry point for -js/gateway-runtime. The main entry (src/index.ts) pulls in runtime-registry + detection machinery that depends onstyleTextfromnode:util, which Bun's browser pol...defaultRuntimeCommandResolverEXTERNAL_RUNTIME_INSTALL_VERSIONS— Generated from the rootpackage.json(agentsJs.externalSDKs) byscripts/bump.ts. Do not edit manually.GATEWAY_RUNTIME_REGISTRY— Curated runtime registry, exposed as a read-onlyRecordso the selection layer can iterate and look up entries. The type is widened from the literalas constshape toReadonly<Record<…>>so d...HOME_PLACEHOLDER— Default directories the gateway prepends toprocess.env.PATHwhen resolving runtime binaries via the resolver in./runtime-command-resolution.ts. The host composition layer threads this list in...MOCK_ACP_RUNTIME_ENV— Env var that gates registration of the in-repomock-acpruntime in {listGatewayRuntimeIds}. Surfaced as a constant rather than an inline string so tests and consumers can reference the same key.SPAWN_SUB_SESSION_DEFAULT_HARNESS— Default harness used whenhints.harnessis unspecified.SPAWN_SUB_SESSION_DEFAULT_TIMEOUT_MS— Default subtask timeout (5 minutes).SPAWN_SUB_SESSION_SUPPORTED_HARNESSES— Harness ids supported byspawnSubSessionv1. Expand this set as harnesses land hardening gates for subagent spawning.validateGatewayRuntimeProfileName— Re-export of {validateRuntimeProfileName} from the internal profile resolver. The gateway-runtime alias is preserved for callers that import via this package's barrel.
Exports
createParseEnvEnvErrorOptionalEnvVarparseEnvRequiredEnvVar
Dependencies
@agentclientprotocol/sdk@agents-js/a2a@agents-js/acp
License
MIT
