Skip to main content

Module channels

Module channels 

Source
Expand description

The chat channel contract (spec 3.3 §5.3, §10 K1, §11 S-I5, S-I6, S-I10; feature channels).

A chat thread is the doorbell and the conversation: a paired account talks to its agents, gets decision cards, says yes once or no, and stops everything. The kernel owns the rules; a platform adapter (Telegram first, in adk-surface) only moves messages. An adapter implements ChannelSink for what goes out and hands what comes in to ChannelGateway::receive as a ChannelInbound; it passes the contract suite in conformance::channel_contract (feature conformance).

RuleWhat the gateway does
Only paired accounts reach an agent (S-I6)An unpaired account’s message, or answer, gets a pairing code (ChannelNotice::PairingCode) and starts nothing; the person accepts the code where the kernel runs (adk-rust pair accept, POST /api/kernel/channels/pair)
One code per account, at most so many waitingThe gateway serializes unpaired accounts’ messages, so concurrent messages from one account get one code and the waiting limit holds; the operator dismisses a waiting account (adk-rust pair revoke, POST /api/kernel/channels/waiting/{id}/dismiss), which then gets no code for DISMISSED_FOR
A paired account’s message is a turnIt starts a turn as the paired person, a Human subject, in the thread’s session, keyed by the platform’s message id so a redelivery starts nothing; the turn’s reply goes back to the same thread, from whichever replica ran it
A message for a running turn reaches it (spec 3.3 §6 “steer”)While the thread’s turn runs on this host, the gateway hands the message to that turn (ChannelHost::steer, InboundOutcome::Steered): its agent takes it at its next safe point and its reply answers it. A turn that ends first hands the message back, and it starts the thread’s next turn under the message’s idempotency key, once. A turn another replica runs is handed nothing: the message starts a turn behind it. A redelivery of a message handed to a turn is recognised by the replica that took it
A removed account reaches no agentRemoving it stops its turns that have not finished, those queued behind the thread’s session included
Cards carry no arguments (S-I5)A DecisionCard holds the agent, a short summary with every argument value masked, and the risk; never the call’s arguments
Chat says yes once or no, never money (§7.2, §7.4)Answers are ChannelAnswer::AllowOnce and ChannelAnswer::Deny at low and medium risk only, through ApprovalService::decide with the version the card showed (S-I2); a call that moves money (ChannelHost::moves_money, ChannelGatewayBuilder::money_tools) and high risk link to the home — high as the request rates it, or as the host does (ChannelHost::rates_high) — and a take-over, whose secret is typed in the home (§8.2), can only be denied
Only who may answer gets buttonsA card goes to the decision’s person when the policy lets that person answer it, and its answers only when chat may decide it
A second answer is shown, never retried (S-I2)A version conflict answers ChannelNotice::AlreadyDecided, or a fresh card when the decision still waits; an answer that counts toward a quorum, or one from someone the policy does not ask, answers ChannelNotice::WaitingForOthers
Stop all from anywhere; resume only at home (S-I10)“stop all” freezes the kernel and answers StopNotice; “resume” is refused with ChannelNotice::ResumeRefused
Nothing notifies during quiet timeA card for a decision asked during quiet time is delivered when quiet time ends, if it still waits: the quiet time of the decision’s area in force, a change made while the kernel runs included (ChannelHost::quiet_ends)
Every waiting decision reaches the threadEvery minute the gateway rings the decisions still waiting, so a card that could not be sent is sent again, and one held on another replica is sent too
A host may decide first (spec 3.5 §10 X12)An InboundRoute set with ChannelGatewayBuilder::route sees each message, with the account’s pairing, before the gateway: a message it takes gets no pairing code and starts no turn (InboundOutcome::Routed). A served site sends strangers to its Inbox this way
Files ride with a messageChannelInbound::attachments, downloaded by the adapter; never in a turn’s input. A paired account’s message with no words starts no turn (InboundOutcome::Empty)

Every answer, pairing request, notification, stop and refusal writes a kernel.channel audit record with surface: chat, the channel and the account, before it acts.

Backend of ChannelBindingStoreTypeFeature
In-memoryInMemoryChannelBindingStore—
SQLiteSqliteChannelBindingStoresqlite (default)
PostgreSQLPostgresChannelBindingStorepostgres
RedisRedisChannelBindingStoreredis

Text from an agent, a tool or a chat platform reaches a sink as it is; the adapter escapes it for its platform before display (S-I9).

Structs§

ChannelAttachment
A file an inbound chat message carried, as its adapter downloaded it, bounded in size and type (spec 3.5 §5 S18, §10 X12): untrusted input, which only a paired account’s message may bring into the site, through the media pipeline.
ChannelBinding
A chat account paired to a person (spec 3.3 §10 K1): its messages are that person’s turns and its answers are that person’s decisions, within what chat may decide.
ChannelDoorbell
The decision doorbell (spec 3.3 §5.3, §10 K1): an ApprovalNotifier registered on StoreApprovalService::with_notifier that hands each submitted decision to the ChannelGateway given it, which sends the card to every paired thread of the decision’s person.
ChannelGateway
The kernel’s side of every chat channel (spec 3.3 §5.3, §10 K1, S-I5, S-I6, S-I10): see the module documentation for the rules it applies.
ChannelGatewayBuilder
Builds a ChannelGateway.
ChannelInbound
What arrived from a chat thread (spec 3.3 §10 K1): untrusted input (S-I6).
ChannelPairingRequest
An unpaired account’s request to pair (spec 3.3 §10 K1): the hash of the code it was sent, never the code.
DecisionCard
A decision as a chat thread shows it (spec 3.3 §5.3, §7.1, S-I5): who asks, a short summary, the risk, and the answers the thread may give. Never the call’s arguments.
InMemoryChannel
A chat channel in process memory (spec 3.3 §10 K1): a ChannelSink that keeps what it is sent per thread, and makes the ChannelInbound values a platform adapter would, for tests and the contract suite.
InMemoryChannelBindingStore
A ChannelBindingStore in process memory, for tests and a kernel with no durable store (spec 3.3 §10 K1). Its pairings end with the process.
PostgresChannelBindingStore
A ChannelBindingStore in PostgreSQL, shared by every replica (spec 3.3 §10 K1, features channels, postgres).
RedisChannelBindingStore
A ChannelBindingStore in Redis, shared by every replica (spec 3.3 §10 K1, features channels, redis).
SqliteChannelBindingStore
A ChannelBindingStore in SQLite (spec 3.3 §10 K1, features channels, sqlite).
StopNotice
Everything was stopped from a chat thread (spec 3.3 S-I10).

Enums§

ChannelAnswer
What a person can answer from a chat thread (spec 3.3 §7.2, §8.2).
ChannelNotice
Something the gateway tells a chat thread (spec 3.3 §5.3, §8).
Delivered
One thing a channel sent to a thread (spec 3.3 §10 K1).
InboundBody
What a person sent from a chat thread (spec 3.3 §10 K1).
InboundOutcome
What the gateway did with one ChannelInbound (spec 3.3 §10 K1).

Constants§

DISMISSED_FOR
How long an account the operator dismissed gets no pairing code (spec 3.3 §10 K1): a day.

Traits§

ChannelBindingStore
Where paired chat accounts and their pairing requests are kept (spec 3.3 §10 K1), on the backends the kernel’s other stores use, with one conformance suite (channel_binding_store_conformance_tests!, feature conformance).
ChannelHost
What the gateway runs on (spec 3.3 §10 K1): the Kernel, or a test double such as the contract suite’s.
ChannelSink
Where a channel’s messages go out (spec 3.3 §10 K1): implemented by each platform adapter.
InboundRoute
What a host decides about an inbound message before the gateway does (spec 3.5 §10 X12, §7.19, A-I24): a served site sends a stranger’s message to its Inbox, where it never gets a pairing code or starts a turn, and takes a paired person’s photos into its media pipeline. Set it with ChannelGatewayBuilder::route.

Functions§

accept_pairing
Pairs the account whose request was sent code to user_id with groups (spec 3.3 §10 K1): the control plane’s POST /kernel/channels/pair.
revoke_binding
Removes the chat account id (spec 3.3 §10 K1); removing a removed one changes nothing.