• Emits a custom event to the swarm bus service.

    This function sends a custom event with a specified topic and payload to the swarm's bus service, allowing clients to broadcast messages for other components to listen to. It is wrapped in beginContext for a clean execution environment and logs the operation if enabled. The function enforces a restriction on reserved topic names (defined in DISALLOWED_EVENT_SOURCE_LIST), throwing an error if a reserved topic is used. The event is structured as an ICustomEvent with the provided clientId, topicName as the source, and payload.

    Type Parameters

    • T extends unknown = any

      The type of the payload, defaulting to any if unspecified.

    Parameters

    • clientId: string

      The clientId parameter.

    • topicName: string

      The topicName parameter.

    • payload: T

      Payload object containing the data to be processed.

    Returns Promise<void>

    If the topicName is a reserved event source (e.g., "agent-bus", "session-bus").

    await event("client-123", "custom-topic", { message: "Hello, swarm!" });
    // Emits an event with topic "custom-topic" and payload { message: "Hello, swarm!" }