Class: Pdf::StudioSession
- Inherits:
-
Object
- Object
- Pdf::StudioSession
- Defined in:
- app/services/pdf/studio_session.rb
Overview
Starts a scoped "PDF studio" Sunny session: an AssistantConversation locked
to the +pdf_tools+ service, optionally seeded with a publication's current PDF
as an attachment plus an opening instruction.
This is the conversational entry point the PDF studio and a publication's
"Create PDF variation" action hand off to — the user describes the change in
plain language and Sunny inspects / edits / generates, staging results back
into the studio (see Assistant::PdfToolBuilder#stage_for_review!, which reads
the conversation's +pdf_source_publication_id+ so a staged PDF can be imported
as a revision or replacement of the source publication).
Defined Under Namespace
Classes: Result
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(user:, source_publication: nil) ⇒ StudioSession
constructor
A new instance of StudioSession.
- #start ⇒ Result
Constructor Details
#initialize(user:, source_publication: nil) ⇒ StudioSession
Returns a new instance of StudioSession.
25 26 27 28 |
# File 'app/services/pdf/studio_session.rb', line 25 def initialize(user:, source_publication: nil) @user = user @source_publication = source_publication end |
Class Method Details
.start ⇒ Object
21 |
# File 'app/services/pdf/studio_session.rb', line 21 def self.start(...) = new(...).start |
Instance Method Details
#start ⇒ Result
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/services/pdf/studio_session.rb', line 31 def start conversation = nil conversation = Assistant::SunnyAgent.create!(user: @user) seeded_upload = seed_publication_pdf!(conversation) conversation.update!( title: session_title, tool_services: ['pdf_tools'], conversation_type: 'pdf_work', default_tool_handles: ['pdf-tools'], draft_prefill: opening_prompt(seeded_upload), pdf_source_publication_id: @source_publication&.id ) Result.new(conversation: conversation) rescue StandardError => e # Don't leave a half-configured conversation (and its seeded upload) behind. conversation&.destroy if conversation&.persisted? Rails.logger.error("[Pdf::StudioSession] #{e.class}: #{e.}") Result.new(error: e.) end |