Module: AssistantConversationPlannable

Extended by:
ActiveSupport::Concern
Included in:
AssistantConversation
Defined in:
app/models/concerns/assistant_conversation_plannable.rb

Overview

Concern mixed into a model: assistant conversation plannable.

Instance Method Summary collapse

Instance Method Details

#can_auto_continue?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/models/concerns/assistant_conversation_plannable.rb', line 36

def can_auto_continue?
  plan_active? && plan_continuation_count < AssistantConversation::MAX_AUTO_CONTINUATIONS
end

#increment_continuation_count!Object



40
41
42
43
44
45
46
47
48
# File 'app/models/concerns/assistant_conversation_plannable.rb', line 40

def increment_continuation_count!
  return unless execution_plan.is_a?(Hash)

  plan = execution_plan.dup
  plan['continuation_count'] = plan['continuation_count'].to_i + 1
  patch = { 'execution_plan' => plan }.to_json
  self.class.where(id: id).update_all(["metadata = metadata || ?::jsonb", patch])
  reload
end

#plan_active?Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
# File 'app/models/concerns/assistant_conversation_plannable.rb', line 7

def plan_active?
  plan = execution_plan
  plan.is_a?(Hash) && Array(plan['steps']).any? do |step|
    %w[pending in_progress].include?(step['status'])
  end
end

#plan_completed_stepsObject



22
23
24
25
26
27
28
# File 'app/models/concerns/assistant_conversation_plannable.rb', line 22

def plan_completed_steps
  return [] unless execution_plan.is_a?(Hash)

  Array(execution_plan['steps']).select do |step|
    %w[completed skipped].include?(step['status'])
  end
end

#plan_continuation_countObject



30
31
32
33
34
# File 'app/models/concerns/assistant_conversation_plannable.rb', line 30

def plan_continuation_count
  return 0 unless execution_plan.is_a?(Hash)

  execution_plan['continuation_count'].to_i
end

#plan_pending_stepsObject



14
15
16
17
18
19
20
# File 'app/models/concerns/assistant_conversation_plannable.rb', line 14

def plan_pending_steps
  return [] unless execution_plan.is_a?(Hash)

  Array(execution_plan['steps']).select do |step|
    %w[pending in_progress].include?(step['status'])
  end
end

#plan_progress_summaryObject



50
51
52
53
54
55
56
57
58
59
60
# File 'app/models/concerns/assistant_conversation_plannable.rb', line 50

def plan_progress_summary
  return nil unless execution_plan.is_a?(Hash)

  steps = Array(execution_plan['steps'])
  completed = steps.count { |step| %w[completed skipped].include?(step['status']) }
  total = steps.size
  pending = steps.select { |step| %w[pending in_progress].include?(step['status']) }
  pending_descriptions = pending.pluck('description')

  "#{completed}/#{total} steps completed. Remaining: #{pending_descriptions.join(', ')}"
end