Class: Forem::AgentSession

Inherits:
APIResource show all
Extended by:
Forem::APIOperations::Create, Forem::APIOperations::List, Forem::APIOperations::Retrieve
Defined in:
lib/forem/resources/agent_session.rb

Overview

Represents an agent session used for AI-assisted content workflows on Forem.

Agent sessions are coding conversation transcripts from CLI tools like Claude Code and other AI coding assistants.

A presign step generates upload credentials before session data is submitted. After creation, the raw asset URL for the session can be retrieved via the raw_url instance method.

Available operations (via mixins):

- +List+     — GET /api/agent_sessions     (getAgentSessions)
- +Create+   — POST /api/agent_sessions    (createAgentSession)
- +Retrieve+ — GET /api/agent_sessions/:id (getAgentSessionById)

AgentSession Fields

  • id (Integer)
  • slug (String) — URL-friendly identifier
  • title (String)
  • tool_name (String) — Tool that produced the session
  • total_messages (Integer)
  • published (Boolean)
  • url (String) — Public URL for the session

Examples:

Get presigned upload credentials before creating a session

presign = client.agent_sessions.presign(filename: "session.json", mime_type: "application/json")
puts presign.presigned_url

Create a new agent session (flat params — no agent_session: wrapper)

session = client.agent_sessions.create(
  title: "My Session",
  curated_data: curated_json,
  tool_name: "claude_code"
)

Retrieve the raw asset URL for an existing session

session = client.agent_sessions.retrieve(99)
puts session.raw_url.raw_url

See Also:

Constant Summary collapse

OBJECT_NAME =
"agent_session"
RESOURCE_PATH =
"/api/agent_sessions"

Instance Attribute Summary

Attributes inherited from ForemObject

#requestor

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Forem::APIOperations::Create

create

Methods included from Forem::APIOperations::List

list

Methods included from Forem::APIOperations::Retrieve

retrieve

Methods inherited from APIResource

#refresh, resource_path, #resource_url

Methods inherited from ForemObject

#==, #[], #[]=, construct_from, cursor_list, #initialize, #inspect, #method_missing, paginated_list, #respond_to_missing?, #to_hash

Methods included from Forem::APIOperations::Request

included, #request

Constructor Details

This class inherits a constructor from Forem::ForemObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Forem::ForemObject

Class Method Details

.create(params = {}, opts = {}) ⇒ Forem::AgentSession

Create a new agent session (createAgentSession).

Sends a POST request to /api/agent_sessions.

Parameters:

  • params (Hash) (defaults to: {})

    request body

  • opts (Hash) (defaults to: {})

    per-request options (e.g., :api_key)

Options Hash (params):

  • :title (String)

    Title for the session (auto-generated if omitted)

  • :curated_data (String)

    JSON string of curated session data with messages array and metadata

  • :s3_key (String)

    S3 key for raw file (from presign endpoint)

  • :tool_name (String)

    One of: "claude_code", "codex", "gemini_cli", "github_copilot", "pi"

Returns:



# File 'lib/forem/resources/agent_session.rb', line 50

.presign(params = {}, opts = {}) ⇒ Forem::ForemObject

Obtain presigned upload credentials for a new agent session asset.

Sends a POST request to /api/agent_sessions/presign. The returned object contains a signed upload URL and any required form fields needed to upload the session file directly to object storage.

Examples:

presign = client.agent_sessions.presign(filename: "output.json", mime_type: "application/json")
puts presign.upload_url

Parameters:

  • params (Hash) (defaults to: {})

    request body

  • opts (Hash) (defaults to: {})

    per-request options (e.g., :api_key)

Options Hash (params):

  • :filename (String)

    the intended filename for the upload

  • :mime_type (String)

    MIME type of the file being uploaded

Returns:

See Also:



90
91
92
93
# File 'lib/forem/resources/agent_session.rb', line 90

def self.presign(params = {}, opts = {})
  resp = request(:post, "/api/agent_sessions/presign", params, opts)
  Forem::ForemObject.construct_from(resp.parsed_body)
end

.retrieve(id, opts = {}) ⇒ Forem::AgentSession

Retrieve an agent session by ID or slug (getAgentSessionById).

The id parameter can be a numeric ID or a slug string (e.g., 'my-session-abc123').

Sends a GET request to /api/agent_sessions/:id.

Parameters:

  • id (Integer, String)

    numeric ID or slug of the session

  • opts (Hash) (defaults to: {})

    per-request options (e.g., :api_key)

Returns:



# File 'lib/forem/resources/agent_session.rb', line 63

Instance Method Details

#raw_url(opts = {}) ⇒ Forem::ForemObject

Return the raw asset URL associated with this agent session.

Sends a GET request to /api/agent_sessions/:id/raw_url.

Examples:

session = client.agent_sessions.retrieve(99)
puts session.raw_url.url

Parameters:

  • opts (Hash) (defaults to: {})

    per-request options (e.g., :api_key)

Returns:

See Also:



105
106
107
108
# File 'lib/forem/resources/agent_session.rb', line 105

def raw_url(opts = {})
  resp = request(:get, "#{resource_url}/raw_url", {}, opts)
  Forem::ForemObject.construct_from(resp.parsed_body)
end