Module: AssistantConversationPlannable

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

Instance Method Summary collapse

Instance Method Details

#can_auto_continue?Boolean

Returns:

  • (Boolean)


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

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

#increment_continuation_count!Object



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

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)


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

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

#plan_completed_stepsObject



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

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

  Array(execution_plan['steps']).select do |step|
    step['status'] == 'completed' || step['status'] == 'skipped'
  end
end

#plan_continuation_countObject



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

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

  execution_plan['continuation_count'].to_i
end

#plan_pending_stepsObject



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

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

  Array(execution_plan['steps']).select do |step|
    step['status'] == 'pending' || step['status'] == 'in_progress'
  end
end

#plan_progress_summaryObject



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

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

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

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