Class: Silas::Api::V1::SessionsController

Inherits:
BaseController
  • Object
show all
Includes:
Serialization
Defined in:
app/controllers/silas/api/v1/sessions_controller.rb

Instance Method Summary collapse

Methods included from Serialization

#invocation_json, #session_json, #step_json, #turn_json

Instance Method Details

#createObject

POST /silas/api/v1/sessions { input:, agent: (optional), metadata: (optional) } channel stays nil ("direct") — API consumers read state via GET/stream; a non-nil channel would enqueue pointless outbound delivery jobs.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/silas/api/v1/sessions_controller.rb', line 10

def create
  input = params[:input].to_s.strip
  return render json: { error: "input is required" }, status: :unprocessable_entity if input.empty?

  handle = params[:agent].present? ? Silas.agent(params[:agent]) : Silas.agent
  session = handle.start(input: input, metadata: )
  render json: session_json(session.reload), status: :created
rescue Silas::TurnInProgressError => e
  render json: { error: e.message }, status: :conflict
rescue Silas::Error => e
  render json: { error: e.message }, status: :unprocessable_entity
end

#showObject

GET /silas/api/v1/sessions/:id — session + turns GET /silas/api/v1/sessions/:id?trace=1 — plus steps + invocations



25
26
27
28
# File 'app/controllers/silas/api/v1/sessions_controller.rb', line 25

def show
  session = Silas::Session.includes(turns: { steps: :tool_invocations }).find(params[:id])
  render json: session_json(session, trace: params[:trace].present?)
end