Packages
snakepit
0.6.3
0.13.0
0.12.0
0.11.1
0.11.0
0.10.1
0.10.0
0.9.1
0.9.0
0.8.9
0.8.8
0.8.7
0.8.6
0.8.5
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
0.7.7
0.7.6
0.7.5
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.11
0.6.10
0.6.9
0.6.8
0.6.7
0.6.6
0.6.5
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
0.5.1
0.5.0
0.4.3
0.4.2
0.4.1
0.4.0
0.3.3
0.3.2
0.3.1
0.3.0
0.2.1
0.2.0
0.1.2
0.1.1
0.1.0
High-performance pooler and session manager for external language integrations. Supports Python, Node.js, Ruby, and more with gRPC streaming, session management, and production-ready process cleanup.
Current section
Files
Jump to
Current section
Files
lib/snakepit/grpc/client.ex
defmodule Snakepit.GRPC.Client do
@moduledoc """
gRPC client for the unified bridge protocol.
Delegates to the real implementation when available.
"""
require Logger
# Uncomment when logging is added to this module:
# alias Snakepit.Logger, as: SLog
def connect(port) when is_integer(port) do
connect("localhost:#{port}")
end
def connect(address) when is_binary(address) do
Snakepit.GRPC.ClientImpl.connect(address)
end
def ping(channel, message, opts \\ []) do
if not Map.get(channel, :mock, false) do
Snakepit.GRPC.ClientImpl.ping(channel, message, opts)
else
# Mock implementation
{:ok, %{message: "Pong: #{message}", server_time: DateTime.utc_now()}}
end
end
def initialize_session(channel, session_id, config \\ %{}, opts \\ []) do
if not Map.get(channel, :mock, false) do
Snakepit.GRPC.ClientImpl.initialize_session(channel, session_id, config, opts)
else
# Mock implementation
{:ok, %{success: true, available_tools: %{}}}
end
end
def cleanup_session(channel, session_id, force \\ false, opts \\ []) do
if not Map.get(channel, :mock, false) do
Snakepit.GRPC.ClientImpl.cleanup_session(channel, session_id, force, opts)
else
# Mock implementation
{:ok, %{success: true, resources_cleaned: 2}}
end
end
def execute_tool(channel, session_id, tool_name, parameters, opts \\ []) do
if not Map.get(channel, :mock, false) do
Snakepit.GRPC.ClientImpl.execute_tool(channel, session_id, tool_name, parameters, opts)
else
# Mock implementation for testing
{:ok, %{success: true, result: %{}, error_message: ""}}
end
end
def execute_streaming_tool(channel, session_id, tool_name, parameters, opts \\ []) do
if not Map.get(channel, :mock, false) do
Snakepit.GRPC.ClientImpl.execute_streaming_tool(
channel,
session_id,
tool_name,
parameters,
opts
)
else
# Mock implementation for testing - return a simple stream
stream =
Stream.iterate(1, &(&1 + 1))
|> Stream.take(5)
|> Stream.map(fn i ->
{:ok,
%{
chunk_id: "mock-#{i}",
data: Jason.encode!(%{"step" => i, "total" => 5}),
is_final: i == 5
}}
end)
{:ok, stream}
end
end
# Existing methods for backward compatibility
def execute(channel, command, args, timeout \\ 30_000) do
# Legacy support - redirect to execute_tool
execute_tool(channel, "default_session", command, args, timeout: timeout)
end
def health(channel, client_id) do
ping(channel, "health_check_#{client_id}")
end
def get_info(_channel) do
# Return mock info for now
{:ok,
%{
version: "1.0.0",
capabilities: ["tools", "streaming"]
}}
end
def get_session(channel, session_id, opts \\ []) do
if not Map.get(channel, :mock, false) do
Snakepit.GRPC.ClientImpl.get_session(channel, session_id, opts)
else
# Mock implementation
{:ok, %{session: %{id: session_id, active: true}}}
end
end
def heartbeat(channel, session_id, opts \\ []) do
if not Map.get(channel, :mock, false) do
Snakepit.GRPC.ClientImpl.heartbeat(channel, session_id, opts)
else
# Mock implementation
{:ok, %{success: true}}
end
end
end