Class: PromptObjects::Server::API::Routes

Inherits:
Object
  • Object
show all
Defined in:
lib/prompt_objects/server/api/routes.rb

Overview

REST API routes for the PromptObjects server. Provides endpoints for listing POs, sessions, and environment info.

Instance Method Summary collapse

Constructor Details

#initialize(runtime) ⇒ Routes

Returns a new instance of Routes.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/prompt_objects/server/api/routes.rb', line 13

def initialize(runtime)
  @runtime = runtime
  if runtime.session_store
    @workspace_repository = Repositories::WorkspaceSessionRepository.new(runtime.session_store)
    @thread_repository = Repositories::ThreadRepository.new(runtime.session_store)
    @run_repository = Repositories::RunRepository.new(runtime.session_store)
    @message_repository = Repositories::MessageRepository.new(runtime.session_store)
    @event_repository = Repositories::EventRepository.new(runtime.session_store)
    @artifact_repository = Repositories::ArtifactRepository.new(runtime.session_store)
    @env_data_repository = Repositories::EnvDataRepository.new(runtime.session_store)
    @run_trace_builder = Operations::RunTraceBuilder.new(runtime.session_store)
  end
end

Instance Method Details

#call(env) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/prompt_objects/server/api/routes.rb', line 27

def call(env)
  request = Rack::Request.new(env)
  # Falcon delivers PATH_INFO as ASCII-8BIT. SQLite binds binary strings
  # as BLOBs, which never compare equal to TEXT columns — so any keyed
  # lookup from a URL path (artifacts, sessions) would silently miss.
  # Normalize to UTF-8 before routing.
  path = request.path_info.dup.force_encoding(Encoding::UTF_8)
  path = path.scrub unless path.valid_encoding?
  path = path.sub("/api", "")

  response = route(request, path)
  json_response(response)
rescue => e
  json_response({ error: e.message }, status: 500)
end