Meshpocalypse Semantic
    Preparing search index...

    Class SwarmNode

    SwarmNode — minimal mesh participant.

    Wraps MeshNode with a small, ergonomic API focused on the three core operations: connect, publish, and discover. Advanced capabilities (circuit breaker, packet history, module registry) remain accessible via the SwarmNode.meshNode escape hatch.

    Index

    Constructors

    Accessors

    • get mcpBootstrap(): McpServerBootstrap | null

      The active McpServerBootstrap instance, if an MCP server was started. Returns null when no MCP server is running.

      Returns McpServerBootstrap | null

    Methods

    • Run a capability auction and return the auction result (or null if no agents bid within the collection window).

      Convenience wrapper over AuctionOrchestrator. Generates a taskId automatically when one is not provided (UUID v4).

      Parameters

      • task: Omit<AuctionTask, "taskId"> & { taskId?: string }

        Task description. taskId is optional; one will be generated if omitted.

      • Optionalgraph: MeshGraph

        SPARQL graph for persisting bid records. Defaults to a NullMeshGraph (no persistence).

      • OptionalauctionConfig: AuctionConfig

        Optional AuctionConfig overrides.

      Returns Promise<AuctionResult | null>

      AuctionResult with winner + all bids, or null if no bids.

      const result = await node.auction({
      requiredCapabilities: ['summarise', 'search'],
      });
      if (result) console.log('Task routed to:', result.winner);
    • Connect to NATS and register agent capabilities in the mesh.

      After calling connect(), the node is reachable by other mesh participants and will receive messages on any subjects it subscribes to via SwarmNode.subscribe.

      Capabilities are announced via a fire-and-forget publish to mesh.agent.register. If a graphUrl was provided in config, the capabilities are also written to the Oxigraph RDF store via a SPARQL UPDATE over HTTP.

      Returns Promise<void>

      If the NATS connection fails.

    • Gracefully disconnect from the mesh.

      Stops all background sweeps, disposes reliability components, and closes the underlying NATS connection. If an MCP HTTP server was started via the mcp config option, it is always stopped (and awaited) before this method returns.

      Returns Promise<void>

    • Discover agents that advertise a given capability.

      Sends a NATS request to mesh.capabilities.query and returns the list of agent IDs that responded with the requested capability. Falls back to an empty array if no responder is available within the timeout.

      Parameters

      • capability: string

        Capability name to search for (e.g. 'search').

      Returns Promise<string[]>

      Array of agent ID strings that have the capability.

    • Publish an event to the mesh.

      The data argument is serialised to JSON and published as UTF-8 bytes to the given NATS subject.

      Parameters

      • subject: string

        NATS subject to publish on (e.g. 'task.result').

      • data: unknown

        JSON-serialisable payload.

      Returns Promise<void>

      If the node is not connected.

    • Publish a confidence score for this agent to the mesh confidence signal bus.

      Convenience wrapper over ConfidenceBus.publish. Pass a ConfidenceBus instance (created with the underlying NATS connection) and an optional taskId for correlation.

      Data collection only — does not alter ATF trust levels (Phase 4).

      Parameters

      • bus: ConfidenceBus

        The ConfidenceBus to publish on.

      • score: number

        Confidence score in [0.0, 1.0].

      • OptionaltaskId: string

        Optional task ID for correlation.

      Returns Promise<void>

      const bus = new ConfidenceBus(natsConnection);
      await node.publishConfidence(bus, 0.92, 'task-xyz');
    • Subscribe to a NATS subject.

      The handler receives the decoded JSON payload. Returns an unsubscribe function; call it to cancel the subscription.

      Parameters

      • subject: string

        NATS subject to subscribe to.

      • handler: (data: unknown) => void

        Callback invoked with the parsed JSON payload.

      Returns () => void

      A zero-argument function that cancels the subscription.

      const unsubscribe = node.subscribe('task.result', (data) => {
      console.log('Received:', data);
      });

      // Later:
      unsubscribe();