Phantom.Session (phantom v0.1.1)
View SourceRepresents the state of the MCP session. This is the state across the conversation and is the bridge between the various transports (HTTP, stdio) to persistence, even if stateless.
Summary
Functions
Closes the SSE stream for the session
Get the PID of the SSE stream for the session id
Notify the client with a log at level "alert"
Notify the client with a log at level "critical"
Notify the client with a log at level "debug"
Notify the client with a log at level "emergency"
Notify the client with a log at level "error"
Notify the client with a log at level "info"
Notify the client with a log at level "notice"
Notify the client with a log at level "warning"
Sends response back to the SSE stream
Sets the log level for the SSE stream. Sets both for the current request for async tasks and the SSE stream
Types
@type log_level() ::
:emergency | :alert | :critical | :error | :warning | :notice | :info | :debug
@type t() :: %Phantom.Session{ assigns: map(), close_after_complete: boolean(), id: binary(), last_event_id: String.t() | nil, pid: pid() | nil, prompts: [atom()], pubsub: module(), requests: map(), resource_templates: [atom()], router: module(), stream_fun: fun(), subscribed: map(), tools: [atom()], tracker: term() }
Functions
@spec finish(Session.t()) :: :ok
Closes the SSE stream for the session
Get the PID of the SSE stream for the session id
Notify the client with a log at level "alert"
Notify the client with a log at level "critical"
Notify the client with a log at level "debug"
Notify the client with a log at level "emergency"
Notify the client with a log at level "error"
Notify the client with a log at level "info"
Notify the client with a log at level "notice"
Notify the client with a log at level "warning"
Sends response back to the SSE stream
This should likely be used in conjunction with:
Phantom.Tool.response(payload)
Phantom.ResourceTemplate.response(payload, resource_template, uri)
Phantom.Prompt.response(payload, prompt)
For example:
session_pid = session.pid
request_id = request.id
Task.async(fn ->
Session.respond(
session_pid,
request_id,
Phantom.Tool.call_response(%{
type: :audio,
data: Base.encode64(File.read!("test/support/game-over.wav")),
mime_type: "audio/wav"
})
)
end)
@spec set_log_level(Session.t(), Phantom.Request.t(), String.t()) :: :ok
Sets the log level for the SSE stream. Sets both for the current request for async tasks and the SSE stream