Skip to main content

enterprise_ai.channels.bridge

Source: sdks/python/src/enterprise_ai/channels/bridge.py. Back to the Python SDK reference index.

note

This page is generated by tools/docs/gen_sdk_reference.py from the SDK sources and the OpenAPI text folders. Do not edit it by hand: change the source and regenerate.

Class ChannelBridgeError​

The channel cannot be bridged (no Navin connection, missing secret resolver, adapter not installed).

EaiError

Model Inbound​

An inbound message, whatever bus produced it.

Fields:

NameTypeRequiredDescription
textstryesText of the message.
userstryesSender of the message (sender_id or sender of the bus message, user by default).
conversation_idstryesConversation the message belongs to (up to 200 characters). A new one is generated when omitted.
metadatadict[str, Any]noFree key-value pairs stored with the object and returned as they are; the platform never interprets them.

Inbound.of​

of(message: Any) -> Inbound

Build an Inbound from a bus message read by attribute: content, sender_id or sender, chat_id or session_id, metadata.

NameTypeDefaultRequiredDescription
messageAnyyesMessage of the Navin bus or of enterprise_ai.runtime.bus; without text content ChannelBridgeError is raised.

Returns: Inbound. A Inbound: An inbound message, whatever bus produced it.

Raises: ChannelBridgeError.

Class ChannelBridge​

Relay between a Navin channel adapter and the channel name of the platform.

Attributes:

NameTypeRequiredDescription
adaptertuple[str, str]yesModule and class of the Navin adapter, split from spec.connection.adapter ("<module>:<class>").
channelyesThe channel as returned by channels.get(name).
clientyesPlatform client used for the channel, runs and sessions calls.
connectionyesThe spec.connection of the channel manifest: provider, adapter, settings, secret_refs.
nameyesName of the bridged platform channel.
outbound_factoryyesFunction building the outbound messages published on the bus.
poll_intervalyesSeconds between two reads of the run state.
resolve_secretyesFunction resolving the secret references of the connection.
timeoutyesMaximum wait in seconds for a run to stop.

Constructor ChannelBridge​

ChannelBridge(client: Any, name: str, resolve_secret: Callable[[str], str] = env_resolver, outbound_factory: Callable[[str, str, str, dict[str, Any]], Any] | None = None, poll_interval: float = 1.0, timeout: float = 300.0) -> None

Read the channel name and keep its spec.connection; raises ChannelBridgeError when it is not a Navin connection (provider: navin, adapter: "<module>:<class>").

NameTypeDefaultRequiredDescription
clientAnyyesParent client.
namestryesName of the platform channel to bridge.
resolve_secretCallable[[str], str]env_resolvernoFunction turning a secret reference of secret_refs into its value; default env_resolver (env://NAME only).
outbound_factoryCallable[[str, str, str, dict[str, Any]], Any] | NoneNonenoBuilds the outbound message from (channel, chat_id, content, metadata); default a BusMessage sent by assistant.
poll_intervalfloat1.0noSeconds between two reads of the run state while waiting for the replies (default 1).
timeoutfloat300.0noMaximum wait in seconds for the run to stop (default 300); past it ChannelBridgeError is raised.

Raises: ChannelBridgeError.

ChannelBridge.adapter_config​

adapter_config() -> dict[str, Any]

Configuration of the Navin adapter: settings plus resolved secrets, enabled true. Dotted names (dm.allowFrom) become nested objects, as the Navin configuration expects.

This element takes no parameter.

Returns: dict[str, Any]. Configuration dict given to the adapter class.

ChannelBridge.handle​

async handle(message: Any, bus: Any) -> dict[str, Any]

Relay one message and publish the replies on bus (publish_outbound).

NameTypeDefaultRequiredDescription
messageAnyyesInbound message of the bus, read by attribute (content, sender_id, chat_id, metadata).
busAnyyesMessage bus of the adapter; replies go out through its publish_outbound.

Returns: dict[str, Any]. Answer of POST /v1/channels/{name}/inbound (session_id, run_id, message_id).

ChannelBridge.load_adapter​

load_adapter(bus: Any, config_factory: Callable[[dict[str, Any]], Any] | None = None) -> Any

Instantiate the Navin adapter class (navin.channels.<module>) on bus; needs the navin package.

NameTypeDefaultRequiredDescription
busAnyyesMessage bus given to the adapter.
config_factoryCallable[[dict[str, Any]], Any] | NoneNonenoOptional function turning the adapter_config dict into the configuration object the adapter expects.

Returns: Any. The adapter instance; ChannelBridgeError when the navin channels are not installed.

Raises: ChannelBridgeError.

ChannelBridge.relay​

relay(message: Any) -> dict[str, Any]

Post an inbound message. Delivers a message from an end user (202) and returns session_id, session_created, message_id, run_id (or run_skipped when the agent is not active) and the DLP result. Needs tenant_admin, developer or agent. Steps: 1. The channel must be active (409 channel_disabled); a signed_webhook channel checks X-EAI-Signature (t=<unix seconds>,v1=<hex HMAC-SHA256 of "<t>." + raw body>, 5 minute window; 401 invalid_signature). 2. The policy channel.inbound is evaluated; size (413 message_too_large) and rate per user (429 rate_limited) are checked. 3. Inbound DLP runs (default detect; block answers 403 dlp_blocked, mask stores the masked text). 4. The open session of the user and conversation is reused, or a new one opened (429 too_many_sessions, 409 session_closed past max_session_minutes). 5. The message is added and a run of the channel agent starts with trigger channel.

Route: /v1/channels/{name}/inbound (POST).

NameTypeDefaultRequiredDescription
messageAnyyesStatus message (up to 2000 characters).

Returns: dict[str, Any]. Decoded JSON answer of the operation "Post an inbound message".

Raises: the typed errors of the transport (Errors).

ChannelBridge.replies​

replies(accepted: dict[str, Any]) -> list[str]

Assistant messages of the session written after the inbound message, once the run stopped.

NameTypeDefaultRequiredDescription
accepteddict[str, Any]yesAnswer of the inbound call, with session_id, run_id and message_id.

Returns: list[str]. Texts of the replies in order; empty when the answer has no session or run.

Raises: ChannelBridgeError.

ChannelBridge.run​

async run(bus: Any, stop: asyncio.Event | None = None) -> None

Consume bus.consume_inbound() until stop is set, relaying every message.

NameTypeDefaultRequiredDescription
busAnyyesMessage bus to consume (consume_inbound) and to answer on (publish_outbound).
stopasyncio.Event | NoneNonenoasyncio.Event that ends the loop once set; default a new event never set.

Returns: None.

Functions​

env_resolver​

env_resolver(ref: str) -> str

Resolve env://NAME from the process environment.

NameTypeDefaultRequiredDescription
refstryesSecret reference, env://NAME; any other scheme raises ChannelBridgeError.

Returns: str. Value of the environment variable; ChannelBridgeError when it is not set.

Raises: ChannelBridgeError.