Fetch Adapter API Reference

June 16, 2026 ยท View on GitHub

AutoContext's public Fetch/ESM adapter lives at autoctx/control-plane/agent-app-fetch. It exposes the same agent-app manifest and invocation wire shape as the TypeScript control-plane Node target while remaining a generic Request to Response seam. Host code owns runtime, workspace, storage, command, tool, and environment capabilities and passes them explicitly.

Import Path

import {
  createAgentAppFetchHandler,
  planAgentAppFetchCatalog,
  renderAgentAppFetchEntrypointTemplate,
} from "autoctx/control-plane/agent-app-fetch";

The subpath is the supported package boundary for Fetch helpers. Importing from source files is not required for generated handlers, conformance cases, or host capability manifests.

Handler Surface

Use createAgentAppFetchHandler(options) when host code already has a static catalog and wants a Request to Response handler. The lower-level handleAgentAppFetchRequest() is exported for wrappers that need to prepare the resolved environment/workspace before dispatching a single request.

Core handler types and helpers:

APIPurpose
AgentAppFetchHandlerOptionsOptions accepted by the handler and wrapper conformance helpers.
AgentAppFetchCatalogEntryStatic or lazily loaded agent handler catalog entry.
createStaticAgentAppCatalogClones already-loaded handler entries into a Fetch catalog.
createAgentAppFetchHandlerBuilds the generic Fetch handler from a catalog plus explicit capabilities.
handleAgentAppFetchRequestDispatches one request when a wrapper has already normalized options.
AgentAppFetchManifestManifest envelope returned by GET /manifest and GET /agents.
AgentAppFetchSuccessEnvelopeSuccessful invocation envelope returned by POST /agents/:agent/invoke.
AgentAppFetchErrorEnvelopeStable error envelope for missing agents, invalid bodies, and handler errors.

Supported routes are:

  • GET /manifest
  • GET /agents
  • POST /agents/:agent/invoke

Accepted host-created capability keys are env, runtime, runtimeFactory, runtimeFactoryName, runtimeFactoryPlan, runtimeFactoryModuleMap, workspace, workspaceStore, commands, tools, eventStore, sessionEventStore, eventSink, and maxBodyBytes.

Catalog And Entrypoint Planning

Build tooling should provide explicit catalog entries. The runtime handler does not discover files.

APIPurpose
planAgentAppFetchCatalogValidates and normalizes explicit .autoctx/agents entries into a deterministic plan.
createAgentAppFetchCatalogFromModuleMapTurns a plan plus a static module map into lazy catalog entries.
renderAgentAppFetchModuleMapEntrypointEmits a small ESM module-map entrypoint that directly creates fetch.
renderAgentAppFetchEntrypointTemplateEmits the generated Fetch entrypoint template with manifest and factory exports.
AGENT_APP_FETCH_ROUTESCanonical route list used by catalog plans and manifests.

renderAgentAppFetchEntrypointTemplate() is the preferred packaging helper for generated Fetch bundles because it emits the catalog plan, static module map, host capability manifest, and createAgentAppFetchEntrypoint() factory in one ESM source string.

Runtime Factory Helpers

Runtime factories let generated entrypoints bundle a static set of runtime factory modules while preserving explicit host capability precedence.

APIPurpose
planAgentAppFetchRuntimeFactoriesValidates and normalizes explicit .autoctx/runtimes entries into a deterministic plan.
createAgentAppFetchRuntimeFactoryFromModuleMapResolves a named runtime factory from a static module map.
createAgentAppFetchLazyRuntimeWraps a runtime factory so the runtime is created only on first prompt/revise use.

Precedence is fixed: direct runtime wins over runtimeFactory, and direct runtimeFactory wins over runtimeFactoryName. Named factories should be selected from runtimeFactoryPlan plus runtimeFactoryModuleMap, never from an ambient module lookup. See ts/examples/generated-fetch-runtime-factory-packaging.ts for a typed generated Fetch packaging example with bundled named runtime factories.

Host Capability Manifest

Generated packages can emit a manifest and schema so host wrappers can validate which capabilities the generic Fetch handler accepts.

APIPurpose
createAgentAppFetchHostCapabilityManifestBuilds the machine-readable manifest from a catalog plan.
renderAgentAppFetchHostCapabilityManifestSerializes the manifest as pretty JSON with a trailing newline.
agentAppFetchHostCapabilityManifestSchemaJSON Schema object for the manifest contract.
renderAgentAppFetchHostCapabilityManifestSchemaSerializes the schema as pretty JSON with a trailing newline.
AGENT_APP_FETCH_ACCEPTED_HOST_CAPABILITIESCanonical accepted capability key list.
AGENT_APP_FETCH_UNSUPPORTED_DEFAULTSCanonical list of defaults intentionally not provided by the generic adapter.

The unsupported-default list documents that the generated handler does not add runtime filesystem discovery, ambient environment capture, local shell execution, host deployment configuration, or commercial orchestration behavior. See fetch-host-capability-manifest.md for manifest JSON and schema validation examples.

Workspace And Session Stores

The Fetch adapter exports provider-neutral store contracts and in-memory references for tests, examples, and pure handlers.

APIPurpose
AgentAppFetchWorkspaceStoreVirtual workspace store contract for files, directories, and metadata.
createAgentAppFetchWorkspaceEnvAdapts a workspace store to the shared runtime workspace surface.
createInMemoryAgentAppFetchWorkspaceStoreIn-memory reference workspace store.
createEdgeInMemoryWorkspaceEnvConvenience in-memory workspace environment for Fetch-compatible runtimes.
AgentAppFetchSessionEventStoreRuntime-session event-store contract with idempotent append and replay.
createAgentAppFetchSessionEventStoreBridgeBridges a session event store into the runtime event-store adapter shape.
createInMemoryAgentAppFetchSessionEventStoreIn-memory reference session event store.

The in-memory references are useful defaults but do not imply persistence across requests. Hosts that need persistence should pass workspaceStore and sessionEventStore explicitly.

Conformance Helpers

Conformance helpers are framework-agnostic. Case factories return named async cases; one-shot runners execute the same cases without assuming a test runner.

APIPurpose
createAgentAppFetchWorkspaceStoreConformanceCasesWorkspace store case factory.
runAgentAppFetchWorkspaceStoreConformanceOne-shot workspace store runner.
createAgentAppFetchSessionEventStoreConformanceCasesSession event-store case factory.
runAgentAppFetchSessionEventStoreConformanceOne-shot session event-store runner.
createAgentAppFetchInvocationConformanceCasesInvocation wrapper case factory.
runAgentAppFetchInvocationConformanceOne-shot invocation wrapper runner.

See fetch-conformance.md for case details, failure modes, and runner examples, fetch-troubleshooting.md for common host wiring failures, and ts/examples/fetch-conformance-host-wrapper.ts for a typed executable wrapper example.

Generated Entrypoint Contract

A source string emitted by renderAgentAppFetchEntrypointTemplate() exports:

  • agentAppFetchCatalogPlan
  • agentAppFetchModuleMap
  • agentAppFetchCatalog
  • agentAppFetchRuntimeFactoryPlan when runtime factories are planned
  • agentAppFetchRuntimeFactoryModuleMap when runtime factories are planned
  • agentAppFetchHostCapabilityManifest
  • createAgentAppFetchEntrypoint(hostCapabilities?)
  • fetch
  • a default object containing fetch

createAgentAppFetchEntrypoint() forwards host-created capabilities to createAgentAppFetchHandler(). When the generated source includes runtime factory entries, it can resolve runtimeFactoryName through the static runtime factory module map lazily. Direct runtime and runtimeFactory capabilities still take precedence over named factory selection.

Boundary Guarantees

The Fetch adapter remains a generic OSS seam:

  • handler and runtime catalogs are explicit build-step inputs;
  • request handling uses static catalogs/module maps and no request-time file discovery;
  • environment data is passed through env rather than captured ambiently;
  • runtime factories are host-created capabilities or selected from static module maps;
  • shell execution is unavailable unless a host deliberately supplies safe command grants;
  • host deployment descriptors, fleet policy, storage bindings, and commercial orchestration stay outside this package.

For packaging guidance, see generated-fetch-packaging.md. For wrapper and store verification, see fetch-conformance.md. For common host wiring failures, see fetch-troubleshooting.md.