Remote modules (Psyclone 2.3.2+): this process *is* a module of a running Psyclone system.
The PsySpec declares the module (``<module name="Asr" type="remote" service="Modules">`` with its triggers,
posts, retrieves and queries) and a ``<service>`` with a ``<modules>`` element hosts it. The process attaches
over any PsycloneClient transport (TCP, TLS, WebSocket; UDP only where the host allows it) and then receives
the module's triggers, posts by post name, retrieves from whiteboards and queries catalogs by the names the
spec gave them::
psy = PsycloneClient.tcp("host", 18700, device="asr-box-1")
asr = RemoteModule.attach(psy, "Asr", Auth.key(api_key)) # the contract comes from the server
asr.on_trigger("Audio", lambda m: asr.post("Text", DataMessage().set_string("Text", recognise(m))))
recent = asr.retrieve("Recent", max_count=5) # list of DataMessage
asr.on_stop(lambda reason: pause())
Protocol ("Remote Module Protocol 1", Psyclone User Guide, "Remote modules"): control frames carry
``PsyPost=PsyModule`` and ``PsyOp``; every frame about a module carries ``PsyModule`` and, after attach, the
server-issued ``PsySession``. Replies echo ``PsyOpID`` and carry ``PsyOpReply=1`` and ``PsyStatus``. Trigger
frames carry ``PsyTrigger``, ``PsySeq``, ``PsyTypeName`` and ``PsyFromName``. With ``Auth.key`` the API key's
secret never travels: the client proves it with ``HMAC-SHA256(sha256hex(secret), "module|device|nonce")`` on a
nonce from ``hello``.
Dynamic modules (2.3.2 phase 2): a host with ``<modules allowdynamic="yes">`` lets a process attach a name the
spec does not declare (inside ``<allow names>``) and build its contract at run time: ``subscribe(Trigger(...))``,
``declare_post``, ``declare_retrieve``, ``declare_query``, ``declare_parameter``; every type is checked against the
host's ``<allow>`` (a refusal raises ``denied``). Ad-hoc ``retrieve_from`` / ``query_catalog`` name a whiteboard or
catalog the policy allows::
ext = RemoteModule.attach(psy, "Ext.Logger")
ext.subscribe(Trigger("All", "Mimir.*").max_age(1000))
ext.declare_post("Note", "Ext.Logger.Note")
After a reconnect the module attaches again with ``Resume`` = its session and ``LastSeq`` = ``last_seq``: while
the session lives the host replays the triggers this process missed (its resume buffer, by default 256 messages /
5 s) and reports what it could not keep through ``on_dropped``. When the session had ended, a changeable module's
subscriptions and declarations are sent again (the desired set).
Handlers run where the client runs its handlers (the reader thread, or the client's ``callback``). A handler
may ``post()`` at once; the blocking calls (``retrieve``, ``query``, ``post_confirmed``, ``describe``) wait for
a reply that arrives on the reader thread, so call them from a handler only when the client has a
``callback`` that runs handlers elsewhere (or from another thread).