Publish an atomic capability
Use an atomic export when another engine should import one capability without evaluating a complete library bundle. The package publishes a descriptor with a default ID; the consuming engine still owns dependencies and the final effective ID.
This recipe follows the community-capabilities fixture.
Build the export
Section titled “Build the export”-
Create the capability through a dependency factory
export function createClassifyTicket(dependencies: ClassifyTicketDependencies,) {return defineCapability({description: "Classify one support ticket.",input: z.object({ ticketId: z.string().min(1) }),output: ticketClassificationSchema,access: createTicketAccessRule(dependencies.permissions),async run({ input, context }) {const ticket = await dependencies.tickets.findById(input.ticketId,);return dependencies.classifier.classify(ticket, {signal: context.signal,});},});} -
Wrap it in
defineExportedCapabilityimport { defineExportedCapability } from "@invokta/core";export function createClassifyTicketExport(dependencies: ClassifyTicketDependencies,) {return defineExportedCapability({source: {name: "@acme/support-capabilities/classify-ticket",version: "1.0.0",},defaultId: "support.classify-ticket",capability: createClassifyTicket(dependencies),});}The source strings exist for deterministic diagnostics. They do not install, resolve, verify, or sandbox the package.
-
Publish the subpath
{"name": "@acme/support-capabilities","version": "1.0.0","type": "module","sideEffects": false,"exports": {".": {"types": "./dist/index.d.ts","import": "./dist/index.js"},"./classify-ticket": {"types": "./dist/classify-ticket.d.ts","import": "./dist/classify-ticket.js"}}}Keep
src/classify-ticket.tsfree of imports from a library bundle. Node can then resolve and evaluate the atomic subpath on its own. -
Import it into an engine
import { importCapability } from "@invokta/core";import {createClassifyTicketExport,} from "@acme/support-capabilities/classify-ticket";const imported = importCapability(createClassifyTicketExport(dependencies.support),{ as: "operations.classify-ticket" },);Omit
asto keepsupport.classify-ticket. Providing it replaces the default ID rather than publishing an alias.
Run it
Section titled “Run it”Build the fixture and the engine that imports its root and subpath exports:
yarn workspace @invokta/example-community-capabilities buildyarn workspace @invokta/example-composed buildnode examples/composed-engine/dist/cli.js listThe list contains community.score-ticket-priority from the package root and
operations.classify-ticket from the remapped subpath. The default
community.classify-ticket ID is absent.
Verify it
Section titled “Verify it”The fixture tests import the built package through its real Node export map and confirm the atomic subpath does not evaluate the library:
yarn workspace @invokta/example-community-capabilities testyarn workspace @invokta/example-community-capabilities typecheckyarn workspace @invokta/example-community-capabilities buildRead the complete
community-capabilities
fixture for the root export, isolated subpath, package-resolution tests, ports,
and domain capability definitions.