LemonCore. SessionKey
(lemon_core v0.1.0)
View Source
Session key generation and parsing.
Session keys provide a stable identifier for routing and state management.
Canonical Formats
- Main:
agent:<agent_id>:main[:sub:<sub_id>] - Channel:
agent:<agent_id>:<channel_id>:<account_id>:<peer_kind>:<peer_id>[:thread:<thread_id>][:sub:<sub_id>]
Notes
Session keys are strictly validated against the canonical formats above.
Summary
Functions
Extract the agent ID from a session key.
Returns the list of allowed peer_kind strings.
Generate a channel peer session key.
Check if a session key is for a channel peer.
Generate a main session key for an agent.
Check if a session key is for the main session.
Parse a session key into its components.
Check if a session key is valid.
Types
Functions
Extract the agent ID from a session key.
Examples
iex> LemonCore.SessionKey.agent_id("agent:my_bot:main")
"my_bot"
iex> LemonCore.SessionKey.agent_id("invalid")
nil
@spec allowed_peer_kinds() :: [String.t()]
Returns the list of allowed peer_kind strings.
Generate a channel peer session key.
Required keys in opts:
:agent_id:channel_id:account_id:peer_kind(:dm, :group, :channel, :unknown):peer_id
Optional:
:thread_id:sub_id
Check if a session key is for a channel peer.
Generate a main session key for an agent.
Examples
iex> LemonCore.SessionKey.main("my_agent")
"agent:my_agent:main"
Check if a session key is for the main session.
Parse a session key into its components.
Returns the parsed components or {:error, :invalid} for malformed keys.
Check if a session key is valid.
Examples
iex> LemonCore.SessionKey.valid?("agent:test:main")
true
iex> LemonCore.SessionKey.valid?("invalid")
false